Remove textures vertical offset. Fix for area enabling parallax.

This commit is contained in:
RealBadAngel 2015-06-21 00:11:09 +02:00
parent a31d08be55
commit 53efe2ef42
2 changed files with 16 additions and 12 deletions

@ -8,7 +8,7 @@ uniform vec3 eyePosition;
varying vec3 vPosition; varying vec3 vPosition;
varying vec3 worldPosition; varying vec3 worldPosition;
varying float generate_heightmaps; varying float area_enable_parallax;
varying vec3 eyeVec; varying vec3 eyeVec;
varying vec3 tsEyeVec; varying vec3 tsEyeVec;
@ -95,7 +95,7 @@ void main (void)
vec3 eyeRay = normalize(tsEyeVec); vec3 eyeRay = normalize(tsEyeVec);
#if PARALLAX_OCCLUSION_MODE == 0 #if PARALLAX_OCCLUSION_MODE == 0
// Parallax occlusion with slope information // Parallax occlusion with slope information
if (normalTexturePresent) { if (normalTexturePresent && area_enable_parallax > 0.0) {
const float scale = PARALLAX_OCCLUSION_SCALE / PARALLAX_OCCLUSION_ITERATIONS; const float scale = PARALLAX_OCCLUSION_SCALE / PARALLAX_OCCLUSION_ITERATIONS;
const float bias = PARALLAX_OCCLUSION_BIAS / PARALLAX_OCCLUSION_ITERATIONS; const float bias = PARALLAX_OCCLUSION_BIAS / PARALLAX_OCCLUSION_ITERATIONS;
for(int i = 0; i < PARALLAX_OCCLUSION_ITERATIONS; i++) { for(int i = 0; i < PARALLAX_OCCLUSION_ITERATIONS; i++) {
@ -106,12 +106,12 @@ void main (void)
#endif #endif
#if PARALLAX_OCCLUSION_MODE == 1 #if PARALLAX_OCCLUSION_MODE == 1
// Relief mapping // Relief mapping
if (normalTexturePresent) { if (normalTexturePresent && area_enable_parallax > 0.0) {
vec2 ds = eyeRay.xy * PARALLAX_OCCLUSION_SCALE; vec2 ds = eyeRay.xy * PARALLAX_OCCLUSION_SCALE;
float dist = find_intersection(uv, ds); float dist = find_intersection(uv, ds);
uv += dist * ds; uv += dist * ds;
#endif #endif
} else if (generate_heightmaps > 0.0) { } else if (area_enable_parallax > 0.0) {
vec2 ds = eyeRay.xy * PARALLAX_OCCLUSION_SCALE; vec2 ds = eyeRay.xy * PARALLAX_OCCLUSION_SCALE;
float dist = find_intersectionRGB(uv, ds); float dist = find_intersectionRGB(uv, ds);
uv += dist * ds; uv += dist * ds;

@ -14,7 +14,7 @@ varying vec3 eyeVec;
varying vec3 lightVec; varying vec3 lightVec;
varying vec3 tsEyeVec; varying vec3 tsEyeVec;
varying vec3 tsLightVec; varying vec3 tsLightVec;
varying float generate_heightmaps; varying float area_enable_parallax;
const float e = 2.718281828459; const float e = 2.718281828459;
const float BS = 10.0; const float BS = 10.0;
@ -35,12 +35,16 @@ float smoothTriangleWave(float x)
void main(void) void main(void)
{ {
gl_TexCoord[0] = gl_MultiTexCoord0; gl_TexCoord[0] = gl_MultiTexCoord0;
gl_TexCoord[0].y += 0.008; //TODO: make offset depending on view angle and parallax uv displacement
//thats for textures that doesnt align vertically, like dirt with grass
//gl_TexCoord[0].y += 0.008;
//Allow parallax/relief mapping only for certain kind of nodes
//Variable is also used to control area of the effect
#if ((DRAW_TYPE == NDT_NORMAL || DRAW_TYPE == NDT_LIQUID || DRAW_TYPE == NDT_FLOWINGLIQUID) && GENERATE_NORMALMAPS) #if ((DRAW_TYPE == NDT_NORMAL || DRAW_TYPE == NDT_LIQUID || DRAW_TYPE == NDT_FLOWINGLIQUID) && GENERATE_NORMALMAPS)
generate_heightmaps = 1.0; area_enable_parallax = 1.0;
#else #else
generate_heightmaps = 0.0; area_enable_parallax = 0.0;
#endif #endif
#if ((MATERIAL_TYPE == TILE_MATERIAL_LIQUID_TRANSPARENT || MATERIAL_TYPE == TILE_MATERIAL_LIQUID_OPAQUE) && ENABLE_WAVING_WATER) #if ((MATERIAL_TYPE == TILE_MATERIAL_LIQUID_TRANSPARENT || MATERIAL_TYPE == TILE_MATERIAL_LIQUID_OPAQUE) && ENABLE_WAVING_WATER)
@ -89,9 +93,9 @@ void main(void)
worldPosition = (mWorld * gl_Vertex).xyz; worldPosition = (mWorld * gl_Vertex).xyz;
// Don't generate heightmaps when too far from the eye // Don't generate heightmaps when too far from the eye
float dist = distance (worldPosition, eyePosition); float dist = distance (vec3(0.0, 0.0 ,0.0), vPosition);
if (dist > 100.00) { if (dist > 100.0) {
generate_heightmaps = 0.0; area_enable_parallax = 0.0;
} }
vec3 sunPosition = vec3 (0.0, eyePosition.y * BS + 900.0, 0.0); vec3 sunPosition = vec3 (0.0, eyePosition.y * BS + 900.0, 0.0);