mirror of
https://github.com/ScrelliCopter/NeHe-SDL_GPU.git
synced 2025-06-19 21:49:17 +10:00
shaders: Implement HLSL for lessons 2-8
This commit is contained in:
BIN
data/shaders/lesson2.pxl.dxb
Normal file
BIN
data/shaders/lesson2.pxl.dxb
Normal file
Binary file not shown.
BIN
data/shaders/lesson2.vtx.dxb
Normal file
BIN
data/shaders/lesson2.vtx.dxb
Normal file
Binary file not shown.
BIN
data/shaders/lesson3.pxl.dxb
Normal file
BIN
data/shaders/lesson3.pxl.dxb
Normal file
Binary file not shown.
BIN
data/shaders/lesson3.vtx.dxb
Normal file
BIN
data/shaders/lesson3.vtx.dxb
Normal file
Binary file not shown.
BIN
data/shaders/lesson6.pxl.dxb
Normal file
BIN
data/shaders/lesson6.pxl.dxb
Normal file
Binary file not shown.
BIN
data/shaders/lesson6.vtx.dxb
Normal file
BIN
data/shaders/lesson6.vtx.dxb
Normal file
Binary file not shown.
BIN
data/shaders/lesson7.pxl.dxb
Normal file
BIN
data/shaders/lesson7.pxl.dxb
Normal file
Binary file not shown.
BIN
data/shaders/lesson7.vtx.dxb
Normal file
BIN
data/shaders/lesson7.vtx.dxb
Normal file
Binary file not shown.
BIN
data/shaders/lesson8.pxl.dxb
Normal file
BIN
data/shaders/lesson8.pxl.dxb
Normal file
Binary file not shown.
BIN
data/shaders/lesson8.vtx.dxb
Normal file
BIN
data/shaders/lesson8.vtx.dxb
Normal file
Binary file not shown.
@@ -213,7 +213,7 @@ def compile_dxbc_shader(shader: Shader, type: str, flags: list[str] | None = Non
|
||||
def compile_shaders() -> None:
|
||||
build_spirv = True
|
||||
build_metal = True
|
||||
build_dxil = False
|
||||
build_dxil = True
|
||||
build_dxbc = False
|
||||
lessons = [ "lesson2", "lesson3", "lesson6", "lesson7", "lesson8", "lesson9" ]
|
||||
src_dir = Path("src/shaders")
|
||||
|
||||
31
src/shaders/lesson2.hlsl
Normal file
31
src/shaders/lesson2.hlsl
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: (C) 2025 a dinosaur
|
||||
* SPDX-License-Identifier: Zlib
|
||||
*/
|
||||
|
||||
struct VertexInput
|
||||
{
|
||||
float3 position : TEXCOORD0;
|
||||
};
|
||||
|
||||
cbuffer VertexUniform : register(b0, space1)
|
||||
{
|
||||
float4x4 viewproj : packoffset(c0);
|
||||
};
|
||||
|
||||
struct Vertex2Pixel
|
||||
{
|
||||
float4 position : SV_Position;
|
||||
};
|
||||
|
||||
Vertex2Pixel VertexMain(VertexInput input)
|
||||
{
|
||||
Vertex2Pixel output;
|
||||
output.position = mul(viewproj, float4(input.position, 1.0));
|
||||
return output;
|
||||
}
|
||||
|
||||
half4 PixelMain(Vertex2Pixel input) : SV_Target0
|
||||
{
|
||||
return half4(1.0, 1.0, 1.0, 1.0);
|
||||
}
|
||||
34
src/shaders/lesson3.hlsl
Normal file
34
src/shaders/lesson3.hlsl
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: (C) 2025 a dinosaur
|
||||
* SPDX-License-Identifier: Zlib
|
||||
*/
|
||||
|
||||
struct VertexInput
|
||||
{
|
||||
float3 position : TEXCOORD0;
|
||||
float4 color : TEXCOORD1;
|
||||
};
|
||||
|
||||
cbuffer VertexUniform : register(b0, space1)
|
||||
{
|
||||
float4x4 viewproj : packoffset(c0);
|
||||
};
|
||||
|
||||
struct Vertex2Pixel
|
||||
{
|
||||
float4 position : SV_Position;
|
||||
half4 color : COLOR0;
|
||||
};
|
||||
|
||||
Vertex2Pixel VertexMain(VertexInput input)
|
||||
{
|
||||
Vertex2Pixel output;
|
||||
output.position = mul(viewproj, float4(input.position, 1.0));
|
||||
output.color = half4(input.color);
|
||||
return output;
|
||||
}
|
||||
|
||||
half4 PixelMain(Vertex2Pixel input) : SV_Target0
|
||||
{
|
||||
return input.color;
|
||||
}
|
||||
37
src/shaders/lesson6.hlsl
Normal file
37
src/shaders/lesson6.hlsl
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: (C) 2025 a dinosaur
|
||||
* SPDX-License-Identifier: Zlib
|
||||
*/
|
||||
|
||||
struct VertexInput
|
||||
{
|
||||
float3 position : TEXCOORD0;
|
||||
float2 texcoord : TEXCOORD1;
|
||||
};
|
||||
|
||||
cbuffer VertexUniform : register(b0, space1)
|
||||
{
|
||||
float4x4 viewproj : packoffset(c0);
|
||||
};
|
||||
|
||||
struct Vertex2Pixel
|
||||
{
|
||||
float4 position : SV_Position;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
Vertex2Pixel VertexMain(VertexInput input)
|
||||
{
|
||||
Vertex2Pixel output;
|
||||
output.position = mul(viewproj, float4(input.position, 1.0));
|
||||
output.texcoord = input.texcoord;
|
||||
return output;
|
||||
}
|
||||
|
||||
Texture2D<half4> Texture : register(t0, space2);
|
||||
SamplerState Sampler : register(s0, space2);
|
||||
|
||||
half4 PixelMain(Vertex2Pixel input) : SV_Target0
|
||||
{
|
||||
return Texture.Sample(Sampler, input.texcoord);
|
||||
}
|
||||
59
src/shaders/lesson7.hlsl
Normal file
59
src/shaders/lesson7.hlsl
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: (C) 2025 a dinosaur
|
||||
* SPDX-License-Identifier: Zlib
|
||||
*/
|
||||
|
||||
struct VertexInput
|
||||
{
|
||||
float3 position : TEXCOORD0;
|
||||
float2 texcoord : TEXCOORD1;
|
||||
float3 normal : TEXCOORD2;
|
||||
};
|
||||
|
||||
cbuffer VertexUniform : register(b0, space1)
|
||||
{
|
||||
float4x4 modelView : packoffset(c0);
|
||||
float4x4 projection : packoffset(c4);
|
||||
};
|
||||
|
||||
cbuffer LightUniform : register(b1, space1)
|
||||
{
|
||||
float4 lightAmbient : packoffset(c0);
|
||||
float4 lightDiffuse : packoffset(c1);
|
||||
float4 lightPosition : packoffset(c2);
|
||||
};
|
||||
|
||||
struct Vertex2Pixel
|
||||
{
|
||||
float4 position : SV_Position;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
half4 color : COLOR0;
|
||||
};
|
||||
|
||||
Vertex2Pixel VertexMain(VertexInput input)
|
||||
{
|
||||
const float4 position = mul(modelView, float4(input.position, 1.0));
|
||||
const float3 normal = normalize(mul(modelView, float4(input.normal, 0.0))).xyz;
|
||||
|
||||
const float3 lightVec = lightPosition.xyz - position.xyz;
|
||||
const float lightDist2 = dot(lightVec, lightVec);
|
||||
const float3 dir = rsqrt(lightDist2) * lightVec;
|
||||
const float lambert = max(0.0, dot(normal, dir));
|
||||
|
||||
const half3 ambient = 0.04 + 0.2 * half3(lightAmbient.rgb);
|
||||
const half3 diffuse = 0.8 * half3(lightDiffuse.rgb);
|
||||
|
||||
Vertex2Pixel output;
|
||||
output.position = mul(projection, position);
|
||||
output.texcoord = input.texcoord;
|
||||
output.color = half4(ambient + lambert * diffuse, 1.0);
|
||||
return output;
|
||||
}
|
||||
|
||||
Texture2D<half4> Texture : register(t0, space2);
|
||||
SamplerState Sampler : register(s0, space2);
|
||||
|
||||
half4 PixelMain(Vertex2Pixel input) : SV_Target0
|
||||
{
|
||||
return input.color * Texture.Sample(Sampler, input.texcoord);
|
||||
}
|
||||
40
src/shaders/lesson8.hlsl
Normal file
40
src/shaders/lesson8.hlsl
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: (C) 2025 a dinosaur
|
||||
* SPDX-License-Identifier: Zlib
|
||||
*/
|
||||
|
||||
struct VertexInput
|
||||
{
|
||||
float3 position : TEXCOORD0;
|
||||
float2 texcoord : TEXCOORD1;
|
||||
};
|
||||
|
||||
cbuffer VertexUniform : register(b0, space1)
|
||||
{
|
||||
float4x4 viewproj : packoffset(c0);
|
||||
float4 color : packoffset(c4);
|
||||
};
|
||||
|
||||
struct Vertex2Pixel
|
||||
{
|
||||
float4 position : SV_Position;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
half4 color : COLOR0;
|
||||
};
|
||||
|
||||
Vertex2Pixel VertexMain(VertexInput input)
|
||||
{
|
||||
Vertex2Pixel output;
|
||||
output.position = mul(viewproj, float4(input.position, 1.0));
|
||||
output.texcoord = input.texcoord;
|
||||
output.color = half4(color);
|
||||
return output;
|
||||
}
|
||||
|
||||
Texture2D<half4> Texture : register(t0, space2);
|
||||
SamplerState Sampler : register(s0, space2);
|
||||
|
||||
half4 PixelMain(Vertex2Pixel input) : SV_Target0
|
||||
{
|
||||
return input.color * Texture.Sample(Sampler, input.texcoord);
|
||||
}
|
||||
Reference in New Issue
Block a user