0% found this document useful (0 votes)
22 views

HDR

This document defines constants and uniforms for different shader modes including copy, gray, blur, heat, and FXAA. It includes headers for prefix, srgb, and tone mapping. For the vertex shader, it sets texture coordinates and outputs screen position and color. The fragment shader contains code for each mode - blur applies a weighted blur kernel, copy and gray do color operations, heat adds noise, and FXAA contains antialiasing code. Color and tone mapping are applied to the final output.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

HDR

This document defines constants and uniforms for different shader modes including copy, gray, blur, heat, and FXAA. It includes headers for prefix, srgb, and tone mapping. For the vertex shader, it sets texture coordinates and outputs screen position and color. The fragment shader contains code for each mode - blur applies a weighted blur kernel, copy and gray do color operations, heat adds noise, and FXAA contains antialiasing code. Color and tone mapping are applied to the final output.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

#include "prefix.

glsl"

#define MODE_COPY 0
#define MODE_GRAY 1
#define MODE_BLUR 2
#define MODE_HEAT 3
#define MODE_FXAA 4

// Set this to 1 to get light metering HUD in HDR mode.


#define WANT_LIGHTMETER 0

#define FXAA_GREEN_AS_LUMA 1

#if __VERSION__ >= 130


#define FXAA_GLSL_130 1
#else
#define FXAA_GLSL_120 1
#endif

#if FSHADER && MODE == MODE_FXAA


#include "Fxaa3_11.glsl"
#endif

#include "srgb.glsl"

#line 31

uniform vec2 u_offset;


uniform vec4 u_kernel1;
uniform vec4 u_kernel2;
uniform float u_time;
#if MODE == MODE_FXAA
uniform vec4 u_super_dim;
#endif
uniform mat4 u_mvp_matrix;

varying vec4 v_screen_pos;


varying vec4 v_color;
varying vec2 v_texcoord0;

uniform vec2 u_filter[4];

#if TONE_MAP
#include "tone_map.glsl"
#endif

#if VSHADER

attribute vec4 a_vertex;


attribute vec4 a_color;
attribute vec2 a_texcoord0;

void main (void)


{
v_texcoord0.st = a_texcoord0;
v_screen_pos = u_mvp_matrix * a_vertex;
gl_Position = v_screen_pos;
v_color = a_color;;

#if TONE_MAP

calc_light_meter();

#endif
}

#endif

#if FSHADER

uniform sampler2D u_tex1;


uniform sampler2D u_tex2;

#define K 1.0

vec4 final_color_correct(vec4 in_color)


{
vec3 rgb = in_color.rgb;

#if TONE_MAP
#if TO_SRGB
tone_map_linear_to_srgb(rgb);
#else
tone_map(rgb);
#endif
#elif TO_SRGB
rgb = to_srgb(rgb);
#endif

return vec4(rgb,in_color.a);
}

void main (void)


