yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
2a5d5b323
master
1//TEST(compute):COMPARE_COMPUTE: -shaderobj 2//TEST(compute):COMPARE_COMPUTE:-cpu -shaderobj 3 4//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer 5RWStructuredBuffer<float> outputBuffer; 6 7struct DisneyBRDFPattern 8{ 9 float3 baseColor; 10 float3 normal; 11 float specular, metallic, roughness; 12 float opacity; 13 float3 emmissive; 14 float ambientOcclusion; 15}; 16 17struct VertexPosition 18{ 19 float3 pos; 20 float3 normal; 21 float2 uv; 22}; 23 24struct CameraView 25{ 26 float3 camPos; 27 float3 camDir; 28}; 29 30interface IVertexInterpolant 31{ 32 float4 getVertexColor(int index); 33 int getVertexColorCount(); 34 float2 getUV(int index); 35 int getUVCount(); 36} 37 38interface IDisneyBRDFPattern 39{ 40 __generic<TVertexInterpolant:IVertexInterpolant> 41 DisneyBRDFPattern evalPattern( 42 CameraView cam, 43 VertexPosition vWorld, 44 VertexPosition vObject, 45 TVertexInterpolant interpolants); 46} 47 48struct StandardVertexInterpolant : IVertexInterpolant 49{ 50 float4 getVertexColor(int index) { return float4(0.0); } 51 int getVertexColorCount() { return 0;} 52 float2 getUV(int index) { return float2(0.0); } 53 int getUVCount() {return 1; } 54}; 55 56struct MaterialPattern1 : IDisneyBRDFPattern 57{ 58 __generic<TVertexInterpolant:IVertexInterpolant> 59 DisneyBRDFPattern evalPattern( 60 CameraView cam, 61 VertexPosition vWorld, 62 VertexPosition vObject, 63 TVertexInterpolant interpolants) 64 { 65 DisneyBRDFPattern rs; 66 rs.baseColor = float3(0.5); 67 rs.opacity = 1.0; 68 return rs; 69 } 70}; 71 72__generic<TVertexInterpolant:IVertexInterpolant, TPattern : IDisneyBRDFPattern> 73float test(TVertexInterpolant vertInterps, TPattern pattern) 74{ 75 CameraView cam; 76 VertexPosition vW, vO; 77 DisneyBRDFPattern rs = pattern.evalPattern(cam, vW, vO, vertInterps); 78 return rs.baseColor.x; 79} 80[numthreads(4, 1, 1)] 81void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 82{ 83 StandardVertexInterpolant vertInterp; 84 MaterialPattern1 mp1; 85 float outVal = test<StandardVertexInterpolant, MaterialPattern1>(vertInterp, mp1); 86 outputBuffer[dispatchThreadID.x] = outVal; 87}