diff options
author | Pierre Frisch | 2011-12-22 07:25:50 -0800 |
---|---|---|
committer | Valerio Virgillito | 2012-01-27 11:18:17 -0800 |
commit | b89a7ee8b956c96a1dcee995ea840feddc5d4b27 (patch) | |
tree | 0f3136ab0ecdbbbed6a83576581af0a53124d6f1 /assets/shaders | |
parent | 2401f05d1f4b94d45e4568b81fc73e67b969d980 (diff) | |
download | ninja-b89a7ee8b956c96a1dcee995ea840feddc5d4b27.tar.gz |
First commit of Ninja to ninja-internal
Signed-off-by: Valerio Virgillito <rmwh84@motorola.com>
Diffstat (limited to 'assets/shaders')
-rw-r--r-- | assets/shaders/Basic.vert.glsl | 26 | ||||
-rw-r--r-- | assets/shaders/linearGradient.frag.glsl | 52 | ||||
-rw-r--r-- | assets/shaders/linearGradient.vert.glsl | 48 | ||||
-rw-r--r-- | assets/shaders/test_fshader.glsl | 159 | ||||
-rw-r--r-- | assets/shaders/test_fshader_full.glsl | 82 | ||||
-rw-r--r-- | assets/shaders/test_vshader.glsl | 82 | ||||
-rw-r--r-- | assets/shaders/ub_fshader.glsl | 263 | ||||
-rw-r--r-- | assets/shaders/ub_vshader.glsl | 162 |
8 files changed, 874 insertions, 0 deletions
diff --git a/assets/shaders/Basic.vert.glsl b/assets/shaders/Basic.vert.glsl new file mode 100644 index 00000000..028786d1 --- /dev/null +++ b/assets/shaders/Basic.vert.glsl | |||
@@ -0,0 +1,26 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | |||
8 | #ifdef GL_ES | ||
9 | precision highp float; | ||
10 | #endif | ||
11 | |||
12 | |||
13 | // attributes | ||
14 | attribute vec3 a_pos; | ||
15 | |||
16 | |||
17 | |||
18 | // matrix uniforms | ||
19 | uniform mat4 u_mvMatrix; | ||
20 | uniform mat4 u_projMatrix; | ||
21 | uniform mat4 u_worldMatrix; | ||
22 | |||
23 | void main(void) | ||
24 | { | ||
25 | gl_Position = u_projMatrix * u_mvMatrix * vec4(a_pos,1.0) ; | ||
26 | } \ No newline at end of file | ||
diff --git a/assets/shaders/linearGradient.frag.glsl b/assets/shaders/linearGradient.frag.glsl new file mode 100644 index 00000000..64cf56ff --- /dev/null +++ b/assets/shaders/linearGradient.frag.glsl | |||
@@ -0,0 +1,52 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | #ifdef GL_ES | ||
8 | precision highp float; | ||
9 | #endif | ||
10 | |||
11 | |||
12 | uniform vec4 u_color1; | ||
13 | uniform vec4 u_color2; | ||
14 | uniform vec4 u_color3; | ||
15 | uniform vec4 u_color4; | ||
16 | uniform float u_colorStop1; | ||
17 | uniform float u_colorStop2; | ||
18 | uniform float u_colorStop3; | ||
19 | uniform float u_colorStop4; | ||
20 | uniform vec2 u_cos_sin_angle; | ||
21 | //uniform int u_colorCount; // currently using 4 | ||
22 | |||
23 | varying vec2 v_uv; | ||
24 | |||
25 | |||
26 | void main(void) | ||
27 | { | ||
28 | float t = dot(v_uv, u_cos_sin_angle); | ||
29 | |||
30 | vec4 color; | ||
31 | if (t < u_colorStop1) | ||
32 | color = u_color1; | ||
33 | else if (t < u_colorStop2) | ||
34 | { | ||
35 | float tLocal = (t - u_colorStop1)/(u_colorStop2 - u_colorStop1); | ||
36 | color = mix(u_color1,u_color2,tLocal); | ||
37 | } | ||
38 | else if (t < u_colorStop3) | ||
39 | { | ||
40 | float tLocal = (t - u_colorStop2)/(u_colorStop3 - u_colorStop2); | ||
41 | color = mix(u_color2,u_color3,tLocal); | ||
42 | } | ||
43 | else if (t < u_colorStop4) | ||
44 | { | ||
45 | float tLocal = (t - u_colorStop3)/(u_colorStop4 - u_colorStop3); | ||
46 | color = mix(u_color3,u_color4,tLocal); | ||
47 | } | ||
48 | else | ||
49 | color = u_color4; | ||
50 | |||
51 | gl_FragColor =color; | ||
52 | } \ No newline at end of file | ||
diff --git a/assets/shaders/linearGradient.vert.glsl b/assets/shaders/linearGradient.vert.glsl new file mode 100644 index 00000000..aac9cbee --- /dev/null +++ b/assets/shaders/linearGradient.vert.glsl | |||
@@ -0,0 +1,48 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | |||
8 | #ifdef GL_ES | ||
9 | precision highp float; | ||
10 | #endif | ||
11 | |||
12 | |||
13 | // attributes | ||
14 | attribute vec3 vert; | ||
15 | attribute vec3 normal; | ||
16 | attribute vec2 texcoord; | ||
17 | |||
18 | //uniform mat4 u_shadowLightWorld; | ||
19 | //uniform mat4 u_shadowBiasMatrix; | ||
20 | //uniform mat4 u_vShadowLight; | ||
21 | //uniform vec3 u_lightPos; | ||
22 | |||
23 | // matrix uniforms | ||
24 | uniform mat4 u_mvMatrix; | ||
25 | uniform vec3 u_eye; | ||
26 | uniform mat4 u_normalMatrix; | ||
27 | uniform mat4 u_projMatrix; | ||
28 | uniform mat4 u_worldMatrix; | ||
29 | |||
30 | uniform vec4 u_color1; | ||
31 | uniform vec4 u_color2; | ||
32 | uniform vec4 u_color3; | ||
33 | uniform vec4 u_color4; | ||
34 | uniform float u_colorStop1; | ||
35 | uniform float u_colorStop2; | ||
36 | uniform float u_colorStop3; | ||
37 | uniform float u_colorStop4; | ||
38 | uniform vec2 u_cos_sin_angle; | ||
39 | //uniform int u_colorCount; // currently using 4 | ||
40 | |||
41 | varying vec2 v_uv; | ||
42 | |||
43 | |||
44 | void main(void) | ||
45 | { | ||
46 | gl_Position = u_projMatrix * u_mvMatrix * vec4(vert,1.0) ; | ||
47 | v_uv = texcoord; | ||
48 | } | ||
diff --git a/assets/shaders/test_fshader.glsl b/assets/shaders/test_fshader.glsl new file mode 100644 index 00000000..3a0af39f --- /dev/null +++ b/assets/shaders/test_fshader.glsl | |||
@@ -0,0 +1,159 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | |||
8 | #ifdef GL_ES | ||
9 | precision highp float; | ||
10 | #endif | ||
11 | |||
12 | // lighting uniforms | ||
13 | uniform vec3 u_light0Pos; | ||
14 | uniform vec4 u_light0Diff; | ||
15 | uniform vec4 u_light0Amb; | ||
16 | |||
17 | // diffuse map | ||
18 | uniform sampler2D colMap; | ||
19 | |||
20 | // environment map | ||
21 | uniform sampler2D envMap; | ||
22 | |||
23 | // normal map | ||
24 | uniform sampler2D normalMap; | ||
25 | |||
26 | // glow map | ||
27 | uniform sampler2D glowMap; | ||
28 | |||
29 | // glow map | ||
30 | uniform sampler2D depthMap; | ||
31 | |||
32 | //material uniforms | ||
33 | uniform vec4 u_matAmbient; | ||
34 | uniform vec4 u_matDiffuse; | ||
35 | uniform vec4 u_matSpecular; | ||
36 | uniform float u_matShininess; | ||
37 | uniform vec4 u_matEmission; | ||
38 | uniform float u_renderGlow; | ||
39 | |||
40 | // varyings | ||
41 | varying vec4 vNormal; // w = texcoord.x | ||
42 | varying vec4 vECPos; // w = texcoord.y | ||
43 | varying vec3 vEyePos; | ||
44 | varying vec4 vShadowCoord; | ||
45 | varying vec2 vEnvTexCoord; | ||
46 | varying float vDiffuseIntensity; | ||
47 | |||
48 | #ifdef PC | ||
49 | |||
50 | void main() | ||
51 | { | ||
52 | vec4 rgba_depth = texture2D(depthMap, vShadowCoord.xy/vShadowCoord.w, -32.0); | ||
53 | const vec4 bit_shift = vec4(1.0/(256.0*256.0*256.0), 1.0/(256.0*256.0), 1.0/256.0, 1.0); | ||
54 | float dist = vShadowCoord.w/200.0; | ||
55 | float d = dot(rgba_depth, bit_shift); | ||
56 | float shadowCoef = (dist > d + 0.00779) ? (0.6) : (1.0); | ||
57 | |||
58 | vec4 colMapTexel = vec4(0); | ||
59 | if (u_renderGlow <= 0.5) { | ||
60 | colMapTexel = vec4(texture2D(colMap, vec2(vNormal.w, vECPos.w)).rgb, 1.0); | ||
61 | } else { | ||
62 | colMapTexel = vec4(texture2D(glowMap, vec2(vNormal.w, vECPos.w)).rgb, 1.0); | ||
63 | } | ||
64 | |||
65 | // normal mapping | ||
66 | vec3 normal = normalize(vNormal.xyz); | ||
67 | vec3 mapNormal = texture2D(normalMap, vec2(vNormal.w, vECPos.w)).xyz * 2.0 - 1.0; | ||
68 | mapNormal = normalize(mapNormal.x*vec3(normal.z, 0.0, -normal.x) + vec3(0.0, mapNormal.y, 0.0) + mapNormal.z*normal); | ||
69 | |||
70 | // create envmap coordinates | ||
71 | vec3 r = reflect( normalize(vec3(vECPos.xyz - vEyePos.xyz)), mapNormal); | ||
72 | float m = 2.0 * sqrt( r.x*r.x + r.y*r.y + r.z*r.z ); | ||
73 | |||
74 | // calculate environment map texel | ||
75 | vec4 envMapTexel = vec4(texture2D(envMap, vec2(r.x/m + 0.5, r.y/m + 0.5)).rgb, 0.0); | ||
76 | |||
77 | // lighting | ||
78 | vec3 lightDirection = u_light0Pos - vECPos.xyz; | ||
79 | float lightDist = length(lightDirection); | ||
80 | lightDirection /= lightDist; | ||
81 | |||
82 | float attenuation = clamp(1.0 - lightDist * 0.01, 0.0, 1.0); | ||
83 | |||
84 | vec3 halfVec = normalize(lightDirection + vEyePos); | ||
85 | |||
86 | float diffuseIntensity = max(0.0, dot(mapNormal, lightDirection)); | ||
87 | float specularModifier = max(0.0, dot(mapNormal, halfVec)); | ||
88 | |||
89 |