Skip to content

Commit

Permalink
add new 'coneCapsule' to quadric shapes library
Browse files Browse the repository at this point in the history
  • Loading branch information
erichlof authored Sep 24, 2024
1 parent 7971f88 commit 549fe4d
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions shaders/Quadric_Shapes_Fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ uniform mat4 uCappedParaboloidInvMatrix;
uniform mat4 uHyperboloidInvMatrix;
uniform mat4 uHyperbolicParaboloidInvMatrix;
uniform mat4 uCapsuleInvMatrix;
uniform mat4 uConeCapsuleInvMatrix;


#define N_RECTANGLES 1
Expand All @@ -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;

Expand All @@ -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;
Expand All @@ -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 <raytracing_core_functions>
Expand Down Expand Up @@ -110,6 +114,8 @@ UnitCapsule capsules[N_CAPSULES];

#include <raytracing_unit_capsule_intersect>

#include <raytracing_unit_cone_capsule_intersect>



//---------------------------------------------------------------------------------------
Expand Down Expand Up @@ -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) );
Expand Down Expand Up @@ -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);
}


Expand Down

0 comments on commit 549fe4d

Please sign in to comment.