Basic.hlsl 2.0 KB

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