Unlit.hlsl 3.1 KB

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