mirror of
https://github.com/ScrelliCopter/NeHe-SDL_GPU.git
synced 2025-06-19 21:49:17 +10:00
shaders: Add Vulkan-only HLSL for Lesson9
This commit is contained in:
56
src/shaders/lesson9.hlsl
Normal file
56
src/shaders/lesson9.hlsl
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: (C) 2025 a dinosaur
|
||||||
|
* SPDX-License-Identifier: Zlib
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct VertexInput
|
||||||
|
{
|
||||||
|
float3 position : TEXCOORD0;
|
||||||
|
float2 texcoord : TEXCOORD1;
|
||||||
|
uint instanceID : SV_InstanceID;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct VertexInstance
|
||||||
|
{
|
||||||
|
float4x4 model;
|
||||||
|
float4 color;
|
||||||
|
};
|
||||||
|
|
||||||
|
StructuredBuffer<VertexInstance> Instances : register(t0, space0);
|
||||||
|
|
||||||
|
cbuffer VertexUniform : register(b0, space1)
|
||||||
|
{
|
||||||
|
float4x4 projection : packoffset(c0);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Vertex2Pixel
|
||||||
|
{
|
||||||
|
float4 position : SV_Position;
|
||||||
|
float2 texcoord : TEXCOORD0;
|
||||||
|
half4 color : COLOR0;
|
||||||
|
};
|
||||||
|
|
||||||
|
Vertex2Pixel VertexMain(VertexInput input)
|
||||||
|
{
|
||||||
|
//FIXME: Indexing dynamically like this works on Vulkan but not D3D12...
|
||||||
|
const VertexInstance instance = Instances[input.instanceID];
|
||||||
|
const float4x4 modelViewProj = mul(projection, instance.model);
|
||||||
|
|
||||||
|
Vertex2Pixel output;
|
||||||
|
output.position = mul(modelViewProj, float4(input.position, 1.0));
|
||||||
|
output.color = half4(instance.color);
|
||||||
|
output.texcoord = input.texcoord;
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
Texture2D<half4> Texture : register(t0, space2);
|
||||||
|
SamplerState Sampler : register(s0, space2);
|
||||||
|
|
||||||
|
#ifdef VULKAN
|
||||||
|
half4 FragmentMain(Vertex2Pixel input) : SV_Target0
|
||||||
|
#else
|
||||||
|
half4 PixelMain(Vertex2Pixel input) : SV_Target0
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
return input.color * Texture.Sample(Sampler, input.texcoord);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user