emd22

Slang Geometry Shader

Oct 11th, 2025
701
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module Geometry;
  2.  
  3.  
  4. struct VSOut
  5. {
  6.     float4 vPosition : SV_Position;
  7.     float3 vNormal   : NORMAL;
  8.     float2 vUV       : TEXCOORD0;
  9. };
  10.  
  11. struct VSIn
  12. {
  13.     float3 vPosition : ATTR0;
  14.     float3 vNormal : ATTR1;
  15.     float2 vUV : ATTR2;
  16. };
  17.  
  18. struct VSPushConsts
  19. {
  20.     float4x4 mMVP;
  21.     float3x3 mNormalMatrix;
  22.     uint uiMaterialIndex;
  23. };
  24.  
  25. [[vk::push_constant]] VSPushConsts VSConst;
  26.  
  27. [shader("vertex")]
  28.  
  29. VSOut VertexMain(VSIn in)
  30. {
  31.     VSOut out;
  32.  
  33.     out.vPosition = mul(float4(in.vPosition, 1.0), VSConst.mMVP);
  34.  
  35.     out.vNormal = mul(in.vNormal, VSConst.mNormalMatrix);
  36.     out.vUV = in.vUV;
  37.  
  38.     return out;
  39. }
  40.  
  41.  
  42. #include "./MaterialProperties.slang.inc"
  43.  
  44. struct FSOut {
  45.     float4 vAlbedo : SV_Target0;
  46.     float4 vNormal : SV_Target1;
  47.  
  48. };
  49.  
  50. struct FSIn
  51. {
  52.     float3 vNormal : NORMAL;
  53.     float2 vUV : TEXCOORD0;
  54. };
  55.  
  56. layout(set = 0, binding = 0) Sampler2D sAlbedo;
  57. layout(set = 1, binding = 0) StructuredBuffer<Material> bMaterialBuffer;
  58.  
  59. [shader("fragment")]
  60.  
  61. FSOut FragmentMain(FSIn in)
  62. {
  63.     FSOut out;
  64.  
  65.     float4 material_color = unpackUnorm4x8ToFloat(bMaterialBuffer[VSConst.uiMaterialIndex].uiBaseColor);
  66.     out.vAlbedo = float4(sAlbedo.Sample(in.vUV).rgb, 1.0) + material_color;
  67.     out.vNormal = float4(in.vNormal, 1.0f);
  68.  
  69.     return out;
  70. }
  71.  
Advertisement
Add Comment
Please, Sign In to add comment