mirror of
https://github.com/ScrelliCopter/NeHe-SDL_GPU.git
synced 2025-06-19 21:49:17 +10:00
Replace GLSL Vulkan shaders with HLSL compiled to SPIR-V by DXC
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -435,9 +435,9 @@ bool NeHe_LoadShaders(NeHeContext* restrict ctx,
|
|||||||
{
|
{
|
||||||
const SDL_GPUShaderFormat format = SDL_GPU_SHADERFORMAT_SPIRV;
|
const SDL_GPUShaderFormat format = SDL_GPU_SHADERFORMAT_SPIRV;
|
||||||
SDL_memcpy(&path[basenameLen], ".vtx.spv", 9);
|
SDL_memcpy(&path[basenameLen], ".vtx.spv", 9);
|
||||||
vtxShader = LoadShader(ctx, path, info, format, SDL_GPU_SHADERSTAGE_VERTEX, "main");
|
vtxShader = LoadShader(ctx, path, info, format, SDL_GPU_SHADERSTAGE_VERTEX, "VertexMain");
|
||||||
SDL_memcpy(&path[basenameLen], ".frg.spv", 9);
|
SDL_memcpy(&path[basenameLen], ".frg.spv", 9);
|
||||||
frgShader = LoadShader(ctx, path, info, format, SDL_GPU_SHADERSTAGE_FRAGMENT, "main");
|
frgShader = LoadShader(ctx, path, info, format, SDL_GPU_SHADERSTAGE_FRAGMENT, "FragmentMain");
|
||||||
}
|
}
|
||||||
else if (availableFormats & SDL_GPU_SHADERFORMAT_DXIL) // Direct3D 12 Shader Model 6.0
|
else if (availableFormats & SDL_GPU_SHADERFORMAT_DXIL) // Direct3D 12 Shader Model 6.0
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: (C) 2025 a dinosaur
|
|
||||||
* SPDX-License-Identifier: Zlib
|
|
||||||
*/
|
|
||||||
|
|
||||||
#version 450
|
|
||||||
|
|
||||||
#ifdef VERTEX
|
|
||||||
|
|
||||||
layout(location = 0) in vec3 i_position;
|
|
||||||
|
|
||||||
layout(set = 1, binding = 0) uniform UBO
|
|
||||||
{
|
|
||||||
mat4 u_viewproj;
|
|
||||||
};
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
gl_Position = u_viewproj * vec4(i_position, 1.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
layout(location = 0) out vec4 o_color;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
o_color = vec4(1.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -25,7 +25,11 @@ Vertex2Pixel VertexMain(VertexInput input)
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef VULKAN
|
||||||
|
half4 FragmentMain(Vertex2Pixel input) : SV_Target0
|
||||||
|
#else
|
||||||
half4 PixelMain(Vertex2Pixel input) : SV_Target0
|
half4 PixelMain(Vertex2Pixel input) : SV_Target0
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
return half4(1.0, 1.0, 1.0, 1.0);
|
return half4(1.0, 1.0, 1.0, 1.0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: (C) 2025 a dinosaur
|
|
||||||
* SPDX-License-Identifier: Zlib
|
|
||||||
*/
|
|
||||||
|
|
||||||
#version 450
|
|
||||||
|
|
||||||
#ifdef VERTEX
|
|
||||||
|
|
||||||
layout(location = 0) in vec3 i_position;
|
|
||||||
layout(location = 1) in vec4 i_color;
|
|
||||||
|
|
||||||
layout(location = 0) out vec4 v_color;
|
|
||||||
|
|
||||||
layout(set = 1, binding = 0) uniform UBO
|
|
||||||
{
|
|
||||||
mat4 u_viewproj;
|
|
||||||
};
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
v_color = i_color;
|
|
||||||
gl_Position = u_viewproj * vec4(i_position, 1.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
layout(location = 0) in vec4 v_color;
|
|
||||||
|
|
||||||
layout(location = 0) out vec4 o_color;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
o_color = v_color;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -28,7 +28,11 @@ Vertex2Pixel VertexMain(VertexInput input)
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef VULKAN
|
||||||
|
half4 FragmentMain(Vertex2Pixel input) : SV_Target0
|
||||||
|
#else
|
||||||
half4 PixelMain(Vertex2Pixel input) : SV_Target0
|
half4 PixelMain(Vertex2Pixel input) : SV_Target0
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
return input.color;
|
return input.color;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: (C) 2025 a dinosaur
|
|
||||||
* SPDX-License-Identifier: Zlib
|
|
||||||
*/
|
|
||||||
|
|
||||||
#version 450
|
|
||||||
|
|
||||||
#ifdef VERTEX
|
|
||||||
|
|
||||||
layout(location = 0) in vec3 i_position;
|
|
||||||
layout(location = 1) in vec2 i_texcoord;
|
|
||||||
|
|
||||||
layout(location = 0) out vec2 v_texcoord;
|
|
||||||
|
|
||||||
layout(set = 1, binding = 0) uniform UBO
|
|
||||||
{
|
|
||||||
mat4 u_viewproj;
|
|
||||||
};
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
v_texcoord = i_texcoord;
|
|
||||||
gl_Position = u_viewproj * vec4(i_position, 1.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
layout(location = 0) in vec2 v_texcoord;
|
|
||||||
|
|
||||||
layout(location = 0) out vec4 o_color;
|
|
||||||
|
|
||||||
layout(set = 2, binding = 0) uniform sampler2D u_texture;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
o_color = texture(u_texture, v_texcoord);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -31,7 +31,11 @@ Vertex2Pixel VertexMain(VertexInput input)
|
|||||||
Texture2D<half4> Texture : register(t0, space2);
|
Texture2D<half4> Texture : register(t0, space2);
|
||||||
SamplerState Sampler : register(s0, space2);
|
SamplerState Sampler : register(s0, space2);
|
||||||
|
|
||||||
|
#ifdef VULKAN
|
||||||
|
half4 FragmentMain(Vertex2Pixel input) : SV_Target0
|
||||||
|
#else
|
||||||
half4 PixelMain(Vertex2Pixel input) : SV_Target0
|
half4 PixelMain(Vertex2Pixel input) : SV_Target0
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
return Texture.Sample(Sampler, input.texcoord);
|
return Texture.Sample(Sampler, input.texcoord);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,62 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: (C) 2025 a dinosaur
|
|
||||||
* SPDX-License-Identifier: Zlib
|
|
||||||
*/
|
|
||||||
|
|
||||||
#version 450
|
|
||||||
|
|
||||||
#ifdef VERTEX
|
|
||||||
|
|
||||||
layout(location = 0) in vec3 i_position;
|
|
||||||
layout(location = 1) in vec2 i_texcoord;
|
|
||||||
layout(location = 2) in vec3 i_normal;
|
|
||||||
|
|
||||||
layout(location = 0) out vec2 v_texcoord;
|
|
||||||
layout(location = 1) out vec4 v_color;
|
|
||||||
|
|
||||||
layout(set = 1, binding = 0) uniform UBO
|
|
||||||
{
|
|
||||||
mat4 u_modelView;
|
|
||||||
mat4 u_projection;
|
|
||||||
};
|
|
||||||
|
|
||||||
layout(set = 1, binding = 1) uniform Light
|
|
||||||
{
|
|
||||||
vec4 u_ambient;
|
|
||||||
vec4 u_diffuse;
|
|
||||||
vec4 u_position;
|
|
||||||
};
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
const vec4 position = u_modelView * vec4(i_position, 1.0);
|
|
||||||
const vec3 normal = normalize(u_modelView * vec4(i_normal, 0.0)).xyz;
|
|
||||||
|
|
||||||
const vec3 lightVec = u_position.xyz - position.xyz;
|
|
||||||
const float lightDest2 = dot(lightVec, lightVec);
|
|
||||||
const vec3 dir = inversesqrt(lightDest2) * lightVec;
|
|
||||||
const float lambert = max(0.0, dot(normal, dir));
|
|
||||||
|
|
||||||
const vec3 ambient = 0.04 + 0.2 * u_ambient.rgb;
|
|
||||||
const vec3 diffuse = 0.8 * u_diffuse.rgb;
|
|
||||||
|
|
||||||
v_texcoord = i_texcoord;
|
|
||||||
v_color = vec4(ambient + lambert * diffuse, 1.0);
|
|
||||||
gl_Position = u_projection * position;
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
layout(location = 0) in vec2 v_texcoord;
|
|
||||||
layout(location = 1) in vec4 v_color;
|
|
||||||
|
|
||||||
layout(location = 0) out vec4 o_color;
|
|
||||||
|
|
||||||
layout(set = 2, binding = 0) uniform sampler2D u_texture;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
o_color = v_color * texture(u_texture, v_texcoord);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -53,7 +53,11 @@ Vertex2Pixel VertexMain(VertexInput input)
|
|||||||
Texture2D<half4> Texture : register(t0, space2);
|
Texture2D<half4> Texture : register(t0, space2);
|
||||||
SamplerState Sampler : register(s0, space2);
|
SamplerState Sampler : register(s0, space2);
|
||||||
|
|
||||||
|
#ifdef VULKAN
|
||||||
|
half4 FragmentMain(Vertex2Pixel input) : SV_Target0
|
||||||
|
#else
|
||||||
half4 PixelMain(Vertex2Pixel input) : SV_Target0
|
half4 PixelMain(Vertex2Pixel input) : SV_Target0
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
return input.color * Texture.Sample(Sampler, input.texcoord);
|
return input.color * Texture.Sample(Sampler, input.texcoord);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,43 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: (C) 2025 a dinosaur
|
|
||||||
* SPDX-License-Identifier: Zlib
|
|
||||||
*/
|
|
||||||
|
|
||||||
#version 450
|
|
||||||
|
|
||||||
#ifdef VERTEX
|
|
||||||
|
|
||||||
layout(location = 0) in vec3 i_position;
|
|
||||||
layout(location = 1) in vec2 i_texcoord;
|
|
||||||
|
|
||||||
layout(location = 0) out vec2 v_texcoord;
|
|
||||||
layout(location = 1) out vec4 v_color;
|
|
||||||
|
|
||||||
layout(set = 1, binding = 0) uniform UBO
|
|
||||||
{
|
|
||||||
mat4 u_viewproj;
|
|
||||||
vec4 u_color;
|
|
||||||
};
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
v_texcoord = i_texcoord;
|
|
||||||
v_color = u_color;
|
|
||||||
gl_Position = u_viewproj * vec4(i_position, 1.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
layout(location = 0) in vec2 v_texcoord;
|
|
||||||
layout(location = 1) in vec4 v_color;
|
|
||||||
|
|
||||||
layout(location = 0) out vec4 o_color;
|
|
||||||
|
|
||||||
layout(set = 2, binding = 0) uniform sampler2D u_texture;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
o_color = v_color * texture(u_texture, v_texcoord);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -34,7 +34,11 @@ Vertex2Pixel VertexMain(VertexInput input)
|
|||||||
Texture2D<half4> Texture : register(t0, space2);
|
Texture2D<half4> Texture : register(t0, space2);
|
||||||
SamplerState Sampler : register(s0, space2);
|
SamplerState Sampler : register(s0, space2);
|
||||||
|
|
||||||
|
#ifdef VULKAN
|
||||||
|
half4 FragmentMain(Vertex2Pixel input) : SV_Target0
|
||||||
|
#else
|
||||||
half4 PixelMain(Vertex2Pixel input) : SV_Target0
|
half4 PixelMain(Vertex2Pixel input) : SV_Target0
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
return input.color * Texture.Sample(Sampler, input.texcoord);
|
return input.color * Texture.Sample(Sampler, input.texcoord);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,56 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: (C) 2025 a dinosaur
|
|
||||||
* SPDX-License-Identifier: Zlib
|
|
||||||
*/
|
|
||||||
|
|
||||||
#version 450
|
|
||||||
|
|
||||||
#ifdef VERTEX
|
|
||||||
|
|
||||||
layout(location = 0) in vec3 i_position;
|
|
||||||
layout(location = 1) in vec2 i_texcoord;
|
|
||||||
|
|
||||||
layout(location = 0) out vec2 v_texcoord;
|
|
||||||
layout(location = 1) out vec4 v_color;
|
|
||||||
|
|
||||||
layout(set = 1, binding = 0) uniform UBO
|
|
||||||
{
|
|
||||||
mat4 u_projection;
|
|
||||||
vec4 u_color;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Instance
|
|
||||||
{
|
|
||||||
mat4 model;
|
|
||||||
vec4 color;
|
|
||||||
};
|
|
||||||
|
|
||||||
layout(std140, set = 0, binding = 0) readonly buffer InstanceData
|
|
||||||
{
|
|
||||||
Instance instances[];
|
|
||||||
} instanceData;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
const Instance instance = instanceData.instances[gl_InstanceIndex];
|
|
||||||
|
|
||||||
v_texcoord = i_texcoord;
|
|
||||||
v_color = instance.color;
|
|
||||||
gl_Position = u_projection * instance.model * vec4(i_position, 1.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
layout(location = 0) in vec2 v_texcoord;
|
|
||||||
layout(location = 1) in vec4 v_color;
|
|
||||||
|
|
||||||
layout(location = 0) out vec4 o_color;
|
|
||||||
|
|
||||||
layout(set = 2, binding = 0) uniform sampler2D u_texture;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
o_color = v_color * texture(u_texture, v_texcoord);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
Reference in New Issue
Block a user