normalmap.fsh 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Effect applies normalmapped lighting to a 2D sprite.
  2. uniform sampler2D TextureSampler;
  3. uniform sampler2D NormalSampler;
  4. uniform vec3 LightDirection;
  5. vec3 LightColor = vec3(1.5);
  6. vec3 AmbientColor = vec3(0.0);
  7. void main()
  8. {
  9. // Look up the texture and normalmap values.
  10. vec4 tex = texture2D(TextureSampler, gl_TexCoord[0].xy);
  11. vec3 normal = texture2D(NormalSampler, gl_TexCoord[0].xy).rgb * 2.0 - 1.0;
  12. // Compute lighting.
  13. float lightAmount = max(dot(normal, LightDirection),0.0);
  14. vec4 color = gl_Color;
  15. color.rgb *= AmbientColor + lightAmount * LightColor;
  16. gl_FragColor = tex * color;
  17. }
  18. //float3 LightDirection;
  19. //float3 LightColor = 1.5;
  20. //float3 AmbientColor = 0;
  21. //sampler TextureSampler : register(s0);
  22. //sampler NormalSampler : register(s1);
  23. //float4 main(float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
  24. //{
  25. // Look up the texture and normalmap values.
  26. // float4 tex = tex2D(TextureSampler, texCoord);
  27. // float3 normal = tex2D(NormalSampler, texCoord);
  28. // Compute lighting.
  29. // float lightAmount = max(dot(normal, LightDirection), 0);
  30. // color.rgb *= AmbientColor + lightAmount * LightColor;
  31. // return tex * color;
  32. //}
  33. //technique Normalmap
  34. //{
  35. // pass Pass1
  36. // {
  37. // PixelShader = compile ps_2_0 main();
  38. // }
  39. //}