Material.hlsl 2.6 KB

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