Basic.hlsl 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #include "Uniforms.hlsl"
  2. #include "Samplers.hlsl"
  3. #include "Transform.hlsl"
  4. void VS(float4 iPos : POSITION,
  5. #ifdef DIFFMAP
  6. float2 iTexCoord : TEXCOORD0,
  7. #endif
  8. #ifdef VERTEXCOLOR
  9. float4 iColor : COLOR0,
  10. #endif
  11. #ifdef SKINNED
  12. float4 iBlendWeights : BLENDWEIGHT,
  13. int4 iBlendIndices : BLENDINDICES,
  14. #endif
  15. #ifdef INSTANCED
  16. float4x3 iModelInstance : TEXCOORD2,
  17. #endif
  18. #ifdef BILLBOARD
  19. float2 iSize : TEXCOORD1,
  20. #endif
  21. #ifdef DIFFMAP
  22. out float2 oTexCoord : TEXCOORD0,
  23. #endif
  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. float4x3 modelMatrix = iModelMatrix;
  33. float3 worldPos = GetWorldPos(modelMatrix);
  34. oPos = GetClipPos(worldPos);
  35. #if defined(D3D11) && defined(CLIPPLANE)
  36. oClip = dot(oPos, cClipPlane);
  37. #endif
  38. #ifdef VERTEXCOLOR
  39. oColor = iColor;
  40. #endif
  41. #ifdef DIFFMAP
  42. oTexCoord = iTexCoord;
  43. #endif
  44. }
  45. void PS(
  46. #if defined(DIFFMAP) || defined(ALPHAMAP)
  47. float2 iTexCoord : TEXCOORD0,
  48. #endif
  49. #ifdef VERTEXCOLOR
  50. float4 iColor : COLOR0,
  51. #endif
  52. #if defined(D3D11) && defined(CLIPPLANE)
  53. float iClip : SV_CLIPDISTANCE0,
  54. #endif
  55. out float4 oColor : OUTCOLOR0)
  56. {
  57. float4 diffColor = cMatDiffColor;
  58. #ifdef VERTEXCOLOR
  59. diffColor *= iColor;
  60. #endif
  61. #if (!defined(DIFFMAP)) && (!defined(ALPHAMAP))
  62. oColor = diffColor;
  63. #endif
  64. #ifdef DIFFMAP
  65. float4 diffInput = Sample2D(DiffMap, iTexCoord);
  66. #ifdef ALPHAMASK
  67. if (diffInput.a < 0.5)
  68. discard;
  69. #endif
  70. oColor = diffColor * diffInput;
  71. #endif
  72. #ifdef ALPHAMAP
  73. float alphaInput = Sample2D(DiffMap, iTexCoord).a;
  74. oColor = float4(diffColor.rgb, diffColor.a * alphaInput);
  75. #endif
  76. }