Merge branch 'master' into master
This commit is contained in:
commit
0842aabe5c
1 changed files with 2557 additions and 769 deletions
|
|
@ -1,6 +1,6 @@
|
|||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [shaders] example - Hybrid Rendering
|
||||
* raylib [shaders] example - hybrid rendering
|
||||
*
|
||||
* Example complexity rating: [★★★★] 4/4
|
||||
*
|
||||
|
|
@ -62,14 +62,20 @@ int main(void)
|
|||
// You are required to write depth for all shaders if one shader does it
|
||||
Shader shdrRaster = LoadShader(0, TextFormat("resources/shaders/glsl%i/hybrid_raster.fs", GLSL_VERSION));
|
||||
|
||||
// Declare Struct used to store camera locs.
|
||||
// Declare Struct used to store camera locs
|
||||
RayLocs marchLocs = {0};
|
||||
|
||||
// Fill the struct with shader locs.
|
||||
// Fill the struct with shader locs
|
||||
marchLocs.camPos = GetShaderLocation(shdrRaymarch, "camPos");
|
||||
marchLocs.camDir = GetShaderLocation(shdrRaymarch, "camDir");
|
||||
marchLocs.screenCenter = GetShaderLocation(shdrRaymarch, "screenCenter");
|
||||
|
||||
// Transfer screenCenter position to shader. Which is used to calculate ray direction
|
||||
Vector2 screenCenter = {.x = screenWidth/2.0f, .y = screenHeight/2.0f};
|
||||
SetShaderValue(shdrRaymarch, marchLocs.screenCenter , &screenCenter , SHADER_UNIFORM_VEC2);
|
||||
|
||||
// Use Customized function to create writable depth texture buffer
|
||||
RenderTexture2D target = LoadRenderTextureDepthTex(screenWidth, screenHeight);
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera camera = {
|
||||
|
|
@ -79,11 +85,10 @@ int main(void)
|
|||
.fovy = 45.0f, // Camera field-of-view Y
|
||||
.projection = CAMERA_PERSPECTIVE // Camera projection type
|
||||
};
|
||||
|
||||
// Camera FOV is pre-calculated in the camera Distance.
|
||||
|
||||
// Camera FOV is pre-calculated in the camera distance
|
||||
float camDist = 1.0f/(tanf(camera.fovy*0.5f*DEG2RAD));
|
||||
RenderTexture2D target = LoadRenderTextureDepthTex(screenWidth, screenHeight);
|
||||
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
|
@ -106,14 +111,14 @@ int main(void)
|
|||
SetShaderValue(shdrRaymarch, marchLocs.screenCenter , &screenCenter , SHADER_UNIFORM_VEC2);
|
||||
UpdateCamera(&camera, CAMERA_ORBITAL);
|
||||
|
||||
// Update Camera Postion in the ray march shader.
|
||||
// Update Camera Postion in the ray march shader
|
||||
SetShaderValue(shdrRaymarch, marchLocs.camPos, &(camera.position), RL_SHADER_UNIFORM_VEC3);
|
||||
|
||||
// Update Camera Looking Vector. Vector length determines FOV.
|
||||
|
||||
// Update Camera Looking Vector. Vector length determines FOV
|
||||
Vector3 camDir = Vector3Scale( Vector3Normalize( Vector3Subtract(camera.target, camera.position)) , camDist);
|
||||
SetShaderValue(shdrRaymarch, marchLocs.camDir, &(camDir), RL_SHADER_UNIFORM_VEC3);
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
// Draw into our custom render texture (framebuffer)
|
||||
|
|
@ -121,11 +126,11 @@ int main(void)
|
|||
ClearBackground(WHITE);
|
||||
|
||||
// Raymarch Scene
|
||||
rlEnableDepthTest(); //Manually enable Depth Test to handle multiple rendering methods.
|
||||
rlEnableDepthTest(); // Manually enable Depth Test to handle multiple rendering methods
|
||||
BeginShaderMode(shdrRaymarch);
|
||||
DrawRectangleRec((Rectangle){0,0, (float)screenWidth, (float)screenHeight},WHITE);
|
||||
EndShaderMode();
|
||||
|
||||
|
||||
// Rasterize Scene
|
||||
BeginMode3D(camera);
|
||||
BeginShaderMode(shdrRaster);
|
||||
|
|
@ -138,7 +143,7 @@ int main(void)
|
|||
EndMode3D();
|
||||
EndTextureMode();
|
||||
|
||||
// Draw into screen our custom render texture
|
||||
// Draw into screen our custom render texture
|
||||
BeginDrawing();
|
||||
ClearBackground(RAYWHITE);
|
||||
DrawTextureRec(target.texture, (Rectangle) { 0, 0, (float)screenWidth, (float)-screenHeight }, (Vector2) { 0, 0 }, WHITE);
|
||||
|
|
|
|||
Loading…
Reference in a new issue