Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
HybridDog committed Sep 27, 2017
1 parent 50b2185 commit 0c0ccb9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
43 changes: 40 additions & 3 deletions client/shaders/nodes_shader/opengl_fragment.glsl
Expand Up @@ -4,6 +4,7 @@ uniform sampler2D textureFlags;

uniform vec4 skyBgColor;
uniform float fogDistance;
uniform float averageBrightness;
uniform vec3 eyePosition;

varying vec3 vPosition;
Expand Down Expand Up @@ -46,7 +47,7 @@ vec4 applyToneMapping(vec4 color)
const float gamma = 1.6;
const float exposureBias = 5.5;
color.rgb = uncharted2Tonemap(exposureBias * color.rgb);
// Precalculated white_scale from
// Precalculated white_scale from
//vec3 whiteScale = 1.0 / uncharted2Tonemap(vec3(W));
vec3 whiteScale = vec3(1.036015346);
color.rgb *= whiteScale;
Expand Down Expand Up @@ -195,8 +196,44 @@ void main(void)
color = base.rgb;
#endif

vec4 col = vec4(color.rgb * gl_Color.rgb, 1.0);

float a, b;
b = 0;

if (averageBrightness < 0.15) {
b = 6.9216142999862;
a = 1.0009872101959;
} else if (averageBrightness < 0.25) {
b = 3.2812798961849;
a = 1.0390475388339;
} else if (averageBrightness < 0.35) {
b = 1.8010717753886;
a = 1.1977795369103;
} else if (averageBrightness < 0.45) {
b = 0.82216323430739;
a = 1.7840574297201;
} else if (averageBrightness < 0.55) {
b = 8.1838768211219e-12;
a = 122191161173.47;
} else if (averageBrightness < 0.65) {
b = -0.82216323430739;
a = -0.78405742972006;
} else if (averageBrightness < 0.75) {
b = -1.8010717753886;
a = -0.1977795369103;
} else if (averageBrightness < 0.85) {
b = -3.2812798961849;
a = -0.039047538833918;
} else if (averageBrightness < 0.95) {
b = -6.9216142999862;
a = -0.00098721019590494;
}
if (b != 0)
color.rgb = (vec3(1.0) - pow(vec3(e), -color.rgb * b)) * a;

color.rgb = (color.rgb - vec3(0.5)) * 1.3 + vec3(0.5);

vec4 col = vec4(color.rgb * gl_Color.rgb, 1.0);

#ifdef ENABLE_TONE_MAPPING
col = applyToneMapping(col);
#endif
Expand Down
5 changes: 5 additions & 0 deletions src/game.cpp
Expand Up @@ -612,6 +612,7 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
bool m_fog_enabled;
CachedPixelShaderSetting<float, 4> m_sky_bg_color;
CachedPixelShaderSetting<float> m_fog_distance;
CachedPixelShaderSetting<float> m_average_brightness;
CachedVertexShaderSetting<float> m_animation_timer_vertex;
CachedPixelShaderSetting<float> m_animation_timer_pixel;
CachedPixelShaderSetting<float, 3> m_day_light;
Expand Down Expand Up @@ -644,6 +645,7 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
m_fog_range(fog_range),
m_sky_bg_color("skyBgColor"),
m_fog_distance("fogDistance"),
m_average_brightness("averageBrightness"),
m_animation_timer_vertex("animationTimer"),
m_animation_timer_pixel("animationTimer"),
m_day_light("dayLight"),
Expand Down Expand Up @@ -689,6 +691,9 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter

m_fog_distance.set(&fog_distance, services);

float avgbr = 0.3f;
m_average_brightness.set(&avgbr, services);

u32 daynight_ratio = (float)m_client->getEnv().getDayNightRatio();
video::SColorf sunlight;
get_sunlight_color(&sunlight, daynight_ratio);
Expand Down

0 comments on commit 0c0ccb9

Please sign in to comment.