Skip to content

Commit 5fde697

Browse files
authoredSep 26, 2019
Simple shader fixes. (#8991)
1. Pass current camera offset to shader, so shader have access to the global coordinates 2. Pass animation timer to fragment shader. C++ code is already there, just wasn't declared in the shader 3. Delay animation timer wrap-around (from 100s to about 16 minutes)
1 parent 9e95bac commit 5fde697

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed
 

Diff for: ‎client/shaders/nodes_shader/opengl_fragment.glsl

+9
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@ uniform vec4 skyBgColor;
66
uniform float fogDistance;
77
uniform vec3 eyePosition;
88

9+
// The cameraOffset is the current center of the visible world.
10+
uniform vec3 cameraOffset;
11+
uniform float animationTimer;
12+
913
varying vec3 vPosition;
14+
// World position in the visible world (i.e. relative to the cameraOffset.)
15+
// This can be used for many shader effects without loss of precision.
16+
// If the absolute position is required it can be calculated with
17+
// cameraOffset + worldPosition (for large coordinates the limits of float
18+
// precision must be considered).
1019
varying vec3 worldPosition;
1120
varying float area_enable_parallax;
1221

Diff for: ‎client/shaders/nodes_shader/opengl_vertex.glsl

+8
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,17 @@ uniform mat4 mWorld;
44
// Color of the light emitted by the sun.
55
uniform vec3 dayLight;
66
uniform vec3 eyePosition;
7+
8+
// The cameraOffset is the current center of the visible world.
9+
uniform vec3 cameraOffset;
710
uniform float animationTimer;
811

912
varying vec3 vPosition;
13+
// World position in the visible world (i.e. relative to the cameraOffset.)
14+
// This can be used for many shader effects without loss of precision.
15+
// If the absolute position is required it can be calculated with
16+
// cameraOffset + worldPosition (for large coordinates the limits of float
17+
// precision must be considered).
1018
varying vec3 worldPosition;
1119

1220
varying vec3 eyeVec;

Diff for: ‎src/client/game.cpp

+17-1
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,8 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
413413
CachedPixelShaderSetting<float, 3> m_eye_position_pixel;
414414
CachedVertexShaderSetting<float, 3> m_eye_position_vertex;
415415
CachedPixelShaderSetting<float, 3> m_minimap_yaw;
416+
CachedPixelShaderSetting<float, 3> m_camera_offset_pixel;
417+
CachedPixelShaderSetting<float, 3> m_camera_offset_vertex;
416418
CachedPixelShaderSetting<SamplerLayer_t> m_base_texture;
417419
CachedPixelShaderSetting<SamplerLayer_t> m_normal_texture;
418420
CachedPixelShaderSetting<SamplerLayer_t> m_texture_flags;
@@ -445,6 +447,8 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
445447
m_eye_position_pixel("eyePosition"),
446448
m_eye_position_vertex("eyePosition"),
447449
m_minimap_yaw("yawVec"),
450+
m_camera_offset_pixel("cameraOffset"),
451+
m_camera_offset_vertex("cameraOffset"),
448452
m_base_texture("baseTexture"),
449453
m_normal_texture("normalTexture"),
450454
m_texture_flags("textureFlags"),
@@ -493,7 +497,7 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
493497
sunlight.b };
494498
m_day_light.set(dnc, services);
495499

496-
u32 animation_timer = porting::getTimeMs() % 100000;
500+
u32 animation_timer = porting::getTimeMs() % 1000000;
497501
float animation_timer_f = (float)animation_timer / 100000.f;
498502
m_animation_timer_vertex.set(&animation_timer_f, services);
499503
m_animation_timer_pixel.set(&animation_timer_f, services);
@@ -523,6 +527,18 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
523527
m_minimap_yaw.set(minimap_yaw_array, services);
524528
}
525529

530+
float camera_offset_array[3];
531+
v3f offset = intToFloat(m_client->getCamera()->getOffset(), BS);
532+
#if (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 8)
533+
camera_offset_array[0] = offset.X;
534+
camera_offset_array[1] = offset.Y;
535+
camera_offset_array[2] = offset.Z;
536+
#else
537+
offset.getAs3Values(camera_offset_array);
538+
#endif
539+
m_camera_offset_pixel.set(camera_offset_array, services);
540+
m_camera_offset_vertex.set(camera_offset_array, services);
541+
526542
SamplerLayer_t base_tex = 0,
527543
normal_tex = 1,
528544
flags_tex = 2;

0 commit comments

Comments
 (0)
Please sign in to comment.