__shdBulbLightWithNormalMap.fsh 1.0 KB

1234567891011121314151617181920212223242526272829
  1. varying vec2 v_vTexcoord;
  2. varying vec4 v_vColour;
  3. varying vec2 v_vPosition;
  4. uniform sampler2D u_sNormalMap;
  5. uniform vec2 u_vCameraVector; //cos, sin
  6. uniform vec4 u_vInfo;
  7. uniform vec4 u_vCamera;
  8. uniform float u_fSpecularIntensity;
  9. void main()
  10. {
  11. #ifdef _YY_HLSL11_
  12. vec2 objectPos = v_vPosition*vec2(1.0, -1.0);
  13. #else
  14. vec2 objectPos = v_vPosition;
  15. #endif
  16. vec3 lightPos = vec3((u_vInfo.xy - u_vCamera.xy) / u_vCamera.zw, u_vInfo.z);
  17. vec4 normalSpecular = texture2D(u_sNormalMap, 0.5 + 0.5*objectPos);
  18. vec3 normal = 2.0*normalSpecular.xyz - 1.0;
  19. normal.xy = mat2(u_vCameraVector.x, -u_vCameraVector.y, u_vCameraVector.y, u_vCameraVector.x)*normal.xy;
  20. gl_FragColor = v_vColour*texture2D(gm_BaseTexture, v_vTexcoord);
  21. gl_FragColor.rgb *= u_vInfo.w*((u_fSpecularIntensity*(1.0 - normalSpecular.w) + 1.0)*max(0.0, dot(normalize(lightPos - vec3(objectPos, 0.0)), normal)));
  22. gl_FragColor.rgb *= u_vInfo.w*(u_fSpecularIntensity*(1.0 - normalSpecular.w) + 1.0);
  23. }