diff --git a/data/shaders/lesson2.pxl.dxb b/data/shaders/lesson2.pxl.dxb new file mode 100644 index 0000000..be827dc Binary files /dev/null and b/data/shaders/lesson2.pxl.dxb differ diff --git a/data/shaders/lesson2.vtx.dxb b/data/shaders/lesson2.vtx.dxb new file mode 100644 index 0000000..91c1bc4 Binary files /dev/null and b/data/shaders/lesson2.vtx.dxb differ diff --git a/data/shaders/lesson3.pxl.dxb b/data/shaders/lesson3.pxl.dxb new file mode 100644 index 0000000..63b2cf7 Binary files /dev/null and b/data/shaders/lesson3.pxl.dxb differ diff --git a/data/shaders/lesson3.vtx.dxb b/data/shaders/lesson3.vtx.dxb new file mode 100644 index 0000000..90706df Binary files /dev/null and b/data/shaders/lesson3.vtx.dxb differ diff --git a/data/shaders/lesson6.pxl.dxb b/data/shaders/lesson6.pxl.dxb new file mode 100644 index 0000000..9db1e39 Binary files /dev/null and b/data/shaders/lesson6.pxl.dxb differ diff --git a/data/shaders/lesson6.vtx.dxb b/data/shaders/lesson6.vtx.dxb new file mode 100644 index 0000000..780dd22 Binary files /dev/null and b/data/shaders/lesson6.vtx.dxb differ diff --git a/data/shaders/lesson7.pxl.dxb b/data/shaders/lesson7.pxl.dxb new file mode 100644 index 0000000..fedd4b8 Binary files /dev/null and b/data/shaders/lesson7.pxl.dxb differ diff --git a/data/shaders/lesson7.vtx.dxb b/data/shaders/lesson7.vtx.dxb new file mode 100644 index 0000000..0050903 Binary files /dev/null and b/data/shaders/lesson7.vtx.dxb differ diff --git a/data/shaders/lesson8.pxl.dxb b/data/shaders/lesson8.pxl.dxb new file mode 100644 index 0000000..fedd4b8 Binary files /dev/null and b/data/shaders/lesson8.pxl.dxb differ diff --git a/data/shaders/lesson8.vtx.dxb b/data/shaders/lesson8.vtx.dxb new file mode 100644 index 0000000..f7aa695 Binary files /dev/null and b/data/shaders/lesson8.vtx.dxb differ diff --git a/scripts/compile_shaders.py b/scripts/compile_shaders.py index c5436c6..b48c92c 100755 --- a/scripts/compile_shaders.py +++ b/scripts/compile_shaders.py @@ -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") diff --git a/src/shaders/lesson2.hlsl b/src/shaders/lesson2.hlsl new file mode 100644 index 0000000..bd36137 --- /dev/null +++ b/src/shaders/lesson2.hlsl @@ -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); +} diff --git a/src/shaders/lesson3.hlsl b/src/shaders/lesson3.hlsl new file mode 100644 index 0000000..8f4f588 --- /dev/null +++ b/src/shaders/lesson3.hlsl @@ -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; +} diff --git a/src/shaders/lesson6.hlsl b/src/shaders/lesson6.hlsl new file mode 100644 index 0000000..59a830d --- /dev/null +++ b/src/shaders/lesson6.hlsl @@ -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 Texture : register(t0, space2); +SamplerState Sampler : register(s0, space2); + +half4 PixelMain(Vertex2Pixel input) : SV_Target0 +{ + return Texture.Sample(Sampler, input.texcoord); +} diff --git a/src/shaders/lesson7.hlsl b/src/shaders/lesson7.hlsl new file mode 100644 index 0000000..9144690 --- /dev/null +++ b/src/shaders/lesson7.hlsl @@ -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 Texture : register(t0, space2); +SamplerState Sampler : register(s0, space2); + +half4 PixelMain(Vertex2Pixel input) : SV_Target0 +{ + return input.color * Texture.Sample(Sampler, input.texcoord); +} diff --git a/src/shaders/lesson8.hlsl b/src/shaders/lesson8.hlsl new file mode 100644 index 0000000..066b817 --- /dev/null +++ b/src/shaders/lesson8.hlsl @@ -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 Texture : register(t0, space2); +SamplerState Sampler : register(s0, space2); + +half4 PixelMain(Vertex2Pixel input) : SV_Target0 +{ + return input.color * Texture.Sample(Sampler, input.texcoord); +}