mirror of
https://github.com/raysan5/raylib.git
synced 2025-12-25 10:22:33 -05:00
REVIEWED: Some PRs formating
This commit is contained in:
@ -10,12 +10,6 @@ uniform bool flipY;
|
||||
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()
|
||||
{
|
||||
// Handle potential Y-flipping
|
||||
@ -27,7 +21,7 @@ void main()
|
||||
float depth = texture2D(depthTexture, texCoord).r;
|
||||
|
||||
// Linearize depth
|
||||
float linearDepth = linearizeDepth(depth);
|
||||
float linearDepth = (2.0*nearPlane)/(farPlane + nearPlane - depth*(farPlane - nearPlane));
|
||||
|
||||
// Output final color
|
||||
gl_FragColor = vec4(vec3(linearDepth), 1.0);
|
||||
|
||||
@ -13,24 +13,17 @@ const float farPlane = 100.0;
|
||||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
// Linearizes the depth buffer value
|
||||
float linearizeDepth(float depth)
|
||||
{
|
||||
return (2.0 * nearPlane) / (farPlane + nearPlane - depth * (farPlane - nearPlane));
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
// Handle potential Y-flipping
|
||||
vec2 texCoord = fragTexCoord;
|
||||
if (flipY)
|
||||
texCoord.y = 1.0 - texCoord.y;
|
||||
if (flipY) texCoord.y = 1.0 - texCoord.y;
|
||||
|
||||
// Sample depth
|
||||
float depth = texture(depthTexture, texCoord).r;
|
||||
|
||||
// Linearize depth value
|
||||
float linearDepth = linearizeDepth(depth);
|
||||
float linearDepth = (2.0*nearPlane)/(farPlane + nearPlane - depth*(farPlane - nearPlane));
|
||||
|
||||
// Output final color
|
||||
finalColor = vec4(vec3(linearDepth), 1.0);
|
||||
|
||||
@ -34,11 +34,11 @@ int main(void)
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 600;
|
||||
const int screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [shader] example - render depth texture");
|
||||
|
||||
// Load camera
|
||||
// Init camera
|
||||
Camera camera = { 0 };
|
||||
camera.position = (Vector3){ 4.0f, 1.0f, 5.0f };
|
||||
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
|
||||
@ -56,7 +56,7 @@ int main(void)
|
||||
SetShaderValue(depthShader, flipTextureLoc, (int[]){ 1 }, SHADER_UNIFORM_INT); // Flip Y texture
|
||||
|
||||
// Load models
|
||||
Model cube = LoadModelFromMesh(GenMeshCube(1.0f, 1.0f, 1.0f));
|
||||
Model cube = LoadModelFromMesh(GenMeshCube(1.0f, 1.0f, 1.0f));
|
||||
Model floor = LoadModelFromMesh(GenMeshPlane(20.0f, 20.0f, 1, 1));
|
||||
|
||||
DisableCursor(); // Limit cursor to relative movement inside the window
|
||||
@ -75,25 +75,19 @@ int main(void)
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginTextureMode(target);
|
||||
|
||||
ClearBackground(WHITE);
|
||||
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
DrawModel(cube, (Vector3){ 0.0f, 0.0f, 0.0f }, 3.0f, YELLOW);
|
||||
DrawModel(floor, (Vector3){ 10.0f, 0.0f, 2.0f }, 2.0f, RED);
|
||||
|
||||
EndMode3D();
|
||||
|
||||
EndTextureMode();
|
||||
|
||||
BeginDrawing();
|
||||
|
||||
BeginShaderMode(depthShader);
|
||||
|
||||
SetShaderValueTexture(depthShader, depthLoc, target.depth);
|
||||
DrawTexture(target.depth, 0, 0, WHITE);
|
||||
|
||||
EndShaderMode();
|
||||
|
||||
DrawRectangle( 10, 10, 320, 93, Fade(SKYBLUE, 0.5f));
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 30 KiB |
@ -74,7 +74,6 @@ int main(void)
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw into our custom render texture (framebuffer)
|
||||
BeginTextureMode(target);
|
||||
ClearBackground(WHITE);
|
||||
@ -93,7 +92,6 @@ int main(void)
|
||||
// Draw into screen our custom render texture
|
||||
BeginDrawing();
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
DrawTextureRec(target.texture, (Rectangle) { 0, 0, (float)screenWidth, (float)-screenHeight }, (Vector2) { 0, 0 }, WHITE);
|
||||
DrawFPS(10, 10);
|
||||
EndDrawing();
|
||||
|
||||
Reference in New Issue
Block a user