Skip to content

Commit

Permalink
Trivialy expand the vtx shader exploder conditional block
Browse files Browse the repository at this point in the history
  • Loading branch information
GertyP committed Dec 7, 2023
1 parent 13eb60d commit 2f1b56a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 27 deletions.
27 changes: 14 additions & 13 deletions renderdoc/data/glsl/mesh.vert
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,23 @@
// reflected in the other.
void vtxExploder(in int vtxID, inout vec3 pos, inout vec3 secondary)
{
float nonLinearVtxExplodeScale = 4.0f * Mesh.exploderScale * Mesh.vtxExploderSNorm *
Mesh.vtxExploderSNorm * Mesh.vtxExploderSNorm;
if(Mesh.exploderScale > 0.0f)
{
float nonLinearVtxExplodeScale = 4.0f * Mesh.exploderScale * Mesh.vtxExploderSNorm *
Mesh.vtxExploderSNorm * Mesh.vtxExploderSNorm;

// A vertex might be coincident with our 'exploderCentre' so that, when normalized,
// can give us INFs/NaNs that, even if multiplied by a zero 'exploderScale', can
// leave us with bad numbers (as seems to be the case with glsl/vulkan, but not hlsl).
// Still, we should make this case safe for when we have a non-zero 'exploderScale' -
vec3 offset = pos - Mesh.exploderCentre;
float offsetDistSquared = dot(offset, offset);
vec3 safeExplodeDir = offset * inversesqrt(max(offsetDistSquared, FLT_EPSILON));
// A vertex might be coincident with our 'exploderCentre' so that, when normalized,
// can give us INFs/NaNs that, even if multiplied by a zero 'exploderScale', can
// leave us with bad numbers (as seems to be the case with glsl/vulkan, but not hlsl).
// Still, we should make this case safe for when we have a non-zero 'exploderScale' -
vec3 offset = pos - Mesh.exploderCentre;
float offsetDistSquared = dot(offset, offset);
vec3 safeExplodeDir = offset * inversesqrt(max(offsetDistSquared, FLT_EPSILON));

float displacement = nonLinearVtxExplodeScale * ((float((vtxID >> 1) & 0xf) / 15.0f) * 1.5f - 0.5f);
pos += (safeExplodeDir * displacement);
float displacement =
nonLinearVtxExplodeScale * ((float((vtxID >> 1) & 0xf) / 15.0f) * 1.5f - 0.5f);
pos += (safeExplodeDir * displacement);

if(Mesh.exploderScale > 0.0f)
{
// For the exploder visualisation, colour verts based on vertex ID, which we
// store in secondary.
//
Expand Down
28 changes: 14 additions & 14 deletions renderdoc/data/hlsl/mesh.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,23 @@ struct meshA2V
// reflected in the other.
void vtxExploder(in uint vtxID, inout float3 pos, inout float3 secondary)
{
float nonLinearVtxExplodeScale =
4.0f * exploderScale * vtxExploderSNorm * vtxExploderSNorm * vtxExploderSNorm;
if(exploderScale > 0.0f)
{
float nonLinearVtxExplodeScale =
4.0f * exploderScale * vtxExploderSNorm * vtxExploderSNorm * vtxExploderSNorm;

// A vertex might be coincident with our 'exploderCentre' so that, when normalized,
// can give us INFs/NaNs that, even if multiplied by a zero 'exploderScale', can
// leave us with bad numbers (as seems to be the case with glsl/vulkan, but not hlsl).
// Still, we should make this case safe for when we have a non-zero 'exploderScale' -
float3 offset = pos - exploderCentre;
float offsetDistSquared = dot(offset, offset);
float3 safeExplodeDir = offset * rsqrt(max(offsetDistSquared, FLT_EPSILON));
// A vertex might be coincident with our 'exploderCentre' so that, when normalized,
// can give us INFs/NaNs that, even if multiplied by a zero 'exploderScale', can
// leave us with bad numbers (as seems to be the case with glsl/vulkan, but not hlsl).
// Still, we should make this case safe for when we have a non-zero 'exploderScale' -
float3 offset = pos - exploderCentre;
float offsetDistSquared = dot(offset, offset);
float3 safeExplodeDir = offset * rsqrt(max(offsetDistSquared, FLT_EPSILON));

float displacement =
nonLinearVtxExplodeScale * ((float((vtxID >> 1u) & 0xfu) / 15.0f) * 1.5f - 0.5f);
pos += (safeExplodeDir * displacement);
float displacement =
nonLinearVtxExplodeScale * ((float((vtxID >> 1u) & 0xfu) / 15.0f) * 1.5f - 0.5f);
pos += (safeExplodeDir * displacement);

if(exploderScale > 0.0f)
{
// For the exploder visualisation, colour verts based on vertex ID, which we
// store in secondary.
//
Expand Down

0 comments on commit 2f1b56a

Please sign in to comment.