merge upstream master into feature branch

This commit is contained in:
Cry dsch 2021-06-01 22:10:04 +02:00
commit eface0dc00
14 changed files with 3460 additions and 2698 deletions

View file

@ -21,7 +21,7 @@
#include <stdlib.h>
#define MAX_MODELS 6
#define MAX_MODELS 7
int main(void)
{
@ -30,7 +30,7 @@ int main(void)
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [models] example - model animation");
InitWindow(screenWidth, screenHeight, "raylib [models] example - model");
// Define the camera to look into our 3d world
Camera camera = { 0 };
@ -48,6 +48,7 @@ int main(void)
model[3] = LoadModel("resources/gltf/BoxAnimated.glb");
model[4] = LoadModel("resources/gltf/AnimatedTriangle.gltf");
model[5] = LoadModel("resources/gltf/AnimatedMorphCube.glb");
model[6] = LoadModel("resources/gltf/vertex_colored_object.glb");
int currentModel = 0;

View file

@ -71,22 +71,22 @@ int main(void)
UpdateCamera(&camera); // Update camera
// Display information about closest hit
RayCollision nearestHit = { 0 };
RayCollision collision = { 0 };
char *hitObjectName = "None";
nearestHit.distance = FLT_MAX;
nearestHit.hit = false;
collision.distance = FLT_MAX;
collision.hit = false;
Color cursorColor = WHITE;
// Get ray and test against objects
ray = GetMouseRay(GetMousePosition(), camera);
// Check ray collision against ground plane
RayCollision groundHitInfo = GetRayCollisionQuad(ray, g0, g1, g2, g3);
// Check ray collision against ground quad
RayCollision collision = GetRayCollisionQuad(ray, g0, g1, g2, g3);
DrawPoint3D(g0, RED);
if ((groundHitInfo.hit) && (groundHitInfo.distance < nearestHit.distance))
if ((groundHitInfo.hit) && (groundHitInfo.distance < collision.distance))
{
nearestHit = groundHitInfo;
collision = groundHitInfo;
cursorColor = GREEN;
hitObjectName = "Ground";
}
@ -94,13 +94,13 @@ int main(void)
// Check ray collision against test triangle
RayCollision triHitInfo = GetRayCollisionTriangle(ray, ta, tb, tc);
if ((triHitInfo.hit) && (triHitInfo.distance < nearestHit.distance))
if ((triHitInfo.hit) && (triHitInfo.distance < collision.distance))
{
nearestHit = triHitInfo;
cursorColor = ORANGE;
collision = triHitInfo;
cursorColor = PURPLE;
hitObjectName = "Triangle";
bary = Vector3Barycenter(nearestHit.point, ta, tb, tc);
bary = Vector3Barycenter(collision.point, ta, tb, tc);
}
// Check ray collision against test sphere
@ -117,7 +117,7 @@ int main(void)
if ((boxHitInfo.hit) && (boxHitInfo.distance < nearestHit.distance))
{
nearestHit = boxHitInfo;
collision = boxHitInfo;
cursorColor = ORANGE;
hitObjectName = "Box";
@ -127,7 +127,7 @@ int main(void)
if (meshHitInfo.hit)
{
nearestHit = meshHitInfo;
collision = meshHitInfo;
cursorColor = ORANGE;
hitObjectName = "Mesh";
}
@ -144,7 +144,7 @@ int main(void)
// Draw the tower
// WARNING: If scale is different than 1.0f,
// not considered by GetCollisionRayModel()
// not considered by GetRayCollisionModel()
DrawModel(tower, towerPos, 1.0f, WHITE);
// Draw the test triangle
@ -159,17 +159,17 @@ int main(void)
if (boxHitInfo.hit) DrawBoundingBox(towerBBox, LIME);
// If we hit something, draw the cursor at the hit point
if (nearestHit.hit)
if (collision.hit)
{
DrawCube(nearestHit.point, 0.3f, 0.3f, 0.3f, cursorColor);
DrawCubeWires(nearestHit.point, 0.3f, 0.3f, 0.3f, RED);
DrawCube(collision.point, 0.3f, 0.3f, 0.3f, cursorColor);
DrawCubeWires(collision.point, 0.3f, 0.3f, 0.3f, RED);
Vector3 normalEnd;
normalEnd.x = nearestHit.point.x + nearestHit.normal.x;
normalEnd.y = nearestHit.point.y + nearestHit.normal.y;
normalEnd.z = nearestHit.point.z + nearestHit.normal.z;
normalEnd.x = collision.point.x + collision.normal.x;
normalEnd.y = collision.point.y + collision.normal.y;
normalEnd.z = collision.point.z + collision.normal.z;
DrawLine3D(nearestHit.point, normalEnd, RED);
DrawLine3D(collision.point, normalEnd, RED);
}
DrawRay(ray, MAROON);
@ -181,21 +181,21 @@ int main(void)
// Draw some debug GUI text
DrawText(TextFormat("Hit Object: %s", hitObjectName), 10, 50, 10, BLACK);
if (nearestHit.hit)
if (collision.hit)
{
int ypos = 70;
DrawText(TextFormat("Distance: %3.2f", nearestHit.distance), 10, ypos, 10, BLACK);
DrawText(TextFormat("Distance: %3.2f", collision.distance), 10, ypos, 10, BLACK);
DrawText(TextFormat("Hit Pos: %3.2f %3.2f %3.2f",
nearestHit.point.x,
nearestHit.point.y,
nearestHit.point.z), 10, ypos + 15, 10, BLACK);
collision.point.x,
collision.point.y,
collision.point.z), 10, ypos + 15, 10, BLACK);
DrawText(TextFormat("Hit Norm: %3.2f %3.2f %3.2f",
nearestHit.normal.x,
nearestHit.normal.y,
nearestHit.normal.z), 10, ypos + 30, 10, BLACK);
collision.normal.x,
collision.normal.y,
collision.normal.z), 10, ypos + 30, 10, BLACK);
if (triHitInfo.hit && strcmp(hitObjectName, "Triangle") == 0)
DrawText(TextFormat("Barycenter: %3.2f %3.2f %3.2f", bary.x, bary.y, bary.z), 10, ypos + 45, 10, BLACK);

