Material.hlsl 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #pragma warning(disable:3557)
  2. #include "Uniforms.hlsl"
  3. #include "Samplers.hlsl"
  4. #include "Transform.hlsl"
  5. #include "ScreenPos.hlsl"
  6. #include "Fog.hlsl"
  7. #include "Lighting.hlsl"
  8. void VS(float4 iPos : POSITION,
  9. #ifdef NUMVERTEXLIGHTS
  10. float3 iNormal : NORMAL,
  11. #endif
  12. #ifdef SKINNED
  13. float4 iBlendWeights : BLENDWEIGHT,
  14. int4 iBlendIndices : BLENDINDICES,
  15. #endif
  16. #ifdef INSTANCED
  17. float4x3 iModelInstance : TEXCOORD2,
  18. #endif
  19. float2 iTexCoord : TEXCOORD0,
  20. out float4 oTexCoord : TEXCOORD0,
  21. out float3 oVertexLighting : TEXCOORD1,
  22. out float4 oScreenPos : TEXCOORD2,
  23. #ifdef VERTEXCOLOR
  24. out float4 oColor : COLOR0,
  25. #endif
  26. out float4 oPos : POSITION)
  27. {
  28. float4x3 modelMatrix = iModelMatrix;
  29. float3 worldPos = GetWorldPos(modelMatrix);
  30. oPos = GetClipPos(worldPos);
  31. oTexCoord = float4(GetTexCoord(iTexCoord), GetZonePos(worldPos), GetDepth(oPos));
  32. oScreenPos = GetScreenPos(oPos);
  33. oVertexLighting = 0.0;
  34. #ifdef NUMVERTEXLIGHTS
  35. float3 normal = GetWorldNormal(modelMatrix);
  36. for (int i = 0; i < NUMVERTEXLIGHTS; ++i)
  37. oVertexLighting += GetVertexLight(i, worldPos, normal) * cVertexLights[i * 3].rgb;
  38. #endif
  39. #ifdef VERTEXCOLOR
  40. oColor = iColor;
  41. #endif
  42. }
  43. void PS(float4 iTexCoord : TEXCOORD0,
  44. float3 iVertexLighting : TEXCOORD1,
  45. float4 iScreenPos : TEXCOORD2,
  46. #ifdef VERTEXCOLOR
  47. float4 iColor : COLOR0,
  48. #endif
  49. out float4 oColor : COLOR0)
  50. {
  51. #ifdef DIFFMAP
  52. float4 diffInput = tex2D(sDiffMap, iTexCoord.xy);
  53. #ifdef ALPHAMASK
  54. if (diffInput.a < 0.5)
  55. discard;
  56. #endif
  57. float3 diffColor = cMatDiffColor.rgb * diffInput.rgb;
  58. #else
  59. float3 diffColor = cMatDiffColor.rgb;
  60. #endif
  61. #ifdef SPECMAP
  62. float specIntensity = cMatSpecProperties.x * tex2D(sSpecMap, iTexCoord.xy).g;
  63. #else
  64. float specIntensity = cMatSpecProperties.x;
  65. #endif
  66. // Lights are accumulated at half intensity. Bring back to full intensity now
  67. float4 lightInput = 2.0 * tex2Dproj(sLightBuffer, iScreenPos);
  68. float3 lightSpecColor = lightInput.a * (lightInput.rgb / GetIntensity(lightInput.rgb));
  69. float3 finalColor = (GetAmbient(iTexCoord.z) + iVertexLighting + lightInput.rgb) * diffColor + lightSpecColor * specIntensity;
  70. oColor = float4(GetFog(finalColor, iTexCoord.w), 1.0);
  71. }