Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Engine
Submodule Engine updated 37 files
+7 −0 assets/shaders/gbuffer.frag
+ − assets/shaders/gbuffer.frag.spv
+29 −0 assets/shaders/include/sleak/gbuffer.glsl
+512 −0 assets/shaders/include/sleak/lighting_default.glsl
+155 −0 assets/shaders/include/sleak/lighting_inputs.glsl
+3 −313 assets/shaders/lighting_pass.frag
+ − assets/shaders/lighting_pass.frag.spv
+7 −0 assets/shaders/lighting_pass_gl.frag
+4 −0 assets/shaders/shadow_depth_gl.frag
+46 −0 assets/shaders/shadow_depth_gl.vert
+14 −0 assets/shaders/shadow_position_gl.vert
+15 −17 docs/pages/backend_support.md
+25 −2 docs/pages/lighting.md
+13 −0 docs/pages/release_notes.md
+7 −1 docs/pages/rendering_pipeline.md
+17 −10 docs/pages/shader_authoring.md
+22 −5 docs/pages/troubleshooting.md
+55 −10 docs/pages/vertex_format.md
+2 −0 include/private/Graphics/Common/RenderCommandQueue.hpp
+5 −0 include/private/Graphics/Common/RenderContext.hpp
+19 −2 include/private/Graphics/Common/Renderer.hpp
+8 −8 include/private/Graphics/Common/ShaderIncludes.hpp
+76 −0 include/private/Graphics/OpenGL/OpenGLRenderer.hpp
+4 −0 include/private/Graphics/OpenGL/OpenGLShader.hpp
+64 −8 include/private/Graphics/Vulkan/VulkanRenderer.hpp
+8 −0 include/public/Core/Application.hpp
+44 −3 include/public/Runtime/VertexLayout.hpp
+14 −0 src/Core/Application.cpp
+18 −1 src/Graphics/Common/RenderCommandQueue.cpp
+367 −15 src/Graphics/OpenGL/OpenGLRenderer.cpp
+13 −0 src/Graphics/OpenGL/OpenGLShader.cpp
+167 −86 src/Graphics/Vulkan/VulkanDeferred.cpp
+7 −0 src/Graphics/Vulkan/VulkanDevice.cpp
+87 −26 src/Graphics/Vulkan/VulkanPipelines.cpp
+9 −4 src/Graphics/Vulkan/VulkanRenderer.cpp
+1 −1 src/Graphics/Vulkan/VulkanSSAO.cpp
+42 −7 src/Graphics/Vulkan/VulkanShadow.cpp
103 changes: 103 additions & 0 deletions Game/assets/shaders/gbuffer_voxel.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#version 450
#extension GL_GOOGLE_include_directive : require

// GBuffer pass, voxel format: engine gbuffer.frag plus RT3 (voxel model)

#include "sleak/frame.glsl"
#include "craft/shading_models.glsl"

layout(location = 0) in vec3 fragWorldPos;
layout(location = 1) in vec3 fragWorldNorm;
layout(location = 2) in vec3 fragWorldTan;
layout(location = 3) in vec3 fragWorldBit;
layout(location = 4) in vec4 fragColor;
layout(location = 5) in vec2 fragUV;

// -- Set 0: PBR material textures (bindings 0-5) --------------------
layout(set = 0, binding = 0) uniform sampler2D texDiffuse;
layout(set = 0, binding = 1) uniform sampler2D texNormal;
layout(set = 0, binding = 2) uniform sampler2D texMetallic;
layout(set = 0, binding = 3) uniform sampler2D texRoughness;
layout(set = 0, binding = 4) uniform sampler2D texAO;
layout(set = 0, binding = 5) uniform sampler2D texEmissive;

// -- Set 0: per-material scalar parameters (binding 6) --------------
layout(set = 0, binding = 6) uniform MaterialParams {
vec4 albedoFactor; // xyz = base color tint, w = opacity
float metallicFactor;
float roughnessFactor;
float aoFactor;
float normalIntensity;
vec4 emissiveFactor; // xyz = emissive color tint, w = intensity
float tilingX;
float tilingY;
float offsetX;
float offsetY;
uint hasNormalMap;
uint hasMetallicMap;
uint hasRoughnessMap;
uint hasAOMap;
uint hasEmissiveMap;
float _pad0;
float _pad1;
float _pad2;
};

layout(location = 0) out vec4 outAlbedoAO;
layout(location = 1) out vec4 outNormalRough;
layout(location = 2) out vec4 outMetalEmit;
layout(location = 3) out vec4 outMotionModel;

// Atlas texels below this alpha are cut out
const float CRAFT_ALPHA_CUTOFF = 0.5;
// Roughness floor that keeps the BRDF finite
const float CRAFT_MIN_ROUGHNESS = 0.04;

