diff options
author | Ananya Sen | 2012-07-09 16:52:49 -0700 |
---|---|---|
committer | Ananya Sen | 2012-07-09 16:52:49 -0700 |
commit | 2eb84584f44b8c774479d1af2ee1d810597474cf (patch) | |
tree | 64cb3e09a8daeb340261dd7f3869c73f7b90b643 /assets/shaders/test_fshader.glsl | |
parent | bf9dba001ec84243e2f12cd13b0c0ae020fba4a2 (diff) | |
parent | cee0deca695359ab468bd06d0e05ed3b2010b338 (diff) | |
download | ninja-2eb84584f44b8c774479d1af2ee1d810597474cf.tar.gz |
Merge branch 'refs/heads/ninja-internal-master' into codemirror-custom-theme-removal
Conflicts:
js/code-editor/codemirror-ninja/theme/lesser-dark-ninja.css
js/code-editor/codemirror-ninja/theme/xq-dark-ninja.css
Signed-off-by: Ananya Sen <Ananya.Sen@motorola.com>
Diffstat (limited to 'assets/shaders/test_fshader.glsl')
-rwxr-xr-x | assets/shaders/test_fshader.glsl | 81 |
1 files changed, 41 insertions, 40 deletions
diff --git a/assets/shaders/test_fshader.glsl b/assets/shaders/test_fshader.glsl index d2b3bd40..2cad58ec 100755 --- a/assets/shaders/test_fshader.glsl +++ b/assets/shaders/test_fshader.glsl | |||
@@ -1,24 +1,25 @@ | |||
1 | /* <copyright> | 1 | /* <copyright> |
2 | Copyright (c) 2012, Motorola Mobility, Inc | 2 | Copyright (c) 2012, Motorola Mobility LLC. |
3 | All Rights Reserved. | 3 | All Rights Reserved. |
4 | BSD License. | ||
5 | 4 | ||
6 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
8 | 7 | ||
9 | - Redistributions of source code must retain the above copyright notice, | 8 | * Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. | 9 | this list of conditions and the following disclaimer. |
11 | - Redistributions in binary form must reproduce the above copyright | 10 | |
12 | notice, this list of conditions and the following disclaimer in the | 11 | * Redistributions in binary form must reproduce the above copyright notice, |
13 | documentation and/or other materials provided with the distribution. | 12 | this list of conditions and the following disclaimer in the documentation |
14 | - Neither the name of Motorola Mobility nor the names of its contributors | 13 | and/or other materials provided with the distribution. |
15 | may be used to endorse or promote products derived from this software | 14 | |
16 | without specific prior written permission. | 15 | * Neither the name of Motorola Mobility LLC nor the names of its |
16 | contributors may be used to endorse or promote products derived from this | ||
17 | software without specific prior written permission. | ||
17 | 18 | ||
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
@@ -40,7 +41,7 @@ uniform vec4 u_light0Amb; | |||
40 | // diffuse map | 41 | // diffuse map |
41 | uniform sampler2D u_colMap; | 42 | uniform sampler2D u_colMap; |
42 | 43 | ||
43 | // environment map | 44 | // environment map |
44 | uniform sampler2D envMap; | 45 | uniform sampler2D envMap; |
45 | 46 | ||
46 | // normal map | 47 | // normal map |
@@ -72,12 +73,12 @@ varying float vDiffuseIntensity; | |||
72 | 73 | ||
73 | void main() | 74 | void main() |
74 | { | 75 | { |
75 | vec4 rgba_depth = texture2D(depthMap, vShadowCoord.xy/vShadowCoord.w, -32.0); | 76 | vec4 rgba_depth = texture2D(depthMap, vShadowCoord.xy/vShadowCoord.w, -32.0); |
76 | 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); | 77 | 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); |
77 | float dist = vShadowCoord.w/200.0; | 78 | float dist = vShadowCoord.w/200.0; |
78 | float d = dot(rgba_depth, bit_shift); | 79 | float d = dot(rgba_depth, bit_shift); |
79 | float shadowCoef = (dist > d + 0.00779) ? (0.6) : (1.0); | 80 | float shadowCoef = (dist > d + 0.00779) ? (0.6) : (1.0); |
80 | 81 | ||
81 | vec4 colMapTexel = vec4(0); | 82 | vec4 colMapTexel = vec4(0); |
82 | if (u_renderGlow <= 0.5) { | 83 | if (u_renderGlow <= 0.5) { |
83 | colMapTexel = vec4(texture2D(u_colMap, vec2(vNormal.w, vECPos.w)).rgb, 1.0); | 84 | colMapTexel = vec4(texture2D(u_colMap, vec2(vNormal.w, vECPos.w)).rgb, 1.0); |
@@ -89,42 +90,42 @@ void main() | |||
89 | vec3 normal = normalize(vNormal.xyz); | 90 | vec3 normal = normalize(vNormal.xyz); |
90 | vec3 mapNormal = texture2D(u_normalMap, vec2(vNormal.w, vECPos.w)).xyz * 2.0 - 1.0; | 91 | vec3 mapNormal = texture2D(u_normalMap, vec2(vNormal.w, vECPos.w)).xyz * 2.0 - 1.0; |
91 | mapNormal = normalize(mapNormal.x*vec3(normal.z, 0.0, -normal.x) + vec3(0.0, mapNormal.y, 0.0) + mapNormal.z*normal); | 92 | mapNormal = normalize(mapNormal.x*vec3(normal.z, 0.0, -normal.x) + vec3(0.0, mapNormal.y, 0.0) + mapNormal.z*normal); |
92 | 93 | ||
93 | // create envmap coordinates | 94 | // create envmap coordinates |
94 | vec3 r = reflect( normalize(vec3(vECPos.xyz - vEyePos.xyz)), mapNormal); | 95 | vec3 r = reflect( normalize(vec3(vECPos.xyz - vEyePos.xyz)), mapNormal); |
95 | float m = 2.0 * sqrt( r.x*r.x + r.y*r.y + r.z*r.z ); | 96 | float m = 2.0 * sqrt( r.x*r.x + r.y*r.y + r.z*r.z ); |
96 | 97 | ||
97 | // calculate environment map texel | 98 | // calculate environment map texel |
98 | vec4 envMapTexel = vec4(texture2D(envMap, vec2(r.x/m + 0.5, r.y/m + 0.5)).rgb, 0.0); | 99 | vec4 envMapTexel = vec4(texture2D(envMap, vec2(r.x/m + 0.5, r.y/m + 0.5)).rgb, 0.0); |
99 | 100 | ||
100 | // lighting | 101 | // lighting |
101 | vec3 lightDirection = u_light0Pos - vECPos.xyz; | 102 | vec3 lightDirection = u_light0Pos - vECPos.xyz; |
102 | float lightDist = length(lightDirection); | 103 | float lightDist = length(lightDirection); |
103 | lightDirection /= lightDist; | 104 | lightDirection /= lightDist; |
104 | 105 | ||
105 | float attenuation = clamp(1.0 - lightDist * 0.01, 0.0, 1.0); | 106 | float attenuation = clamp(1.0 - lightDist * 0.01, 0.0, 1.0); |
106 | 107 | ||
107 | vec3 halfVec = normalize(lightDirection + vEyePos); | 108 | vec3 halfVec = normalize(lightDirection + vEyePos); |
108 | 109 | ||
109 | float diffuseIntensity = max(0.0, dot(mapNormal, lightDirection)); | 110 | float diffuseIntensity = max(0.0, dot(mapNormal, lightDirection)); |
110 | float specularModifier = max(0.0, dot(mapNormal, halfVec)); | 111 | float specularModifier = max(0.0, dot(mapNormal, halfVec)); |
111 | 112 | ||
112 | float pf; | 113 | float pf; |
113 | if(diffuseIntensity == 0.0) | 114 | if(diffuseIntensity == 0.0) |
114 | pf = 0.0; | 115 | pf = 0.0; |
115 | else | 116 | else |
116 | pf = pow(specularModifier, 76.0); | 117 | pf = pow(specularModifier, 76.0); |
117 | 118 | ||
118 | vec4 ambient = u_matAmbient * u_light0Amb; | 119 | vec4 ambient = u_matAmbient * u_light0Amb; |
119 | 120 | ||
120 | vec4 diffuse = u_matDiffuse * (colMapTexel + envMapTexel)*shadowCoef; | 121 | vec4 diffuse = u_matDiffuse * (colMapTexel + envMapTexel)*shadowCoef; |
121 | 122 | ||
122 | if (u_renderGlow <= 0.5) { | 123 | if (u_renderGlow <= 0.5) { |
123 | diffuse *= u_light0Diff; | 124 | diffuse *= u_light0Diff; |
124 | } | 125 | } |
125 | 126 | ||
126 | vec4 specular = 2.0 * pf * envMapTexel; | 127 | vec4 specular = 2.0 * pf * envMapTexel; |
127 | 128 | ||
128 | //gl_FragColor = vec4(dist, dist, dist, 1.0); | 129 | //gl_FragColor = vec4(dist, dist, dist, 1.0); |
129 | gl_FragColor = ((colMapTexel*(ambient + diffuse)) + specular); | 130 | gl_FragColor = ((colMapTexel*(ambient + diffuse)) + specular); |
130 | } | 131 | } |
@@ -138,43 +139,43 @@ void main() | |||
138 | vec4 colMapTexel = vec4(texture2D(u_colMap, vec2(vNormal.w, vECPos.w)).rgb, 1.0); | 139 | vec4 colMapTexel = vec4(texture2D(u_colMap, vec2(vNormal.w, vECPos.w)).rgb, 1.0); |
139 | 140 | ||
140 | // // normal mapping | 141 | // // normal mapping |
141 | vec3 normal = normalize(vNormal.xyz); | 142 | vec3 normal = normalize(vNormal.xyz); |
142 | // vec3 mapNormal = texture2D(u_normalMap, vec2(vNormal.w, vECPos.w)).xyz * 2.0 - 1.0; | 143 | // vec3 mapNormal = texture2D(u_normalMap, vec2(vNormal.w, vECPos.w)).xyz * 2.0 - 1.0; |
143 | // mapNormal = normalize(mapNormal.x*vec3(normal.z, 0.0, -normal.x) + vec3(0.0, mapNormal.y, 0.0) + mapNormal.z*normal); | 144 | // mapNormal = normalize(mapNormal.x*vec3(normal.z, 0.0, -normal.x) + vec3(0.0, mapNormal.y, 0.0) + mapNormal.z*normal); |
144 | // | 145 | // |
145 | // // create envmap coordinates | 146 | // // create envmap coordinates |
146 | // vec3 r = reflect( (vec3(vECPos.xyz - vEyePos.xyz)), mapNormal); | 147 | // vec3 r = reflect( (vec3(vECPos.xyz - vEyePos.xyz)), mapNormal); |
147 | // float m = 2.0 * length(r); | 148 | // float m = 2.0 * length(r); |
148 | 149 | ||
149 | // calculate environment map texel | 150 | // calculate environment map texel |
150 | //vec4 envMapTexel = vec4(texture2D(envMap, vec2(r.x/m + 0.5, r.y/m + 0.5)).rgb, 0.0); | 151 | //vec4 envMapTexel = vec4(texture2D(envMap, vec2(r.x/m + 0.5, r.y/m + 0.5)).rgb, 0.0); |
151 | vec4 envMapTexel = vec4(texture2D(envMap, vEnvTexCoord).rgb, 0.0); | 152 | vec4 envMapTexel = vec4(texture2D(envMap, vEnvTexCoord).rgb, 0.0); |
152 | 153 | ||
153 | // lighting | 154 | // lighting |
154 | //vec3 lightDirection = normalize(u_light0Pos - vECPos.xyz); | 155 | //vec3 lightDirection = normalize(u_light0Pos - vECPos.xyz); |
155 | // float lightDist = length(lightDirection); | 156 | // float lightDist = length(lightDirection); |
156 | // lightDirection /= lightDist; | 157 | // lightDirection /= lightDist; |
157 | 158 | ||
158 | 159 | ||
159 | //vec3 halfVec = normalize(lightDirection + vEyePos); | 160 | //vec3 halfVec = normalize(lightDirection + vEyePos); |
160 | 161 | ||
161 | //float diffuseIntensity = max(0.0, dot(normal, lightDirection)); | 162 | //float diffuseIntensity = max(0.0, dot(normal, lightDirection)); |
162 | // float specularModifier = max(0.0, dot(mapNormal, halfVec)); | 163 | // float specularModifier = max(0.0, dot(mapNormal, halfVec)); |
163 | 164 | ||
164 | // float pf; | 165 | // float pf; |
165 | //if(diffuseIntensity == 0.0) | 166 | //if(diffuseIntensity == 0.0) |
166 | //pf = 0.0; | 167 | //pf = 0.0; |
167 | //else | 168 | //else |
168 | //pf = pow(specularModifier, 76.0); | 169 | //pf = pow(specularModifier, 76.0); |
169 | 170 | ||
170 | // vec4 ambient = u_matAmbient * u_light0Amb; | 171 | // vec4 ambient = u_matAmbient * u_light0Amb; |
171 | 172 | ||
172 | vec4 diffuse = u_matDiffuse*(colMapTexel + envMapTexel)*(vDiffuseIntensity + u_matAmbient); | 173 | vec4 diffuse = u_matDiffuse*(colMapTexel + envMapTexel)*(vDiffuseIntensity + u_matAmbient); |
173 | 174 | ||
174 | //diffuse *= u_light0Diff * diffuseIntensity; | 175 | //diffuse *= u_light0Diff * diffuseIntensity; |
175 | 176 | ||
176 | //vec4 specular = envMapTexel; | 177 | //vec4 specular = envMapTexel; |
177 | 178 | ||
178 | //gl_FragColor = vec4(dist, dist, dist, 1.0); | 179 | //gl_FragColor = vec4(dist, dist, dist, 1.0); |
179 | gl_FragColor = diffuse;//(colMapTexel*(ambient + diffuse)) + specular; | 180 | gl_FragColor = diffuse;//(colMapTexel*(ambient + diffuse)) + specular; |
180 | } | 181 | } |