Skip to content
Permalink
Browse files

glsl/parallax: define parallaxDepth/Offset in reliefMapping_fp instead

simplifies the code, only requires ifdef at one place
  • Loading branch information...
illwieckz committed Mar 30, 2019
1 parent de985ba commit 0beb003dde537acf8817cf29a893adb4816fc10a
@@ -77,9 +77,6 @@ uniform float u_ShadowBlur;

uniform mat4 u_ViewMatrix;

uniform float u_ParallaxDepthScale;
uniform float u_ParallaxOffsetBias;

IN(smooth) vec3 var_Position;
IN(smooth) vec2 var_TexDiffuse;
IN(smooth) vec2 var_TexNormal;
@@ -956,7 +953,7 @@ void main()

#if defined(USE_PARALLAX_MAPPING)
// compute texcoords offset from heightmap
vec2 texOffset = ParallaxTexOffset(texNormal, u_ParallaxDepthScale, u_ParallaxOffsetBias, viewDir, tangentToWorldMatrix);
vec2 texOffset = ParallaxTexOffset(texNormal, viewDir, tangentToWorldMatrix);

texDiffuse += texOffset;
texNormal += texOffset;
@@ -28,8 +28,6 @@ uniform sampler2D u_LightMap;
uniform sampler2D u_DeluxeMap;
uniform float u_AlphaThreshold;
uniform vec3 u_ViewOrigin;
uniform float u_ParallaxDepthScale;
uniform float u_ParallaxOffsetBias;

IN(smooth) vec3 var_Position;
IN(smooth) vec2 var_TexDiffuse;
@@ -60,7 +58,7 @@ void main()

#if defined(USE_PARALLAX_MAPPING)
// compute texcoords offset from heightmap
vec2 texOffset = ParallaxTexOffset(texNormal, u_ParallaxDepthScale, u_ParallaxOffsetBias, viewDir, tangentToWorldMatrix);
vec2 texOffset = ParallaxTexOffset(texNormal, viewDir, tangentToWorldMatrix);

texDiffuse += texOffset;
texGlow += texOffset;
@@ -32,8 +32,6 @@ uniform float u_RefractionIndex;
uniform float u_FresnelPower;
uniform float u_FresnelScale;
uniform float u_FresnelBias;
uniform float u_ParallaxDepthScale;
uniform float u_ParallaxOffsetBias;
uniform float u_NormalScale;
uniform mat4 u_ModelMatrix;
uniform mat4 u_UnprojectMatrix;
@@ -98,7 +96,7 @@ void main()
// ray intersect in view direction

// compute texcoords offset from heightmap
vec2 texOffset = ParallaxTexOffset(texNormal, u_ParallaxDepthScale, u_ParallaxOffsetBias, viewDir, tangentToWorldMatrix);
vec2 texOffset = ParallaxTexOffset(texNormal, viewDir, tangentToWorldMatrix);

texScreen += texOffset;
texNormal += texOffset;
@@ -25,8 +25,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
uniform samplerCube u_ColorMap;
uniform vec3 u_ViewOrigin;
uniform mat4 u_ModelMatrix;
uniform float u_ParallaxDepthScale;
uniform float u_ParallaxOffsetBias;

IN(smooth) vec3 var_Position;
IN(smooth) vec2 var_TexNormal;
@@ -47,7 +45,7 @@ void main()

#if defined(USE_PARALLAX_MAPPING)
// compute texcoords offset from heightmap
vec2 texOffset = ParallaxTexOffset(texNormal, u_ParallaxDepthScale, u_ParallaxOffsetBias, viewDir, tangentToWorldMatrix);
vec2 texOffset = ParallaxTexOffset(texNormal, viewDir, tangentToWorldMatrix);

texNormal += texOffset;
#endif // USE_PARALLAX_MAPPING
@@ -26,6 +26,11 @@ uniform sampler2D u_NormalMap;
uniform int u_HeightMapInNormalMap;
#endif // r_normalMapping || USE_PARALLAX_MAPPING

#if defined(USE_PARALLAX_MAPPING)
uniform float u_ParallaxDepthScale;
uniform float u_ParallaxOffsetBias;
#endif // USE_PARALLAX_MAPPING

#if defined(r_normalMapping)
uniform vec3 u_NormalFormat;

@@ -107,18 +112,18 @@ vec3 NormalInWorldSpace(vec2 texNormal, mat3 tangentToWorldMatrix)
// most of the code doing somewhat the same is likely to be named
// RayIntersectDisplaceMap in other id tech3-based engines
// so please keep the comment above to enable cross-tree look-up
vec2 ParallaxTexOffset(vec2 rayStartTexCoords, float parallaxDepthScale, float parallaxOffsetBias, vec3 viewDir, mat3 tangentToWorldMatrix)
vec2 ParallaxTexOffset(vec2 rayStartTexCoords, vec3 viewDir, mat3 tangentToWorldMatrix)
{
// compute view direction in tangent space
vec3 tangentViewDir = normalize(viewDir * tangentToWorldMatrix);

vec2 displacement = tangentViewDir.xy * -parallaxDepthScale / tangentViewDir.z;
vec2 displacement = tangentViewDir.xy * -u_ParallaxDepthScale / tangentViewDir.z;

const int linearSearchSteps = 16;
const int binarySearchSteps = 6;

float depthStep = 1.0 / float(linearSearchSteps);
float topDepth = 1.0 - parallaxOffsetBias;
float topDepth = 1.0 - u_ParallaxOffsetBias;

// current size of search window
float currentSize = depthStep;
@@ -32,8 +32,6 @@ uniform float u_EnvironmentInterpolation;

uniform float u_AlphaThreshold;
uniform vec3 u_ViewOrigin;
uniform float u_ParallaxDepthScale;
uniform float u_ParallaxOffsetBias;

uniform sampler3D u_LightGrid1;
uniform sampler3D u_LightGrid2;
@@ -95,7 +93,7 @@ void main()

#if defined(USE_PARALLAX_MAPPING)
// compute texcoords offset from heightmap
vec2 texOffset = ParallaxTexOffset(texNormal, u_ParallaxDepthScale, u_ParallaxOffsetBias, viewDir, tangentToWorldMatrix);
vec2 texOffset = ParallaxTexOffset(texNormal, viewDir, tangentToWorldMatrix);

texDiffuse += texOffset;
texGlow += texOffset;
@@ -27,8 +27,6 @@ uniform sampler2D u_SpecularMap;
uniform sampler2D u_GlowMap;

uniform float u_AlphaThreshold;
uniform float u_ParallaxDepthScale;
uniform float u_ParallaxOffsetBias;
uniform float u_LightWrapAround;

uniform sampler3D u_LightGrid1;
@@ -91,7 +89,7 @@ void main()

#if defined(USE_PARALLAX_MAPPING)
// compute texcoords offset from heightmap
vec2 texOffset = ParallaxTexOffset(texNormal, u_ParallaxDepthScale, u_ParallaxOffsetBias, viewDir, tangentToWorldMatrix);
vec2 texOffset = ParallaxTexOffset(texNormal, viewDir, tangentToWorldMatrix);

texDiffuse += texOffset;
texGlow += texOffset;

0 comments on commit 0beb003

Please sign in to comment.
You can’t perform that action at this time.