void main() {
vec2 uv = fragUV * vec2(tilingX, tilingY) + vec2(offsetX, offsetY);

// --- Base Colour / Albedo ---
vec4 albedoSample = texture(texDiffuse, uv) * albedoFactor;
if (albedoSample.a < CRAFT_ALPHA_CUTOFF) discard;

// --- Normal (TBN basis) ---
vec3 N = normalize(fragWorldNorm);
if (hasNormalMap != 0u) {
vec3 tN = texture(texNormal, uv).xyz * 2.0 - 1.0;
tN.xy *= normalIntensity;
tN.z = sqrt(max(1.0 - dot(tN.xy, tN.xy), 0.0));
vec3 T = normalize(fragWorldTan - dot(fragWorldTan, N) * N);
vec3 B = normalize(fragWorldBit - dot(fragWorldBit, N) * N -
dot(fragWorldBit, T) * T);
N = normalize(mat3(T, B, N) * tN);
}

// --- Metallic ---
float metallic = hasMetallicMap != 0u
? texture(texMetallic, uv).r * metallicFactor
: metallicFactor;
metallic = clamp(metallic, 0.0, 1.0);

// --- Roughness ---
float roughness = hasRoughnessMap != 0u
? texture(texRoughness, uv).r * roughnessFactor
: roughnessFactor;
roughness = clamp(roughness, CRAFT_MIN_ROUGHNESS, 1.0);

// --- Ambient Occlusion (vertex AO in the red channel) ---
float ao = hasAOMap != 0u
? texture(texAO, uv).r * aoFactor
: fragColor.r * aoFactor;
ao = clamp(ao, 0.0, 1.0);

// --- Emissive (HDR in RT2.gba) ---
vec3 emissive = hasEmissiveMap != 0u
? texture(texEmissive, uv).rgb * emissiveFactor.rgb * emissiveFactor.w
: emissiveFactor.rgb * emissiveFactor.w;

outAlbedoAO = SleakFrameGuard(vec4(albedoSample.rgb, ao));
outNormalRough = vec4(N * 0.5 + 0.5, roughness);
outMetalEmit = vec4(metallic, emissive);
outMotionModel = SleakEncodeMotionModel(vec2(0.0), 0.0,
CRAFT_SHADING_MODEL_VOXEL);
}
Binary file added Game/assets/shaders/gbuffer_voxel.frag.spv
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#version 450 core
#extension GL_GOOGLE_include_directive : require

// GBuffer geometry pass — outputs material properties to 3 render targets.
// RT0: AlbedoRGB + AO (RGBA8)
// RT1: WorldNormalXYZ + Rough (RGBA16F, normal packed to [0,1])
// RT2: Metallic + EmissiveScale (RGBA8)
// GBuffer pass, OpenGL, voxel format: engine gbuffer_gl.frag plus RT3

in vec3 fragWorldPos;
in vec3 fragWorldNorm;
Expand All @@ -16,6 +14,7 @@ in vec4 fragShadowCoord;
layout(location = 0) out vec4 outAlbedoAO;
layout(location = 1) out vec4 outNormalRough;
layout(location = 2) out vec4 outMetalEmit;
layout(location = 3) out vec4 outMotionModel;

// Material textures (binding must match TEXTURE_SLOT defines)
layout(binding = 0) uniform sampler2D diffuseTexture;
Expand Down Expand Up @@ -52,11 +51,15 @@ layout(std140, binding = 1) uniform MaterialUBO {
vec2 _pad1;
};

#include "sleak/frame.glsl"
#include "craft/shading_models.glsl"

void main() {
vec2 uv = fragUV * matTiling + matOffset;

// Albedo
vec4 albedo = (HasDiffuseMap != 0u) ? texture(diffuseTexture, uv) : matDiffuseColor;
vec4 albedo = (HasDiffuseMap != 0u) ? texture(diffuseTexture, uv)
: matDiffuseColor;
if (albedo.a < matAlphaCutoff) discard;

// Normal (world space)
Expand All @@ -70,13 +73,19 @@ void main() {
}

// PBR scalars
float roughness = (HasRoughnessMap != 0u) ? texture(roughnessTexture, uv).r : matRoughness;
float metallic = (HasMetallicMap != 0u) ? texture(metallicTexture, uv).r : matMetallic;
float ao = (HasAOMap != 0u) ? texture(aoTexture, uv).r : (matAO * fragColor.r);
float emitScale = (HasEmissiveMap != 0u) ? length(texture(emissiveTexture, uv).rgb) :
length(matEmissiveColor) * matEmissiveIntensity;
float roughness = (HasRoughnessMap != 0u) ? texture(roughnessTexture, uv).r
: matRoughness;
float metallic = (HasMetallicMap != 0u) ? texture(metallicTexture, uv).r
: matMetallic;
float ao = (HasAOMap != 0u) ? texture(aoTexture, uv).r
: (matAO * fragColor.r);
float emitScale = (HasEmissiveMap != 0u)
? length(texture(emissiveTexture, uv).rgb)
: length(matEmissiveColor) * matEmissiveIntensity;

outAlbedoAO = vec4(albedo.rgb, ao);
outAlbedoAO = SleakFrameGuard(vec4(albedo.rgb, ao));
outNormalRough = vec4(N * 0.5 + 0.5, roughness); // pack normal to [0,1]
outMetalEmit = vec4(metallic, clamp(emitScale, 0.0, 1.0), 0.0, 1.0);
outMotionModel = SleakEncodeMotionModel(vec2(0.0), 0.0,
CRAFT_SHADING_MODEL_VOXEL);
}
9 changes: 9 additions & 0 deletions Game/assets/shaders/include/craft/shading_models.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef CRAFT_SHADING_MODELS_GLSL
#define CRAFT_SHADING_MODELS_GLSL

#include "sleak/gbuffer.glsl"

// SleakCraft shading model ids in GBuffer RT3.w; 0 belongs to the engine
#define CRAFT_SHADING_MODEL_VOXEL 1u

#endif
Loading
Loading