Slang shaders for push constants sample
This commit is contained in:
parent
880b48485f
commit
22ae3726e6
2 changed files with 54 additions and 0 deletions
16
shaders/slang/pushconstants/pushconstants.frag.slang
Normal file
16
shaders/slang/pushconstants/pushconstants.frag.slang
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
/* Copyright (c) 2025, Sascha Willems
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct VSOutput
|
||||||
|
{
|
||||||
|
float3 Color;
|
||||||
|
};
|
||||||
|
|
||||||
|
[shader("fragment")]
|
||||||
|
float4 main(VSOutput input) : SV_TARGET
|
||||||
|
{
|
||||||
|
return float4(input.Color, 1.0);
|
||||||
|
}
|
||||||
38
shaders/slang/pushconstants/pushconstants.vert.slang
Normal file
38
shaders/slang/pushconstants/pushconstants.vert.slang
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
/* Copyright (c) 2025, Sascha Willems
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct VSInput
|
||||||
|
{
|
||||||
|
float3 Pos : POSITION0;
|
||||||
|
float3 Normal : NORMAL0;
|
||||||
|
float3 Color : COLOR0;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct UBO
|
||||||
|
{
|
||||||
|
float4x4 projection;
|
||||||
|
float4x4 model;
|
||||||
|
float4x4 view;
|
||||||
|
};
|
||||||
|
ConstantBuffer<UBO> ubo;
|
||||||
|
|
||||||
|
struct VSOutput
|
||||||
|
{
|
||||||
|
float4 Pos : SV_POSITION;
|
||||||
|
float3 Color;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Uniform entry-point parameters are automatically bound to push constants by slang
|
||||||
|
[shader("vertex")]
|
||||||
|
VSOutput main(VSInput input, uniform float4 pushColor, uniform float4 pushPosition)
|
||||||
|
{
|
||||||
|
VSOutput output;
|
||||||
|
output.Color = input.Color * pushColor.rgb;
|
||||||
|
float3 locPos = float3(mul(ubo.model, float4(input.Pos.xyz, 1.0)).xyz);
|
||||||
|
float3 worldPos = locPos + pushPosition.xyz;
|
||||||
|
output.Pos = mul(ubo.projection, mul(ubo.view, float4(worldPos.xyz, 1.0)));
|
||||||
|
return output;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue