Skip to content
Closed
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Thumbs.db
.vscode/
.idea/
*.code-workspace
imgui.ini

# vcpkg binary cache and top-level helper artifacts (keep vcpkg.exe if present)
.vcpkg_binary_cache
Expand Down
12 changes: 12 additions & 0 deletions Assets/icons/camera_icon.ppm
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
P3
# Genesis Editor camera icon (8x8), magenta background is transparent key
8 8
255
255 0 255 255 0 255 255 0 255 255 0 255 255 0 255 255 0 255 255 0 255 255 0 255
255 0 255 255 0 255 220 220 220 220 220 220 220 220 220 220 220 220 255 0 255 255 0 255
255 0 255 220 220 220 220 220 220 220 220 220 220 220 220 220 220 220 220 220 220 255 0 255
255 0 255 220 220 220 220 220 220 255 255 255 255 255 255 220 220 220 220 220 220 255 0 255
255 0 255 220 220 220 220 220 220 255 255 255 255 255 255 220 220 220 220 220 220 255 0 255
255 0 255 220 220 220 220 220 220 220 220 220 220 220 220 220 220 220 220 220 220 255 0 255
255 0 255 255 0 255 220 220 220 220 220 220 220 220 220 220 220 220 255 0 255 255 0 255
255 0 255 255 0 255 255 0 255 255 0 255 255 0 255 255 0 255 255 0 255 255 0 255
12 changes: 12 additions & 0 deletions Assets/icons/light_dir_icon.ppm
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
P3
# Genesis Editor directional light icon (8x8), magenta background is transparent key
8 8
255
255 0 255 255 0 255 255 0 255 220 220 220 255 0 255 255 0 255 255 0 255 255 0 255
255 0 255 255 0 255 220 220 220 255 255 255 220 220 220 255 0 255 255 0 255 255 0 255
255 0 255 220 220 220 255 255 255 255 255 255 255 255 255 220 220 220 255 0 255 255 0 255
220 220 220 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 220 220 220 255 0 255
255 0 255 220 220 220 255 255 255 255 255 255 255 255 255 220 220 220 255 0 255 255 0 255
255 0 255 255 0 255 220 220 220 255 255 255 220 220 220 255 0 255 255 0 255 255 0 255
255 0 255 255 0 255 255 0 255 220 220 220 255 0 255 255 0 255 255 0 255 255 0 255
255 0 255 255 0 255 255 0 255 255 0 255 255 0 255 255 0 255 255 0 255 255 0 255
12 changes: 12 additions & 0 deletions Assets/icons/light_point_icon.ppm
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
P3
# Genesis Editor point light icon (8x8), magenta background is transparent key
8 8
255
255 0 255 255 0 255 255 0 255 220 220 220 255 0 255 255 0 255 255 0 255 255 0 255
255 0 255 255 0 255 220 220 220 220 220 220 220 220 220 255 0 255 255 0 255 255 0 255
255 0 255 220 220 220 220 220 220 255 255 255 220 220 220 220 220 220 255 0 255 255 0 255
220 220 220 220 220 220 255 255 255 255 255 255 255 255 255 220 220 220 220 220 220 255 0 255
255 0 255 220 220 220 220 220 220 255 255 255 220 220 220 220 220 220 255 0 255 255 0 255
255 0 255 255 0 255 220 220 220 220 220 220 220 220 220 255 0 255 255 0 255 255 0 255
255 0 255 255 0 255 255 0 255 220 220 220 255 0 255 255 0 255 255 0 255 255 0 255
255 0 255 255 0 255 255 0 255 255 0 255 255 0 255 255 0 255 255 0 255 255 0 255
6 changes: 6 additions & 0 deletions Assets/models/triangle.obj.meta
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Genesis Asset Meta
guid=947aba47-02b1-4204-4105-e2f708a9f18b
importer=model
source_timestamp=1766818049
setting=flip_uvs|0
setting=gen_normals|1
21 changes: 17 additions & 4 deletions Assets/shaders/deferred_lighting.frag
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ uniform sampler2D gPosition;
uniform sampler2D gNormal;
uniform sampler2D gAlbedoSpec;
uniform sampler2D shadowMap;
uniform vec2 uShadowMapTexelSize;

uniform vec3 uLightDir;
uniform vec3 uLightColor;
uniform float uLightIntensity;
uniform vec3 viewPos;
uniform mat4 lightSpaceMatrix;
uniform float uBloomThreshold;
uniform float uShadowPcfRadius;

