diff options
Diffstat (limited to 'assets/shaders/test_fshader_full.glsl')
-rwxr-xr-x | assets/shaders/test_fshader_full.glsl | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/assets/shaders/test_fshader_full.glsl b/assets/shaders/test_fshader_full.glsl index ae7d45b2..b2fc60e9 100755 --- a/assets/shaders/test_fshader_full.glsl +++ b/assets/shaders/test_fshader_full.glsl | |||
@@ -41,7 +41,7 @@ uniform vec4 u_lightAmb; | |||
41 | // diffuse map | 41 | // diffuse map |
42 | uniform sampler2D colMap; | 42 | uniform sampler2D colMap; |
43 | 43 | ||
44 | // environment map | 44 | // environment map |
45 | uniform sampler2D envMap; | 45 | uniform sampler2D envMap; |
46 | 46 | ||
47 | // normal map | 47 | // normal map |
@@ -62,45 +62,45 @@ varying vec3 vEyePos; | |||
62 | 62 | ||
63 | void main() | 63 | void main() |
64 | { | 64 | { |
65 | vec4 colMapTexel = vec4(texture2D(colMap, vec2(vNormal.w, vECPos.w)).rgb, 1.0); | 65 | vec4 colMapTexel = vec4(texture2D(colMap, vec2(vNormal.w, 1.0 - vECPos.w)).rgb, 1.0); |
66 | 66 | ||
67 | // normal mapping | 67 | // normal mapping |
68 | vec3 normal = normalize(vNormal.xyz); | 68 | vec3 normal = normalize(vNormal.xyz); |
69 | vec3 mapNormal = texture2D(normalMap, vec2(vNormal.w, vECPos.w)).xyz * 2.0 - 1.0; | 69 | vec3 mapNormal = texture2D(normalMap, vec2(vNormal.w, vECPos.w)).xyz * 2.0 - 1.0; |
70 | mapNormal = normalize(mapNormal.x*vec3(normal.z, 0.0, -normal.x) + vec3(0.0, mapNormal.y, 0.0) + mapNormal.z*normal); | 70 | mapNormal = normalize(mapNormal.x*vec3(normal.z, 0.0, -normal.x) + vec3(0.0, mapNormal.y, 0.0) + mapNormal.z*normal); |
71 | 71 | ||
72 | // create envmap coordinates | 72 | // create envmap coordinates |
73 | vec3 r = reflect( normalize(vec3(vECPos.xyz - vEyePos.xyz)), mapNormal); | 73 | vec3 r = reflect( normalize(vec3(vECPos.xyz - vEyePos.xyz)), mapNormal); |
74 | float m = 2.0 * sqrt( r.x*r.x + r.y*r.y + r.z*r.z ); | 74 | float m = 2.0 * sqrt( r.x*r.x + r.y*r.y + r.z*r.z ); |
75 | 75 | ||
76 | // calculate environment map texel | 76 | // calculate environment map texel |
77 | vec4 envMapTexel = vec4(texture2D(envMap, vec2(r.x/m + 0.5, r.y/m + 0.5)).rgb, 0.0); | 77 | vec4 envMapTexel = vec4(texture2D(envMap, vec2(r.x/m + 0.5, r.y/m + 0.5)).rgb, 0.0); |
78 | 78 | ||
79 | // lighting | 79 | // lighting |
80 | vec3 lightDirection = u_lightPos - vECPos.xyz; | 80 | vec3 lightDirection = u_lightPos - vECPos.xyz; |
81 | float lightDist = length(lightDirection); | 81 | float lightDist = length(lightDirection); |
82 | lightDirection /= lightDist; | 82 | lightDirection /= lightDist; |
83 | 83 | ||
84 | float attenuation = clamp(1.0 - lightDist * 0.01, 0.0, 1.0); | 84 | float attenuation = clamp(1.0 - lightDist * 0.01, 0.0, 1.0); |
85 | 85 | ||
86 | vec3 halfVec = normalize(lightDirection + vEyePos); | 86 | vec3 halfVec = normalize(lightDirection + vEyePos); |
87 | 87 | ||
88 | float diffuseIntensity = max(0.0, dot(mapNormal, lightDirection)); | 88 | float diffuseIntensity = max(0.0, dot(mapNormal, lightDirection)); |
89 | float specularModifier = max(0.0, dot(mapNormal, halfVec)); | 89 | float specularModifier = max(0.0, dot(mapNormal, halfVec)); |
90 | 90 | ||
91 | float pf; | 91 | float pf; |
92 | if(diffuseIntensity == 0.0) | 92 | if(diffuseIntensity == 0.0) |
93 | pf = 0.0; | 93 | pf = 0.0; |
94 | else | 94 | else |
95 | pf = pow(specularModifier, 76.0); | 95 | pf = pow(specularModifier, 76.0); |
96 | 96 | ||
97 | vec4 ambient = u_matAmbient * u_lightAmb; | 97 | vec4 ambient = u_matAmbient * u_lightAmb; |
98 | vec4 diffuse = u_matDiffuse * (colMapTexel + envMapTexel); | 98 | vec4 diffuse = u_matDiffuse * (colMapTexel + envMapTexel); |
99 | 99 | ||
100 | if (u_renderGlow <= 0.5) | 100 | if (u_renderGlow <= 0.5) |
101 | diffuse *= u_lightDiff * diffuseIntensity * attenuation; | 101 | diffuse *= u_lightDiff * diffuseIntensity * attenuation; |
102 | 102 | ||
103 | vec4 specular = 2.0 * pf * envMapTexel; | 103 | vec4 specular = 2.0 * pf * envMapTexel; |
104 | 104 | ||
105 | gl_FragColor = (colMapTexel*(ambient + diffuse)) + specular + vec4(0.0,0.0,0.0,1.0); | 105 | gl_FragColor = (colMapTexel*(ambient + diffuse)) + specular + vec4(0.0,0.0,0.0,1.0); |
106 | } | 106 | } |