Unlit.hlsl 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #include "Uniforms.hlsl"
  2. #include "Samplers.hlsl"
  3. #include "Transform.hlsl"
  4. #include "Fog.hlsl"
  5. void VS(float4 iPos : POSITION,
  6. float2 iTexCoord : TEXCOORD0,
  7. #ifdef VERTEXCOLOR
  8. float4 iColor : COLOR0,
  9. #endif
  10. #ifdef SKINNED
  11. float4 iBlendWeights : BLENDWEIGHT,
  12. int4 iBlendIndices : BLENDINDICES,
  13. #endif
  14. #ifdef INSTANCED
  15. float4x3 iModelInstance : TEXCOORD2,
  16. #endif
  17. #ifdef BILLBOARD
  18. float2 iSize : TEXCOORD1,
  19. #endif
  20. out float2 oTexCoord : TEXCOORD0,
  21. out float4 oWorldPos : TEXCOORD2,
  22. #ifdef VERTEXCOLOR
  23. out float4 oColor : COLOR0,
  24. #endif
  25. out float4 oPos : POSITION)
  26. {
  27. float4x3 modelMatrix = iModelMatrix;
  28. float3 worldPos = GetWorldPos(modelMatrix);
  29. oPos = GetClipPos(worldPos);
  30. oTexCoord = GetTexCoord(iTexCoord);
  31. oWorldPos = float4(worldPos, GetDepth(oPos));
  32. #ifdef VERTEXCOLOR
  33. oColor = iColor;
  34. #endif
  35. }
  36. void PS(float2 iTexCoord : TEXCOORD0,
  37. float4 iWorldPos: TEXCOORD2,
  38. #ifdef VERTEXCOLOR
  39. float4 iColor : COLOR0,
  40. #endif
  41. #ifdef PREPASS
  42. out float4 oDepth : COLOR1,
  43. #endif
  44. #ifdef DEFERRED
  45. out float4 oAlbedo : COLOR1,
  46. out float4 oNormal : COLOR2,
  47. out float4 oDepth : COLOR3,
  48. #endif
  49. out float4 oColor : COLOR0)
  50. {
  51. // Get material diffuse albedo
  52. #ifdef DIFFMAP
  53. float4 diffColor = cMatDiffColor * tex2D(sDiffMap, iTexCoord);
  54. #ifdef ALPHAMASK
  55. if (diffColor.a < 0.5)
  56. discard;
  57. #endif
  58. #else
  59. float4 diffColor = cMatDiffColor;
  60. #endif
  61. #ifdef VERTEXCOLOR
  62. diffColor *= iColor;
  63. #endif
  64. // Get fog factor
  65. #ifdef HEIGHTFOG
  66. float fogFactor = GetHeightFogFactor(iWorldPos.w, iWorldPos.y);
  67. #else
  68. float fogFactor = GetFogFactor(iWorldPos.w);
  69. #endif
  70. #if defined(PREPASS)
  71. // Fill light pre-pass G-Buffer
  72. oColor = float4(0.5, 0.5, 0.5, 1.0);
  73. oDepth = iWorldPos.w;
  74. #elif defined(DEFERRED)
  75. // Fill deferred G-buffer
  76. oColor = float4(GetFog(diffColor.rgb, fogFactor), diffColor.a);
  77. oAlbedo = float4(0.0, 0.0, 0.0, 0.0);
  78. oNormal = float4(0.5, 0.5, 0.5, 1.0);
  79. oDepth = iWorldPos.w;
  80. #else
  81. oColor = float4(GetFog(diffColor.rgb, fogFactor), diffColor.a);
  82. #endif
  83. }