struct PointLight {
vec3 position;
Expand Down Expand Up @@ -72,11 +75,21 @@ float ShadowCalculation(vec4 fragPosLightSpace, vec3 normal, vec3 lightDir)
{
vec3 projCoords = fragPosLightSpace.xyz / fragPosLightSpace.w;
projCoords = projCoords * 0.5 + 0.5;
if(projCoords.z > 1.0) return 0.0;
float closestDepth = texture(shadowMap, projCoords.xy).r;
if (projCoords.z > 1.0) return 0.0;

float currentDepth = projCoords.z;
float bias = max(0.05 * (1.0 - dot(normal, lightDir)), 0.005);
float shadow = currentDepth - bias > closestDepth ? 1.0 : 0.0;
float radius = max(uShadowPcfRadius, 0.5);
vec2 texelSize = max(uShadowMapTexelSize, vec2(1.0 / 2048.0)) * radius;

float shadow = 0.0;
for (int x = -1; x <= 1; ++x) {
for (int y = -1; y <= 1; ++y) {
float pcfDepth = texture(shadowMap, projCoords.xy + vec2(x, y) * texelSize).r;
shadow += (currentDepth - bias > pcfDepth) ? 1.0 : 0.0;
}
}
shadow /= 9.0;
return shadow;
}

Expand Down Expand Up @@ -169,7 +182,7 @@ void main()

// Check for brightness for bloom
float brightness = dot(FragColor.rgb, vec3(0.2126, 0.7152, 0.0722));
if(brightness > 1.0)
if(brightness > uBloomThreshold)
BrightColor = vec4(FragColor.rgb, 1.0);
else
BrightColor = vec4(0.0, 0.0, 0.0, 1.0);
Expand Down
29 changes: 20 additions & 9 deletions Assets/shaders/pbr.frag
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,32 @@ uniform int uHasBaseColorTexture = 0;
uniform vec3 uLightDir = vec3(0.5, 0.5, 0.8);
uniform vec3 uLightColor = vec3(1.0, 1.0, 1.0);
uniform float uLightIntensity = 1.0;
uniform float uBloomThreshold;
uniform float uShadowPcfRadius;

uniform sampler2D shadowMap;
uniform vec2 uShadowMapTexelSize;

float ShadowCalculation(vec4 fragPosLightSpace)
float ShadowCalculation(vec4 fragPosLightSpace, vec3 normal, vec3 lightDir)
{
vec3 projCoords = fragPosLightSpace.xyz / fragPosLightSpace.w;
projCoords = projCoords * 0.5 + 0.5;
float closestDepth = texture(shadowMap, projCoords.xy).r;
if (projCoords.z > 1.0)
return 0.0;

float currentDepth = projCoords.z;
float bias = 0.005;
float shadow = currentDepth - bias > closestDepth ? 1.0 : 0.0;
float bias = max(0.05 * (1.0 - dot(normal, lightDir)), 0.005);
float radius = max(uShadowPcfRadius, 0.5);
vec2 texelSize = max(uShadowMapTexelSize, vec2(1.0 / 2048.0)) * radius;

if(projCoords.z > 1.0)
shadow = 0.0;

float shadow = 0.0;
for (int x = -1; x <= 1; ++x) {
for (int y = -1; y <= 1; ++y) {
float pcfDepth = texture(shadowMap, projCoords.xy + vec2(x, y) * texelSize).r;
shadow += (currentDepth - bias > pcfDepth) ? 1.0 : 0.0;
}
}
shadow /= 9.0;
return shadow;
}

Expand All @@ -44,7 +55,7 @@ void main() {
baseColor *= texture(uBaseColorTexture, vUV);
}

float shadow = ShadowCalculation(vFragPosLightSpace);
float shadow = ShadowCalculation(vFragPosLightSpace, n, lightDir);

vec3 diffuse = baseColor.rgb * NdotL * uLightColor * uLightIntensity;
vec3 viewDir = normalize(vec3(0.0,0.0,1.0)); // TODO: Pass camera pos
Expand All @@ -59,7 +70,7 @@ void main() {

// Check whether fragment output is higher than threshold, if so output as brightness color
float brightness = dot(FragColor.rgb, vec3(0.2126, 0.7152, 0.0722));
if(brightness > 1.0)
if(brightness > uBloomThreshold)
BrightColor = vec4(FragColor.rgb, 1.0);
else
BrightColor = vec4(0.0, 0.0, 0.0, 1.0);
Expand Down
46 changes: 46 additions & 0 deletions Assets/shaders/postprocess.frag
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,36 @@ uniform sampler2D uBloomBlur;
uniform float uExposure;
uniform float uGamma;
uniform bool uBloom;
uniform bool uVignetteEnabled;
uniform float uVignetteIntensity;
uniform float uVignetteRadius;
uniform float uVignetteSoftness;
uniform sampler2D uLUT;
uniform bool uLUTEnabled;
uniform float uLUTIntensity;
uniform float uLUTSize;

vec3 ApplyLUT(vec3 color)
{
float size = max(uLUTSize, 2.0);
vec3 c = clamp(color, 0.0, 1.0);

float slice = c.b * (size - 1.0);
float slice0 = floor(slice);
float slice1 = min(slice0 + 1.0, size - 1.0);
float lerpFactor = slice - slice0;

float texelSize = 1.0 / (size * size);
float texelSizeY = 1.0 / size;

float x0 = (slice0 * size + c.r * (size - 1.0)) * texelSize + texelSize * 0.5;
float x1 = (slice1 * size + c.r * (size - 1.0)) * texelSize + texelSize * 0.5;
float y = (c.g * (size - 1.0)) * texelSizeY + texelSizeY * 0.5;

vec3 c0 = texture(uLUT, vec2(x0, y)).rgb;
vec3 c1 = texture(uLUT, vec2(x1, y)).rgb;
return mix(c0, c1, lerpFactor);
}

void main()
{
Expand All @@ -20,6 +50,22 @@ void main()

// Gamma correction
result = pow(result, vec3(1.0 / uGamma));

// Vignette
if (uVignetteEnabled) {
float dist = distance(TexCoords, vec2(0.5));
float edge0 = max(uVignetteRadius - uVignetteSoftness, 0.0);
float edge1 = max(uVignetteRadius, edge0 + 0.0001);
float vignette = 1.0 - smoothstep(edge0, edge1, dist);
float mixAmt = clamp(uVignetteIntensity, 0.0, 1.0);
result *= mix(1.0, vignette, mixAmt);
}

// LUT
if (uLUTEnabled) {
vec3 lutColor = ApplyLUT(result);
result = mix(result, lutColor, clamp(uLUTIntensity, 0.0, 1.0));
}

FragColor = vec4(result, 1.0);
}
Loading
Loading