From 549fe4d35eedecfd9f754c2213e82311adc4ec28 Mon Sep 17 00:00:00 2001 From: Erich Loftis Date: Tue, 24 Sep 2024 11:05:25 -0500 Subject: [PATCH] add new 'coneCapsule' to quadric shapes library --- shaders/Quadric_Shapes_Fragment.glsl | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/shaders/Quadric_Shapes_Fragment.glsl b/shaders/Quadric_Shapes_Fragment.glsl index 56a5c9b..75814a7 100644 --- a/shaders/Quadric_Shapes_Fragment.glsl +++ b/shaders/Quadric_Shapes_Fragment.glsl @@ -22,6 +22,7 @@ uniform mat4 uCappedParaboloidInvMatrix; uniform mat4 uHyperboloidInvMatrix; uniform mat4 uHyperbolicParaboloidInvMatrix; uniform mat4 uCapsuleInvMatrix; +uniform mat4 uConeCapsuleInvMatrix; #define N_RECTANGLES 1 @@ -38,6 +39,7 @@ uniform mat4 uCapsuleInvMatrix; #define N_HYPERBOLOIDS 1 #define N_HYPERBOLIC_PARABOLOIDS 1 #define N_CAPSULES 1 +#define N_CONE_CAPSULES 1 vec3 rayOrigin, rayDirection; @@ -56,6 +58,7 @@ struct UnitCappedParaboloid { vec2 uvScale; Material material; }; struct UnitHyperboloid { vec2 uvScale; Material material; }; struct UnitHyperbolicParaboloid { vec2 uvScale; Material material; }; struct UnitCapsule { vec2 uvScale; Material material; }; +struct UnitConeCapsule { vec2 uvScale; Material material; }; // recorded intersection data: vec3 intersectionNormal; @@ -78,6 +81,7 @@ UnitCappedParaboloid cappedParaboloids[N_CAPPED_PARABOLOIDS]; UnitHyperboloid hyperboloids[N_HYPERBOLOIDS]; UnitHyperbolicParaboloid hyperbolicParaboloids[N_HYPERBOLIC_PARABOLOIDS]; UnitCapsule capsules[N_CAPSULES]; +UnitConeCapsule coneCapsules[N_CONE_CAPSULES]; #include @@ -110,6 +114,8 @@ UnitCapsule capsules[N_CAPSULES]; #include +#include + //--------------------------------------------------------------------------------------- @@ -369,6 +375,20 @@ float SceneIntersect( int isShadowRay, int sceneUsesDirectionalLight ) intersectionShapeIsClosed = TRUE; } + // transform ray into Unit coneCapsule's object space + rObjOrigin = vec3( uConeCapsuleInvMatrix * vec4(rayOrigin, 1.0) ); + rObjDirection = vec3( uConeCapsuleInvMatrix * vec4(rayDirection, 0.0) ); + d = UnitConeCapsuleIntersect(0.4, rObjOrigin, rObjDirection, normal); + if (d < t) + { + t = d; + intersectionPoint = rObjOrigin + (t * rObjDirection); + intersectionNormal = transpose(mat3(uConeCapsuleInvMatrix)) * normal; + intersectionMaterial = coneCapsules[0].material; + intersectionUV = calcUnitCylinderUV(intersectionPoint) * coneCapsules[0].uvScale; + intersectionShapeIsClosed = TRUE; + } + // transform ray into Unit Box's object space rObjOrigin = vec3( uBoxInvMatrix * vec4(rayOrigin, 1.0) ); @@ -816,6 +836,7 @@ void SetupScene(void) hyperboloids[0] = UnitHyperboloid(vec2(8, 6), whiteRedCheckerMaterial); hyperbolicParaboloids[0] = UnitHyperbolicParaboloid(vec2(4, 4), whiteRedCheckerMaterial); capsules[0] = UnitCapsule(vec2(8, 3), whiteRedCheckerMaterial); + coneCapsules[0] = UnitConeCapsule(vec2(8, 3), whiteRedCheckerMaterial); }