yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
2aaa91007
master
1//TEST:SIMPLE(filecheck=CHECK): -target spirv 2 3// CHECK: OpEntryPoint 4 5static extern const bool _AlphaTest = false; 6static extern const bool _BaseColorMap = false; 7static extern const bool _NormalMap = false; 8static extern const bool _EmissiveMap = false; 9static extern const bool _MetallicRoughnessMap = false; 10 11interface IVertexInput 12{ 13 float3 GetPosition(); 14 float3 GetNormal(); 15 float4 GetTangent(); 16 float2 GetUV(); 17 float4 GetBone(); 18} 19 20struct StandardVertexInput : IVertexInput 21{ 22 float3 position; 23 float3 normal; 24 float4 tangent; 25 float2 uv; 26 27 float3 GetPosition() {return position;} 28 float3 GetNormal() {return normal;} 29 float4 GetTangent() {return tangent;} 30 float2 GetUV() { return uv;} 31 float4 GetBone() { return float4(0,0,0,0);} 32} 33 34extern struct VertexInput : IVertexInput = StandardVertexInput; 35 36struct PushConstant 37{ 38 float4x4 model; 39 float4x4 invTspModel; 40} 41 42[vk_push_constant] 43PushConstant pconst; 44 45struct VertexOutput 46{ 47 float4 position : SV_Position; 48 float3 positionWS; 49 float3 normalWS; 50 float3 tangentWS; 51 float3 bitangentWS; 52 float2 uv; 53} 54 55 56 57VertexOutput SceneLitVertex(VertexInput input) 58{ 59 VertexOutput output; 60 float3 vertexPos = input.GetPosition(); 61 float3 normal = input.GetNormal(); 62 float4 tangent = input.GetTangent(); 63 64 output.positionWS = mul(pconst.model, float4(vertexPos, 1)).xyz; 65 66 matrix<float,3,3> model33 = (float3x3)pconst.invTspModel; 67 output.normalWS = mul(model33, normal).xyz; 68 output.tangentWS = mul(model33, tangent.xyz); 69 output.bitangentWS = tangent.w * cross(output.normalWS, output.tangentWS); 70 output.uv = input.GetUV(); 71 72 float4x4 vp = {}; 73 output.position = mul(vp, float4(output.positionWS, 1)); 74 75 return output; 76} 77 78 79[shader("vertex")] 80VertexOutput VertexMain(VertexInput input) 81{ 82 return SceneLitVertex(input); 83} 84 85struct PerMaterial 86{ 87 float4 baseColorFactor; 88 float4 emissive; 89 float roughness; 90 float metallic; 91 float alphaCutoff; 92 93 Sampler2D baseColorTex; 94 Sampler2D normalMap; 95 Sampler2D metallicRoughnessMap; 96 Sampler2D emissiveMap; 97}; 98 99ParameterBlock<PerMaterial> perMaterial; 100 101struct FragmentOutput 102{ 103 float4 color : SV_Target0; 104} 105 106FragmentOutput SceneLitFragment(VertexOutput input) 107{ 108 FragmentOutput output; 109 output.color = 0; 110 111 return output; 112} 113 114[shader("fragment")] 115FragmentOutput FragmentMain(VertexOutput input) 116{ 117 return SceneLitFragment(input); 118}