yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Matthew MoultonImprove documentation and example formatting consistency (#4299)78d34f3b3

master
1014 B52 linesraw
1// Vertex and fragment shader to draw a textured quad on screen.
2
3cbuffer Uniforms
4{
5    int x;
6    int y;
7    int width;
8    int height;
9    int viewWidth;
10    int viewHeight;
11    Texture2D texture;
12    SamplerState sampler;
13}
14
15struct AssembledVertex
16{
17    float3	position : POSITION;
18};
19
20struct Fragment
21{
22    float4 color;
23};
24
25struct VertexStageOutput
26{
27    float2 uv : UV;
28    float4 sv_position : SV_Position;
29};
30
31[shader("vertex")]
32VertexStageOutput vertexMain(
33    AssembledVertex assembledVertex)
34{
35    VertexStageOutput output;
36
37    float3 position = assembledVertex.position;
38
39    output.uv = position.xy;
40    output.sv_position.x = (x + position.x * width) / (float)viewWidth * 2.0f - 1.0f;
41    output.sv_position.y = -((y + position.y * height) / (float)viewHeight * 2.0f - 1.0f);
42    output.sv_position.z = 0.5;
43    output.sv_position.w = 1.0;
44    return output;
45}
46
47[shader("fragment")]
48float4 fragmentMain(
49    float2 uv : UV) : SV_Target
50{
51    return float4(texture.Sample(sampler, uv).xyz, 1.0);
52}