Skip to content

Commit

Permalink
Merge pull request #1306 from Azaezel/alpha41/sus
Browse files Browse the repository at this point in the history
fix misbehaving imposter display
  • Loading branch information
Azaezel authored Aug 28, 2024
2 parents 77a4486 + 39300b1 commit 6fcfff4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
27 changes: 14 additions & 13 deletions Templates/BaseGame/game/core/rendering/shaders/gl/imposter.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include "torque.glsl"


#line 25
#define IMPOSTER_MAX_UVS 64


Expand Down Expand Up @@ -94,24 +94,22 @@ void imposter_v(

// First check to see if we need to render the top billboard.
int index;
/*
if ( includePoles && ( lookPitch < polarAngle || lookPitch > sPi - polarAngle ) )
if ( includePoles && ( lookPitch < polarHalfStep || lookPitch > M_PI_F - polarHalfStep ) )
{
index = numEquatorSteps * 3;
index = numEquatorSteps * numPolarSteps;

// When we render the top/bottom billboard we always use
// a fixed vector that matches the rotation of the object.
rightVec = vec3( 1, 0, 0 ) * sCornerRight[corner];
upVec = vec3( 0, 1, 0 ) * sCornerUp[corner];
upVec = vec3( 0, -1, 0 ) * sCornerUp[corner];

if ( lookPitch > sPi - polarAngle )
if ( lookPitch < polarHalfStep )
{
upVec = -upVec;
index++;
}
}
else
*/
{
// Calculate the rotation around the z axis then add the
// equator half step. This gets the images to switch a
Expand All @@ -126,20 +124,23 @@ void imposter_v(

// TODO: How can we do this without conditionals?
// Normalize the result to 0 to 2PI.
if ( rotZ < 0.0 )
if ( rotZ < 0 )
rotZ += M_2PI_F;
if ( rotZ > M_2PI_F )
else if ( rotZ > M_2PI_F )
rotZ -= M_2PI_F;
if ( rotY < 0.0 )

if ( rotY < 0 )
rotY += M_2PI_F;
if ( rotY > M_PI_F ) // Not M_2PI_F?
else if ( rotY > M_2PI_F )
rotY -= M_2PI_F;

float polarIdx = round( abs( rotY ) / polarStepSize );
int polarIdx = int(max(min(round( rotY / polarStepSize ), numPolarSteps-2),0));

// Get the index to the start of the right polar
// images for this viewing angle.
int numPolarOffset = int( float( numEquatorSteps ) * polarIdx );
int numPolarOffset = numEquatorSteps * polarIdx;
if (includePoles)
numPolarOffset = (numEquatorSteps+2) * polarIdx;

// Calculate the final image index for lookup
// of the texture coords.
Expand Down
21 changes: 11 additions & 10 deletions Templates/BaseGame/game/core/rendering/shaders/imposter.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,22 @@ void imposter_v(

// First check to see if we need to render the top billboard.
int index;
/*
if ( includePoles && ( lookPitch < polarAngle || lookPitch > sPi - polarAngle ) )
if ( includePoles && ( lookPitch < polarHalfStep || lookPitch > (M_PI_F - polarHalfStep) ) )
{
index = numEquatorSteps * 3;
index = numEquatorSteps * numPolarSteps;

// When we render the top/bottom billboard we always use
// a fixed vector that matches the rotation of the object.
rightVec = float3( 1, 0, 0 ) * sCornerRight[corner];
upVec = float3( 0, 1, 0 ) * sCornerUp[corner];
upVec = float3( 0, -1, 0 ) * sCornerUp[corner];

if ( lookPitch > sPi - polarAngle )
if ( lookPitch < polarHalfStep )
{
upVec = -upVec;
index++;
}
}
else
*/
{
// Calculate the rotation around the z axis then add the
// equator half step. This gets the images to switch a
Expand All @@ -116,19 +114,22 @@ void imposter_v(
// Normalize the result to 0 to 2PI.
if ( rotZ < 0 )
rotZ += M_2PI_F;
if ( rotZ > M_2PI_F )
else if ( rotZ > M_2PI_F )
rotZ -= M_2PI_F;

if ( rotY < 0 )
rotY += M_2PI_F;
if ( rotY > M_PI_F ) // Not M_2PI_F?
else if ( rotY > M_2PI_F )
rotY -= M_2PI_F;

float polarIdx = round( abs( rotY ) / polarStepSize );
int polarIdx = max(min(round( rotY / polarStepSize ), numPolarSteps-2),0);

// Get the index to the start of the right polar
// images for this viewing angle.
int numPolarOffset = numEquatorSteps * polarIdx;

if (includePoles)
numPolarOffset = (numEquatorSteps+2) * polarIdx;

// Calculate the final image index for lookup
// of the texture coords.
index = ( rotZ / equatorStepSize ) + numPolarOffset;
Expand Down

0 comments on commit 6fcfff4

Please sign in to comment.