View file

@ -37,7 +37,7 @@ int main(void)
Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f);
Model skybox = LoadModelFromMesh(cube);
bool useHDR = false;
bool useHDR = true;
// Load skybox shader and set required locations
// NOTE: Some locations are automatically set at shader loading
@ -55,13 +55,15 @@ int main(void)
SetShaderValue(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, SHADER_UNIFORM_INT);
char skyboxFileName[256] = { 0 };
Texture2D panorama;
if (useHDR)
{
TextCopy(skyboxFileName, "resources/dresden_square_2k.hdr");
// Load HDR panorama (sphere) texture
Texture2D panorama = panorama = LoadTexture(skyboxFileName);
panorama = LoadTexture(skyboxFileName);
// Generate cubemap (texture with 6 quads-cube-mapping) from panorama HDR texture
// NOTE 1: New texture is generated rendering to texture, shader calculates the sphere->cube coordinates mapping
@ -69,7 +71,7 @@ int main(void)
// despite texture can be successfully created.. so using PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 instead of PIXELFORMAT_UNCOMPRESSED_R32G32B32A32
skybox.materials[0].maps[MATERIAL_MAP_CUBEMAP].texture = GenTextureCubemap(shdrCubemap, panorama, 1024, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8);
UnloadTexture(panorama); // Texture not required anymore, cubemap already generated
//UnloadTexture(panorama); // Texture not required anymore, cubemap already generated
}
else
{
@ -143,11 +145,11 @@ int main(void)
DrawGrid(10, 1.0f);
EndMode3D();
//DrawTextureEx(panorama, (Vector2){ 0, 0 }, 0.0f, 0.5f, WHITE);
if (useHDR)
DrawText(TextFormat("Panorama image from hdrihaven.com: %s", GetFileName(skyboxFileName)), 10, GetScreenHeight() - 20, 10, BLACK);
else
DrawText(TextFormat(": %s", GetFileName(skyboxFileName)), 10, GetScreenHeight() - 20, 10, BLACK);
if (useHDR) DrawText(TextFormat("Panorama image from hdrihaven.com: %s", GetFileName(skyboxFileName)), 10, GetScreenHeight() - 20, 10, BLACK);
else DrawText(TextFormat(": %s", GetFileName(skyboxFileName)), 10, GetScreenHeight() - 20, 10, BLACK);
DrawFPS(10, 10);
@ -208,18 +210,32 @@ static TextureCubemap GenTextureCubemap(Shader shader, Texture2D panorama, int s
};
rlViewport(0, 0, size, size); // Set viewport to current fbo dimensions
// Activate and enable texture for drawing to cubemap faces
rlActiveTextureSlot(0);
rlEnableTexture(panorama.id);
for (int i = 0; i < 6; i++)
{
// Set the view matrix for the current cube face
rlSetUniformMatrix(shader.locs[SHADER_LOC_MATRIX_VIEW], fboViews[i]);
// Select the current cubemap face attachment for the fbo
// WARNING: This function by default enables->attach->disables fbo!!!
rlFramebufferAttach(fbo, cubemap.id, RL_ATTACHMENT_COLOR_CHANNEL0, RL_ATTACHMENT_CUBEMAP_POSITIVE_X + i, 0);
rlEnableFramebuffer(fbo);
rlSetTexture(panorama.id); // WARNING: It must be called after enabling current framebuffer if using internal batch system!
// Load and draw a cube, it uses the current enabled texture
rlClearScreenBuffers();
DrawCubeV(Vector3Zero(), Vector3One(), WHITE);
rlDrawRenderBatchActive();
rlLoadDrawCube();
// ALTERNATIVE: Try to use internal batch system to draw the cube instead of rlLoadDrawCube
// for some reason this method does not work, maybe due to cube triangles definition? normals pointing out?
// TODO: Investigate this issue...
//rlSetTexture(panorama.id); // WARNING: It must be called after enabling current framebuffer if using internal batch system!
//rlClearScreenBuffers();
//DrawCubeV(Vector3Zero(), Vector3One(), WHITE);
//rlDrawRenderBatchActive();
}
//------------------------------------------------------------------------------------------
@ -238,7 +254,7 @@ static TextureCubemap GenTextureCubemap(Shader shader, Texture2D panorama, int s
cubemap.width = size;
cubemap.height = size;
cubemap.mipmaps = 1;
cubemap.format = PIXELFORMAT_UNCOMPRESSED_R32G32B32;
cubemap.format = format;
return cubemap;
}

View file

@ -1,16 +1,5 @@
/*******************************************************************************************
*
* BRDF LUT Generation - Bidirectional reflectance distribution function fragment shader
*
* REF: https://github.com/HectorMF/BRDFGenerator
*
* Copyright (c) 2017 Victor Fisac
*
**********************************************************************************************/
#version 330
// Input vertex attributes (from vertex shader)
in vec2 fragTexCoord;
@ -86,6 +75,8 @@ float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness)
return ggx1*ggx2;
}
// Bidirectional reflectance distribution function
// Ref: https://github.com/HectorMF/BRDFGenerator
vec2 IntegrateBRDF(float NdotV, float roughness)
{
float A = 0.0;

View file

@ -1,11 +1,3 @@
/*******************************************************************************************
*
* rPBR [shader] - Bidirectional reflectance distribution function vertex shader
*
* Copyright (c) 2017 Victor Fisac
*
**********************************************************************************************/
#version 330
// Input vertex attributes

View file

@ -1,11 +1,3 @@
/*******************************************************************************************
*
* rPBR [shader] - Equirectangular to cubemap vertex shader
*
* Copyright (c) 2017 Victor Fisac
*
**********************************************************************************************/
#version 330
// Input vertex attributes

View file

@ -1,11 +1,3 @@
/*******************************************************************************************
*
* rPBR [shader] - Irradiance cubemap fragment shader
*
* Copyright (c) 2017 Victor Fisac
*
**********************************************************************************************/
#version 330
// Input vertex attributes (from vertex shader)

View file

@ -1,11 +1,3 @@
/*******************************************************************************************
*
* rPBR [shader] - Physically based rendering fragment shader
*
* Copyright (c) 2017 Victor Fisac
*
**********************************************************************************************/
#version 330
#define MAX_REFLECTION_LOD 4.0

View file

@ -1,11 +1,3 @@
/*******************************************************************************************
*
* rPBR [shader] - Physically based rendering vertex shader
*
* Copyright (c) 2017 Victor Fisac
*
**********************************************************************************************/
#version 330
// Input vertex attributes

View file

@ -1,14 +1,7 @@
/*******************************************************************************************
*
* rPBR [shader] - Prefiltered environment for reflections fragment shader
*
* Copyright (c) 2017 Victor Fisac
*
**********************************************************************************************/
#version 330
#define MAX_SAMPLES 1024u
#define CUBEMAP_RESOLUTION 1024.0
#define MAX_SAMPLES 1024u
#define CUBEMAP_RESOLUTION 1024.0
// Input vertex attributes (from vertex shader)
in vec3 fragPosition;

View file

@ -1,13 +1,3 @@
/*******************************************************************************************
*
* rPBR [shader] - Background skybox fragment shader
*
* Copyright (c) 2017 Victor Fisac
*
* 19-Jun-2020 - modified by Giuseppe Mastrangelo (@peppemas) - VFlip Support
*
**********************************************************************************************/
#version 330
// Input vertex attributes (from vertex shader)

View file

@ -1,11 +1,3 @@
/*******************************************************************************************
*
* rPBR [shader] - Background skybox vertex shader
*
* Copyright (c) 2017 Victor Fisac
*
**********************************************************************************************/
#version 330
// Input vertex attributes