{
#if MODE==MODE_BLUR

gl_FragColor =
u_kernel2.w * texture2D(u_tex1, v_texcoord0.st - 7.0 *
u_offset * K)
+ u_kernel2.z * texture2D(u_tex1, v_texcoord0.st - 6.0 *
u_offset * K)
+ u_kernel2.y * texture2D(u_tex1, v_texcoord0.st - 5.0 *
u_offset * K)
+ u_kernel2.x * texture2D(u_tex1, v_texcoord0.st - 4.0 *
u_offset * K)
+ u_kernel1.w * texture2D(u_tex1, v_texcoord0.st - 3.0 *
u_offset * K)
+ u_kernel1.z * texture2D(u_tex1, v_texcoord0.st - 2.0 *
u_offset * K)
+ u_kernel1.y * texture2D(u_tex1, v_texcoord0.st - u_offset *
K)
+ u_kernel1.x * texture2D(u_tex1, v_texcoord0.st )
+ u_kernel1.y * texture2D(u_tex1, v_texcoord0.st + u_offset *
K)
+ u_kernel1.z * texture2D(u_tex1, v_texcoord0.st + 2.0 *
u_offset * K)
+ u_kernel1.w * texture2D(u_tex1, v_texcoord0.st + 3.0 *
u_offset * K)
+ u_kernel2.x * texture2D(u_tex1, v_texcoord0.st + 4.0 *
u_offset * K)
+ u_kernel2.y * texture2D(u_tex1, v_texcoord0.st + 5.0 *
u_offset * K)
+ u_kernel2.z * texture2D(u_tex1, v_texcoord0.st + 6.0 *
u_offset * K)
+ u_kernel2.w * texture2D(u_tex1, v_texcoord0.st + 7.0 *
u_offset * K);
#endif

#if MODE==MODE_COPY
gl_FragColor = v_color * final_color_correct(texture2D(u_tex1,
v_texcoord0.st));
#endif

#if MODE==MODE_GRAY
// Grayscale shader. v_color's rgb is the weight ratios to convert to
gray - usually
// mostly green since that's how our eyes work.

vec4 rgba = texture2D(u_tex1, v_texcoord0.st);


rgba.rgb = vec3(dot(v_color.rgb,rgba.rgb));
rgba = final_color_correct(rgba);
rgba.a *= v_color.a;
gl_FragColor = rgba;
#endif

#if MODE==MODE_HEAT
// gl_FragColor = texture2D(u_tex1, v_screen_pos.st);
vec2 screen_rat = vec2(
(v_screen_pos.x /
v_screen_pos.w) * 0.5 + 0.5,
(v_screen_pos.y /
v_screen_pos.w) * 0.5 + 0.5);
float t1 = fract(u_time);
t1 = (t1 > 0.5) ? (1.0 - t1) : t1;
t1 *= 2.0;
float t2 = 1.0 - t1;

vec2 noise_st1 = texture2D(u_tex2, screen_rat*0.5


+vec2(0,u_time)).rg * 2.0 - vec2(1.0);
vec2 noise_st2 = texture2D(u_tex2, screen_rat*0.5 +
vec2(0.5)+vec2(u_time,0)).rg * 2.0 - vec2(1.0);

vec3 blur = texture2D(u_tex1, screen_rat


+ noise_st1 * 0.001 * t1
+ noise_st2 * 0.001 * t2).rgb;

gl_FragColor = vec4(blur,v_color.a);
gl_FragColor = final_color_correct(gl_FragColor);

// gl_FragColor = vec4(blur,0.25+noise);
// gl_FragColor = vec4(0.5 + noise);

#endif

#if MODE==MODE_FXAA

// gl_FragColor.rgb = FxaaPixelShader(v_texcoord0.xy, u_tex1, u_offset);

gl_FragColor = vec4(0.0);

for(int x = 0; x < u_super_dim.x; ++x)


for(int y = 0; y < u_super_dim.y; ++y)
{
vec2 sub_pos = v_texcoord0.xy + vec2(x,y) * u_offset -
u_super_dim.zw;
gl_FragColor += FxaaPixelShader(
// v_texcoord0.xy,
// pos
sub_pos,
vec4(0.0),
// console pos
u_tex1,
// tex
u_tex1,
// console tex-1
u_tex1,
// console tex-2
u_offset,
// 1/screen size
vec4(0.0),
// console screen offsets
vec4(0.0),
// console screen offsets
vec4(0.0),
// console screen offsets
0.75,
// sub px qual
0.166,
// edge thesh
0.0833,
// min thresh
0.0,
// sharpness (console)
0.05,
// console edge
0.0,
// console edge min
vec4(0.0));
// console directional constants
}
gl_FragColor *= (1.0 / (u_super_dim.x * u_super_dim.y));

// gl_FragColor.rgb = texture2D(u_tex1,v_texcoord0.xy).xyz;
gl_FragColor = final_color_correct(gl_FragColor);
gl_FragColor.a = 1.0;

#endif
}
#endif

You might also like