Merge branch 'raysan5:master' into master

This commit is contained in:
Jon Daniel 2025-04-10 23:20:24 +02:00 • committed by GitHub
commit 89554a1b11
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 784 additions and 30 deletions

View file

@ -1,26 +1,34 @@
#version 100
precision mediump float;
// Input vertex attributes (from vertex shader)
varying vec2 fragTexCoord;
varying vec4 fragColor;
// Input uniform values
uniform sampler2D texture0; // Depth texture
uniform vec4 colDiffuse;
uniform sampler2D depthTexture;
uniform bool flipY;
// NOTE: Add your custom variables here
float nearPlane = 0.1;
float farPlane = 100.0;
// Function to linearize depth from non-linear depth buffer
float linearizeDepth(float depth)
{
return (2.0 * nearPlane) / (farPlane + nearPlane - depth * (farPlane - nearPlane));
}
void main()
{
float zNear = 0.01; // camera z near
float zFar = 10.0; // camera z far
float z = texture2D(texture0, fragTexCoord).x;
// Handle potential Y-flipping
vec2 texCoord = fragTexCoord;
if (flipY)
texCoord.y = 1.0 - texCoord.y;
// Linearize depth value
float depth = (2.0*zNear)/(zFar + zNear - z*(zFar - zNear));
// Sample depth texture
float depth = texture2D(depthTexture, texCoord).r;
// Calculate final fragment color
gl_FragColor = vec4(depth, depth, depth, 1.0);
// Linearize depth
float linearDepth = linearizeDepth(depth);
// Output final color
gl_FragColor = vec4(vec3(linearDepth), 1.0);
}

View file

@ -2,26 +2,36 @@
// Input vertex attributes (from vertex shader)
in vec2 fragTexCoord;
in vec4 fragColor;
// Input uniform values
uniform sampler2D texture0; // Depth texture
uniform vec4 colDiffuse;
uniform sampler2D depthTexture;
uniform bool flipY;
const float nearPlane = 0.1;
const float farPlane = 100.0;
// Output fragment color
out vec4 finalColor;
// NOTE: Add your custom variables here
// Linearizes the depth buffer value
float linearizeDepth(float depth)
{
return (2.0 * nearPlane) / (farPlane + nearPlane - depth * (farPlane - nearPlane));
}
void main()
{
float zNear = 0.01; // camera z near
float zFar = 10.0; // camera z far
float z = texture(texture0, fragTexCoord).x;
// Handle potential Y-flipping
vec2 texCoord = fragTexCoord;
if (flipY)
texCoord.y = 1.0 - texCoord.y;
// Sample depth
float depth = texture(depthTexture, texCoord).r;
// Linearize depth value
float depth = (2.0*zNear)/(zFar + zNear - z*(zFar - zNear));
float linearDepth = linearizeDepth(depth);
// Calculate final fragment color
finalColor = vec4(depth, depth, depth, 1.0);
// Output final color
finalColor = vec4(vec3(linearDepth), 1.0);
}