diff --git a/Templates/BaseGame/game/core/rendering/shaders/gl/imposter.glsl b/Templates/BaseGame/game/core/rendering/shaders/gl/imposter.glsl index 20bc62688a..8bd32e8ab1 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/gl/imposter.glsl +++ b/Templates/BaseGame/game/core/rendering/shaders/gl/imposter.glsl @@ -22,7 +22,7 @@ #include "torque.glsl" - +#line 25 #define IMPOSTER_MAX_UVS 64 @@ -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 @@ -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. diff --git a/Templates/BaseGame/game/core/rendering/shaders/imposter.hlsl b/Templates/BaseGame/game/core/rendering/shaders/imposter.hlsl index bc700ba030..2373271aa6 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/imposter.hlsl +++ b/Templates/BaseGame/game/core/rendering/shaders/imposter.hlsl @@ -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 @@ -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;