yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
65a761ac6
master
1// shaders.slang 2 3// 4// This file provides a simple vertex and fragment shader that can be compiled 5// using Slang. This code should also be valid as HLSL, and thus it does not 6// use any of the new language features supported by Slang. 7// 8 9// Uniform data to be passed from application -> shader. 10cbuffer Uniforms 11{ 12 float4x4 modelViewProjection; 13} 14 15// Per-vertex attributes to be assembled from bound vertex buffers. 16struct AssembledVertex 17{ 18 float3 position : POSITION; 19 float3 color : COLOR; 20}; 21 22// Output of the vertex shader, and input to the fragment shader. 23struct CoarseVertex 24{ 25 float3 color; 26}; 27 28// Output of the fragment shader 29struct Fragment 30{ 31 float4 color; 32}; 33 34// Vertex Shader 35 36struct VertexStageOutput 37{ 38 CoarseVertex coarseVertex : CoarseVertex; 39 float4 sv_position : SV_Position; 40}; 41 42[shader("vertex")] 43VertexStageOutput vertexMain( 44 AssembledVertex assembledVertex) 45{ 46 VertexStageOutput output; 47 48 float3 position = assembledVertex.position; 49 float3 color = assembledVertex.color; 50 51 output.coarseVertex.color = color; 52 output.sv_position = mul(modelViewProjection, float4(position, 1.0)); 53 54 return output; 55} 56 57// Fragment Shader 58 59[shader("fragment")] 60Fragment fragmentMain( 61 CoarseVertex coarseVertex : CoarseVertex) : SV_Target 62{ 63 float3 color = coarseVertex.color; 64 65 Fragment output; 66 output.color = float4(color, 1.0); 67 return output; 68}