Unlit.hlsl 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #include "Uniforms.hlsl"
  2. #include "Samplers.hlsl"
  3. #include "Transform.hlsl"
  4. #include "Fog.hlsl"
  5. void VS(float4 iPos : POSITION,
  6. #ifndef NOUV
  7. float2 iTexCoord : TEXCOORD0,
  8. #endif
  9. #ifdef VERTEXCOLOR
  10. float4 iColor : COLOR0,
  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. #ifdef BILLBOARD
  20. float2 iSize : TEXCOORD1,
  21. #endif
  22. out float2 oTexCoord : TEXCOORD0,
  23. out float4 oWorldPos : TEXCOORD2,
  24. #ifdef VERTEXCOLOR
  25. out float4 oColor : COLOR0,
  26. #endif
  27. #if defined(D3D11) && defined(CLIPPLANE)
  28. out float oClip : SV_CLIPDISTANCE0,
  29. #endif
  30. out float4 oPos : OUTPOSITION)
  31. {
  32. // Define a 0,0 UV coord if not expected from the vertex data
  33. #ifdef NOUV
  34. float2 iTexCoord = float2(0.0, 0.0);
  35. #endif
  36. float4x3 modelMatrix = iModelMatrix;
  37. float3 worldPos = GetWorldPos(modelMatrix);
  38. oPos = GetClipPos(worldPos);
  39. oTexCoord = GetTexCoord(iTexCoord);
  40. oWorldPos = float4(worldPos, GetDepth(oPos));
  41. #if defined(D3D11) && defined(CLIPPLANE)
  42. oClip = dot(oPos, cClipPlane);
  43. #endif
  44. #ifdef VERTEXCOLOR
  45. oColor = iColor;
  46. #endif
  47. }
  48. void PS(float2 iTexCoord : TEXCOORD0,
  49. float4 iWorldPos: TEXCOORD2,
  50. #ifdef VERTEXCOLOR
  51. float4 iColor : COLOR0,
  52. #endif
  53. #if defined(D3D11) && defined(CLIPPLANE)
  54. float iClip : SV_CLIPDISTANCE0,
  55. #endif
  56. #ifdef PREPASS
  57. out float4 oDepth : OUTCOLOR1,
  58. #endif
  59. #ifdef DEFERRED
  60. out float4 oAlbedo : OUTCOLOR1,
  61. out float4 oNormal : OUTCOLOR2,
  62. out float4 oDepth : OUTCOLOR3,
  63. #endif
  64. out float4 oColor : OUTCOLOR0)
  65. {
  66. // Get material diffuse albedo
  67. #ifdef DIFFMAP
  68. float4 diffColor = cMatDiffColor * Sample2D(DiffMap, iTexCoord);
  69. #ifdef ALPHAMASK
  70. if (diffColor.a < 0.5)
  71. discard;
  72. #endif
  73. #else
  74. float4 diffColor = cMatDiffColor;
  75. #endif
  76. #ifdef VERTEXCOLOR
  77. diffColor *= iColor;
  78. #endif
  79. // Get fog factor
  80. #ifdef HEIGHTFOG
  81. float fogFactor = GetHeightFogFactor(iWorldPos.w, iWorldPos.y);
  82. #else
  83. float fogFactor = GetFogFactor(iWorldPos.w);
  84. #endif
  85. #if defined(PREPASS)
  86. // Fill light pre-pass G-Buffer
  87. oColor = float4(0.5, 0.5, 0.5, 1.0);
  88. oDepth = iWorldPos.w;
  89. #elif defined(DEFERRED)
  90. // Fill deferred G-buffer
  91. oColor = float4(GetFog(diffColor.rgb, fogFactor), diffColor.a);
  92. oAlbedo = float4(0.0, 0.0, 0.0, 0.0);
  93. oNormal = float4(0.5, 0.5, 0.5, 1.0);
  94. oDepth = iWorldPos.w;
  95. #else
  96. oColor = float4(GetFog(diffColor.rgb, fogFactor), diffColor.a);
  97. #endif
  98. }