Style: Fix code formatting in GLES3 shaders

This commit is contained in:
Rémi Verschelde 2018-08-24 13:42:18 +02:00
parent f123694b4e
commit 1b6d75a599
17 changed files with 1552 additions and 1923 deletions

View file

@ -1,6 +1,5 @@
[vertex] [vertex]
/* /*
from VisualServer: from VisualServer:
@ -110,7 +109,6 @@ uniform float blend_amount;
void main() { void main() {
#ifdef ENABLE_BLEND #ifdef ENABLE_BLEND
vertex_out = vertex_attrib_blend + vertex_attrib * blend_amount; vertex_out = vertex_attrib_blend + vertex_attrib * blend_amount;
@ -140,7 +138,6 @@ void main() {
uv2_out = uv2_attrib_blend + uv2_attrib * blend_amount; uv2_out = uv2_attrib_blend + uv2_attrib * blend_amount;
#endif #endif
#ifdef ENABLE_SKELETON #ifdef ENABLE_SKELETON
bone_out = bone_attrib_blend; bone_out = bone_attrib_blend;
@ -149,7 +146,6 @@ void main() {
#else //ENABLE_BLEND #else //ENABLE_BLEND
vertex_out = vertex_attrib * blend_amount; vertex_out = vertex_attrib * blend_amount;
#ifdef ENABLE_NORMAL #ifdef ENABLE_NORMAL
@ -177,7 +173,6 @@ void main() {
uv2_out = uv2_attrib * blend_amount; uv2_out = uv2_attrib * blend_amount;
#endif #endif
#ifdef ENABLE_SKELETON #ifdef ENABLE_SKELETON
bone_out = bone_attrib; bone_out = bone_attrib;
@ -190,8 +185,6 @@ void main() {
[fragment] [fragment]
void main() { void main() {
} }

View file

@ -1,6 +1,5 @@
[vertex] [vertex]
layout(location = 0) in highp vec2 vertex; layout(location = 0) in highp vec2 vertex;
layout(location = 3) in vec4 color_attrib; layout(location = 3) in vec4 color_attrib;
@ -31,12 +30,11 @@ layout(location=12) in highp vec4 instance_custom_data;
layout(location = 4) in highp vec2 uv_attrib; layout(location = 4) in highp vec2 uv_attrib;
//skeletn // skeleton
#endif #endif
uniform highp vec2 color_texpixel_size; uniform highp vec2 color_texpixel_size;
layout(std140) uniform CanvasItemData { //ubo:0 layout(std140) uniform CanvasItemData { //ubo:0
highp mat4 projection_matrix; highp mat4 projection_matrix;
@ -46,7 +44,6 @@ layout(std140) uniform CanvasItemData { //ubo:0
uniform highp mat4 modelview_matrix; uniform highp mat4 modelview_matrix;
uniform highp mat4 extra_matrix; uniform highp mat4 extra_matrix;
out highp vec2 uv_interp; out highp vec2 uv_interp;
out mediump vec4 color_interp; out mediump vec4 color_interp;
@ -55,7 +52,6 @@ out mediump vec4 color_interp;
out highp vec2 pixel_size_interp; out highp vec2 pixel_size_interp;
#endif #endif
#ifdef USE_SKELETON #ifdef USE_SKELETON
uniform mediump sampler2D skeleton_texture; // texunit:-1 uniform mediump sampler2D skeleton_texture; // texunit:-1
uniform highp mat4 skeleton_transform; uniform highp mat4 skeleton_transform;
@ -80,11 +76,9 @@ layout(std140) uniform LightData { //ubo:1
highp float shadow_distance_mult; highp float shadow_distance_mult;
}; };
out vec4 light_uv_interp; out vec4 light_uv_interp;
out vec2 transformed_light_uv; out vec2 transformed_light_uv;
out vec4 local_rot; out vec4 local_rot;
#ifdef USE_SHADOWS #ifdef USE_SHADOWS
@ -101,7 +95,6 @@ uniform int h_frames;
uniform int v_frames; uniform int v_frames;
#endif #endif
#if defined(USE_MATERIAL) #if defined(USE_MATERIAL)
layout(std140) uniform UniformData { //ubo:2 layout(std140) uniform UniformData { //ubo:2
@ -112,7 +105,6 @@ MATERIAL_UNIFORMS
#endif #endif
VERTEX_SHADER_GLOBALS VERTEX_SHADER_GLOBALS
void main() { void main() {
@ -143,7 +135,6 @@ void main() {
highp vec4 outvec = vec4(vertex, 0.0, 1.0); highp vec4 outvec = vec4(vertex, 0.0, 1.0);
#endif #endif
#ifdef USE_PARTICLES #ifdef USE_PARTICLES
//scale by texture size //scale by texture size
outvec.xy /= color_texpixel_size; outvec.xy /= color_texpixel_size;
@ -158,7 +149,6 @@ void main() {
#endif #endif
#define extra_matrix extra_matrix2 #define extra_matrix extra_matrix2
{ {
@ -167,7 +157,6 @@ VERTEX_SHADER_CODE
} }
#ifdef USE_NINEPATCH #ifdef USE_NINEPATCH
pixel_size_interp = abs(dst_rect.zw) * vertex; pixel_size_interp = abs(dst_rect.zw) * vertex;
@ -187,7 +176,6 @@ VERTEX_SHADER_CODE
outvec.xy = floor(outvec + 0.5).xy; outvec.xy = floor(outvec + 0.5).xy;
#endif #endif
#ifdef USE_SKELETON #ifdef USE_SKELETON
if (bone_weights != vec4(0.0)) { //must be a valid bone if (bone_weights != vec4(0.0)) { //must be a valid bone
@ -197,32 +185,32 @@ VERTEX_SHADER_CODE
ivec2 tex_ofs = ivec2(bone_indicesi.x % 256, (bone_indicesi.x / 256) * 2); ivec2 tex_ofs = ivec2(bone_indicesi.x % 256, (bone_indicesi.x / 256) * 2);
highp mat2x4 m = mat2x4( highp mat2x4 m;
m = mat2x4(
texelFetch(skeleton_texture, tex_ofs, 0), texelFetch(skeleton_texture, tex_ofs, 0),
texelFetch(skeleton_texture,tex_ofs+ivec2(0,1),0) texelFetch(skeleton_texture, tex_ofs + ivec2(0, 1), 0))
) * bone_weights.x; * bone_weights.x;
tex_ofs = ivec2(bone_indicesi.y % 256, (bone_indicesi.y / 256) * 2); tex_ofs = ivec2(bone_indicesi.y % 256, (bone_indicesi.y / 256) * 2);
m += mat2x4( m += mat2x4(
texelFetch(skeleton_texture, tex_ofs, 0), texelFetch(skeleton_texture, tex_ofs, 0),
texelFetch(skeleton_texture,tex_ofs+ivec2(0,1),0) texelFetch(skeleton_texture, tex_ofs + ivec2(0, 1), 0))
) * bone_weights.y; * bone_weights.y;
tex_ofs = ivec2(bone_indicesi.z % 256, (bone_indicesi.z / 256) * 2); tex_ofs = ivec2(bone_indicesi.z % 256, (bone_indicesi.z / 256) * 2);
m += mat2x4( m += mat2x4(
texelFetch(skeleton_texture, tex_ofs, 0), texelFetch(skeleton_texture, tex_ofs, 0),
texelFetch(skeleton_texture,tex_ofs+ivec2(0,1),0) texelFetch(skeleton_texture, tex_ofs + ivec2(0, 1), 0))
) * bone_weights.z; * bone_weights.z;
tex_ofs = ivec2(bone_indicesi.w % 256, (bone_indicesi.w / 256) * 2); tex_ofs = ivec2(bone_indicesi.w % 256, (bone_indicesi.w / 256) * 2);
m += mat2x4( m += mat2x4(
texelFetch(skeleton_texture, tex_ofs, 0), texelFetch(skeleton_texture, tex_ofs, 0),
texelFetch(skeleton_texture,tex_ofs+ivec2(0,1),0) texelFetch(skeleton_texture, tex_ofs + ivec2(0, 1), 0))
) * bone_weights.w; * bone_weights.w;
mat4 bone_matrix = skeleton_transform * transpose(mat4(m[0], m[1], vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0))) * skeleton_transform_inverse; mat4 bone_matrix = skeleton_transform * transpose(mat4(m[0], m[1], vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0))) * skeleton_transform_inverse;
@ -248,7 +236,6 @@ VERTEX_SHADER_CODE
pos = outvec.xy; pos = outvec.xy;
#endif #endif
local_rot.xy = normalize((modelview_matrix * (extra_matrix * vec4(1.0, 0.0, 0.0, 0.0))).xy); local_rot.xy = normalize((modelview_matrix * (extra_matrix * vec4(1.0, 0.0, 0.0, 0.0))).xy);
local_rot.zw = normalize((modelview_matrix * (extra_matrix * vec4(0.0, 1.0, 0.0, 0.0))).xy); local_rot.zw = normalize((modelview_matrix * (extra_matrix * vec4(0.0, 1.0, 0.0, 0.0))).xy);
#ifdef USE_TEXTURE_RECT #ifdef USE_TEXTURE_RECT
@ -256,25 +243,18 @@ VERTEX_SHADER_CODE
local_rot.zw *= sign(src_rect.w); local_rot.zw *= sign(src_rect.w);
#endif #endif
#endif #endif
} }
[fragment] [fragment]
uniform mediump sampler2D color_texture; // texunit:0 uniform mediump sampler2D color_texture; // texunit:0
uniform highp vec2 color_texpixel_size; uniform highp vec2 color_texpixel_size;
uniform mediump sampler2D normal_texture; // texunit:1 uniform mediump sampler2D normal_texture; // texunit:1
in highp vec2 uv_interp; in highp vec2 uv_interp;
in mediump vec4 color_interp; in mediump vec4 color_interp;
#if defined(SCREEN_TEXTURE_USED) #if defined(SCREEN_TEXTURE_USED)
uniform sampler2D screen_texture; // texunit:-3 uniform sampler2D screen_texture; // texunit:-3
@ -292,7 +272,6 @@ layout(std140) uniform CanvasItemData {
highp float time; highp float time;
}; };
#ifdef USE_LIGHTING #ifdef USE_LIGHTING
layout(std140) uniform LightData { layout(std140) uniform LightData {
@ -314,10 +293,8 @@ uniform lowp sampler2D light_texture; // texunit:-1
in vec4 light_uv_interp; in vec4 light_uv_interp;
in vec2 transformed_light_uv; in vec2 transformed_light_uv;
in vec4 local_rot; in vec4 local_rot;
#ifdef USE_SHADOWS #ifdef USE_SHADOWS
uniform highp sampler2D shadow_texture; // texunit:-2 uniform highp sampler2D shadow_texture; // texunit:-2
@ -332,12 +309,8 @@ const bool at_light_pass = false;
uniform mediump vec4 final_modulate; uniform mediump vec4 final_modulate;
layout(location = 0) out mediump vec4 frag_color; layout(location = 0) out mediump vec4 frag_color;
#if defined(USE_MATERIAL) #if defined(USE_MATERIAL)
layout(std140) uniform UniformData { layout(std140) uniform UniformData {
@ -369,7 +342,6 @@ void light_compute(
LIGHT_SHADER_CODE LIGHT_SHADER_CODE
#endif #endif
} }
#ifdef USE_TEXTURE_RECT #ifdef USE_TEXTURE_RECT
@ -388,11 +360,8 @@ uniform bool np_draw_center;
// left top right bottom in pixel coordinates // left top right bottom in pixel coordinates
uniform vec4 np_margins; uniform vec4 np_margins;
float map_ninepatch_axis(float pixel, float draw_size, float tex_pixel_size, float margin_begin, float margin_end, int np_repeat, inout int draw_center) { float map_ninepatch_axis(float pixel, float draw_size, float tex_pixel_size, float margin_begin, float margin_end, int np_repeat, inout int draw_center) {
float tex_size = 1.0 / tex_pixel_size; float tex_size = 1.0 / tex_pixel_size;
if (pixel < margin_begin) { if (pixel < margin_begin) {
@ -426,7 +395,6 @@ float map_ninepatch_axis(float pixel, float draw_size,float tex_pixel_size,float
return (margin_begin + ratio * dst_area) * tex_pixel_size; return (margin_begin + ratio * dst_area) * tex_pixel_size;
} }
} }
} }
#endif #endif
@ -446,8 +414,7 @@ void main() {
int draw_center = 2; int draw_center = 2;
uv = vec2( uv = vec2(
map_ninepatch_axis(pixel_size_interp.x, abs(dst_rect.z), color_texpixel_size.x, np_margins.x, np_margins.z, np_repeat_h, draw_center), map_ninepatch_axis(pixel_size_interp.x, abs(dst_rect.z), color_texpixel_size.x, np_margins.x, np_margins.z, np_repeat_h, draw_center),
map_ninepatch_axis(pixel_size_interp.y,abs(dst_rect.w),color_texpixel_size.y,np_margins.y,np_margins.w,np_repeat_v,draw_center) map_ninepatch_axis(pixel_size_interp.y, abs(dst_rect.w), color_texpixel_size.y, np_margins.y, np_margins.w, np_repeat_v, draw_center));
);
if (draw_center == 0) { if (draw_center == 0) {
color.a = 0.0; color.a = 0.0;
@ -477,8 +444,6 @@ void main() {
#endif #endif
vec3 normal; vec3 normal;
#if defined(NORMAL_USED) #if defined(NORMAL_USED)
@ -496,13 +461,10 @@ void main() {
normal = vec3(0.0, 0.0, 1.0); normal = vec3(0.0, 0.0, 1.0);
} }
#if defined(SCREEN_UV_USED) #if defined(SCREEN_UV_USED)
vec2 screen_uv = gl_FragCoord.xy * screen_pixel_size; vec2 screen_uv = gl_FragCoord.xy * screen_pixel_size;
#endif #endif
{ {
float normal_depth = 1.0; float normal_depth = 1.0;
@ -515,18 +477,14 @@ FRAGMENT_SHADER_CODE
#if defined(NORMALMAP_USED) #if defined(NORMALMAP_USED)
normal = mix(vec3(0.0, 0.0, 1.0), normal_map * vec3(2.0, -2.0, 1.0) - vec3(1.0, -1.0, 0.0), normal_depth); normal = mix(vec3(0.0, 0.0, 1.0), normal_map * vec3(2.0, -2.0, 1.0) - vec3(1.0, -1.0, 0.0), normal_depth);
#endif #endif
} }
#ifdef DEBUG_ENCODED_32 #ifdef DEBUG_ENCODED_32
highp float enc32 = dot(color, highp vec4(1.0 / (256.0 * 256.0 * 256.0), 1.0 / (256.0 * 256.0), 1.0 / 256.0, 1)); highp float enc32 = dot(color, highp vec4(1.0 / (256.0 * 256.0 * 256.0), 1.0 / (256.0 * 256.0), 1.0 / 256.0, 1));
color = vec4(vec3(enc32), 1.0); color = vec4(vec3(enc32), 1.0);
#endif #endif
color *= final_modulate; color *= final_modulate;
#ifdef USE_LIGHTING #ifdef USE_LIGHTING
vec2 light_vec = transformed_light_uv; vec2 light_vec = transformed_light_uv;
@ -600,10 +558,8 @@ FRAGMENT_SHADER_CODE
point = vec2(-light_vec.y, light_vec.x); point = vec2(-light_vec.y, light_vec.x);
sh = 0.75 + (1.0 / 8.0); sh = 0.75 + (1.0 / 8.0);
} }
highp vec4 s = shadow_matrix * vec4(point, 0.0, 1.0); highp vec4 s = shadow_matrix * vec4(point, 0.0, 1.0);
s.xyz /= s.w; s.xyz /= s.w;
su = s.x * 0.5 + 0.5; su = s.x * 0.5 + 0.5;
@ -622,26 +578,30 @@ FRAGMENT_SHADER_CODE
#endif #endif
#ifdef SHADOW_USE_GRADIENT #ifdef SHADOW_USE_GRADIENT
#define SHADOW_TEST(m_ofs) { highp float sd = SHADOW_DEPTH(shadow_texture,vec2(m_ofs,sh)); shadow_attenuation+=1.0-smoothstep(sd,sd+shadow_gradient,sz); } #define SHADOW_TEST(m_ofs) \
{ \
highp float sd = SHADOW_DEPTH(shadow_texture, vec2(m_ofs, sh)); \
shadow_attenuation += 1.0 - smoothstep(sd, sd + shadow_gradient, sz); \
}
#else #else
#define SHADOW_TEST(m_ofs) { highp float sd = SHADOW_DEPTH(shadow_texture,vec2(m_ofs,sh)); shadow_attenuation+=step(sz,sd); } #define SHADOW_TEST(m_ofs) \
{ \
highp float sd = SHADOW_DEPTH(shadow_texture, vec2(m_ofs, sh)); \
shadow_attenuation += step(sz, sd); \
}
#endif #endif
#ifdef SHADOW_FILTER_NEAREST #ifdef SHADOW_FILTER_NEAREST
SHADOW_TEST(su); SHADOW_TEST(su);
#endif #endif
#ifdef SHADOW_FILTER_PCF3 #ifdef SHADOW_FILTER_PCF3
SHADOW_TEST(su + shadowpixel_size); SHADOW_TEST(su + shadowpixel_size);
@ -651,7 +611,6 @@ FRAGMENT_SHADER_CODE
#endif #endif
#ifdef SHADOW_FILTER_PCF5 #ifdef SHADOW_FILTER_PCF5
SHADOW_TEST(su + shadowpixel_size * 2.0); SHADOW_TEST(su + shadowpixel_size * 2.0);
@ -663,7 +622,6 @@ FRAGMENT_SHADER_CODE
#endif #endif
#ifdef SHADOW_FILTER_PCF7 #ifdef SHADOW_FILTER_PCF7
SHADOW_TEST(su + shadowpixel_size * 3.0); SHADOW_TEST(su + shadowpixel_size * 3.0);
@ -677,7 +635,6 @@ FRAGMENT_SHADER_CODE
#endif #endif
#ifdef SHADOW_FILTER_PCF9 #ifdef SHADOW_FILTER_PCF9
SHADOW_TEST(su + shadowpixel_size * 4.0); SHADOW_TEST(su + shadowpixel_size * 4.0);
@ -722,5 +679,4 @@ FRAGMENT_SHADER_CODE
#endif #endif
//color.rgb *= color.a; //color.rgb *= color.a;
frag_color = color; frag_color = color;
} }

View file

@ -1,7 +1,5 @@
[vertex] [vertex]
uniform highp mat4 projection_matrix; uniform highp mat4 projection_matrix;
uniform highp mat4 light_matrix; uniform highp mat4 light_matrix;
uniform highp mat4 world_matrix; uniform highp mat4 world_matrix;
@ -22,18 +20,14 @@ void main() {
in highp vec4 position_interp; in highp vec4 position_interp;
#ifdef USE_RGBA_SHADOWS #ifdef USE_RGBA_SHADOWS
layout(location = 0) out lowp vec4 distance_buf; layout(location = 0) out lowp vec4 distance_buf;
#else #else
layout(location = 0) out highp float distance_buf; layout(location = 0) out highp float distance_buf;
#endif #endif
void main() { void main() {
highp float depth = ((position_interp.z / position_interp.w) + 1.0) * 0.5 + 0.0;//bias; highp float depth = ((position_interp.z / position_interp.w) + 1.0) * 0.5 + 0.0; // bias
#ifdef USE_RGBA_SHADOWS #ifdef USE_RGBA_SHADOWS
@ -43,7 +37,5 @@ void main() {
#else #else
distance_buf = depth; distance_buf = depth;
#endif #endif
} }

View file

@ -1,6 +1,5 @@
[vertex] [vertex]
layout(location = 0) in highp vec4 vertex_attrib; layout(location = 0) in highp vec4 vertex_attrib;
#if defined(USE_CUBEMAP) || defined(USE_PANORAMA) #if defined(USE_CUBEMAP) || defined(USE_PANORAMA)
layout(location = 4) in vec3 cube_in; layout(location = 4) in vec3 cube_in;
@ -44,7 +43,6 @@ void main() {
uv_interp = copy_section.xy + uv_interp * copy_section.zw; uv_interp = copy_section.xy + uv_interp * copy_section.zw;
gl_Position.xy = (copy_section.xy + (gl_Position.xy * 0.5 + 0.5) * copy_section.zw) * 2.0 - 1.0; gl_Position.xy = (copy_section.xy + (gl_Position.xy * 0.5 + 0.5) * copy_section.zw) * 2.0 - 1.0;
#endif #endif
} }
[fragment] [fragment]
@ -72,7 +70,6 @@ uniform samplerCube source_cube; //texunit:0
uniform sampler2D source; //texunit:0 uniform sampler2D source; //texunit:0
#endif #endif
#ifdef USE_MULTIPLIER #ifdef USE_MULTIPLIER
uniform float multiplier; uniform float multiplier;
#endif #endif
@ -83,8 +80,7 @@ vec4 texturePanorama(vec3 normal,sampler2D pano ) {
vec2 st = vec2( vec2 st = vec2(
atan(normal.x, normal.z), atan(normal.x, normal.z),
acos(normal.y) acos(normal.y));
);
if (st.x < 0.0) if (st.x < 0.0)
st.x += M_PI * 2.0; st.x += M_PI * 2.0;
@ -92,18 +88,15 @@ vec4 texturePanorama(vec3 normal,sampler2D pano ) {
st /= vec2(M_PI * 2.0, M_PI); st /= vec2(M_PI * 2.0, M_PI);
return textureLod(pano, st, 0.0); return textureLod(pano, st, 0.0);
} }
#endif #endif
uniform float stuff; uniform float stuff;
uniform vec2 pixel_size; uniform vec2 pixel_size;
in vec2 uv2_interp; in vec2 uv2_interp;
#ifdef USE_BCS #ifdef USE_BCS
uniform vec3 bcs; uniform vec3 bcs;
@ -118,9 +111,6 @@ uniform sampler2D color_correction; //texunit:1
layout(location = 0) out vec4 frag_color; layout(location = 0) out vec4 frag_color;
void main() { void main() {
//vec4 color = color_interp; //vec4 color = color_interp;
@ -151,8 +141,6 @@ void main() {
vec4 color = textureLod(source, uv_interp, 0.0); vec4 color = textureLod(source, uv_interp, 0.0);
#endif #endif
#ifdef LINEAR_TO_SRGB #ifdef LINEAR_TO_SRGB
//regular Linear -> SRGB conversion //regular Linear -> SRGB conversion
vec3 a = vec3(0.055); vec3 a = vec3(0.055);
@ -173,7 +161,6 @@ void main() {
color.a = 1.0; color.a = 1.0;
#endif #endif
#ifdef GAUSSIAN_HORIZONTAL #ifdef GAUSSIAN_HORIZONTAL
color *= 0.38774; color *= 0.38774;
color += texture(source, uv_interp + vec2(1.0, 0.0) * pixel_size) * 0.24477; color += texture(source, uv_interp + vec2(1.0, 0.0) * pixel_size) * 0.24477;
@ -210,4 +197,3 @@ void main() {
#endif #endif
frag_color = color; frag_color = color;
} }

View file

@ -1,6 +1,5 @@
[vertex] [vertex]
layout(location = 0) in highp vec4 vertex_attrib; layout(location = 0) in highp vec4 vertex_attrib;
layout(location = 4) in vec2 uv_in; layout(location = 4) in vec2 uv_in;
@ -14,7 +13,6 @@ void main() {
[fragment] [fragment]
uniform highp samplerCube source_cube; //texunit:0 uniform highp samplerCube source_cube; //texunit:0
in vec2 uv_interp; in vec2 uv_interp;
@ -39,11 +37,11 @@ void main() {
normal.z = 0.5 - 0.5 * ((normal.x * normal.x) + (normal.y * normal.y)); normal.z = 0.5 - 0.5 * ((normal.x * normal.x) + (normal.y * normal.y));
normal = normalize(normal); normal = normalize(normal);
/* /*
normal.z = 0.5; normal.z = 0.5;
normal = normalize(normal); normal = normalize(normal);
*/ */
if (!z_flip) { if (!z_flip) {
normal.z = -normal.z; normal.z = -normal.z;
} }
@ -71,9 +69,7 @@ void main() {
float depth_fix = 1.0 / dot(normal, unorm); float depth_fix = 1.0 / dot(normal, unorm);
depth = 2.0 * depth - 1.0; depth = 2.0 * depth - 1.0;
float linear_depth = 2.0 * z_near * z_far / (z_far + z_near - depth * (z_far - z_near)); float linear_depth = 2.0 * z_near * z_far / (z_far + z_near - depth * (z_far - z_near));
gl_FragDepth = (linear_depth * depth_fix + bias) / z_far; gl_FragDepth = (linear_depth * depth_fix + bias) / z_far;
} }

View file

@ -1,6 +1,5 @@
[vertex] [vertex]
layout(location = 0) in highp vec2 vertex; layout(location = 0) in highp vec2 vertex;
layout(location = 4) in highp vec2 uv; layout(location = 4) in highp vec2 uv;
@ -15,7 +14,6 @@ void main() {
[fragment] [fragment]
precision highp float; precision highp float;
precision highp int; precision highp int;
@ -36,15 +34,11 @@ uniform int face_id;
uniform float roughness; uniform float roughness;
in highp vec2 uv_interp; in highp vec2 uv_interp;
layout(location = 0) out vec4 frag_color; layout(location = 0) out vec4 frag_color;
#define M_PI 3.14159265359 #define M_PI 3.14159265359
vec3 texelCoordToVec(vec2 uv, int faceID) {
vec3 texelCoordToVec(vec2 uv, int faceID)
{
mat3 faceUvVectors[6]; mat3 faceUvVectors[6];
/* /*
// -x // -x
@ -113,8 +107,7 @@ vec3 texelCoordToVec(vec2 uv, int faceID)
return normalize(result); return normalize(result);
} }
vec3 ImportanceSampleGGX(vec2 Xi, float Roughness, vec3 N) vec3 ImportanceSampleGGX(vec2 Xi, float Roughness, vec3 N) {
{
float a = Roughness * Roughness; // DISNEY'S ROUGHNESS [see Burley'12 siggraph] float a = Roughness * Roughness; // DISNEY'S ROUGHNESS [see Burley'12 siggraph]
// Compute distribution direction // Compute distribution direction
@ -137,15 +130,13 @@ vec3 ImportanceSampleGGX(vec2 Xi, float Roughness, vec3 N)
} }
// http://graphicrants.blogspot.com.au/2013/08/specular-brdf-reference.html // http://graphicrants.blogspot.com.au/2013/08/specular-brdf-reference.html
float GGX(float NdotV, float a) float GGX(float NdotV, float a) {
{
float k = a / 2.0; float k = a / 2.0;
return NdotV / (NdotV * (1.0 - k) + k); return NdotV / (NdotV * (1.0 - k) + k);
} }
// http://graphicrants.blogspot.com.au/2013/08/specular-brdf-reference.html // http://graphicrants.blogspot.com.au/2013/08/specular-brdf-reference.html
float G_Smith(float a, float nDotV, float nDotL) float G_Smith(float a, float nDotV, float nDotL) {
{
return GGX(nDotL, a * a) * GGX(nDotV, a * a); return GGX(nDotL, a * a) * GGX(nDotV, a * a);
} }
@ -162,8 +153,6 @@ vec2 Hammersley(uint i, uint N) {
return vec2(float(i) / float(N), radicalInverse_VdC(i)); return vec2(float(i) / float(N), radicalInverse_VdC(i));
} }
#ifdef LOW_QUALITY #ifdef LOW_QUALITY
#define SAMPLE_COUNT 64u #define SAMPLE_COUNT 64u
@ -182,8 +171,7 @@ vec4 texturePanorama(vec3 normal,sampler2D pano ) {
vec2 st = vec2( vec2 st = vec2(
atan(normal.x, normal.z), atan(normal.x, normal.z),
acos(normal.y) acos(normal.y));
);
if (st.x < 0.0) if (st.x < 0.0)
st.x += M_PI * 2.0; st.x += M_PI * 2.0;
@ -191,14 +179,12 @@ vec4 texturePanorama(vec3 normal,sampler2D pano ) {
st /= vec2(M_PI * 2.0, M_PI); st /= vec2(M_PI * 2.0, M_PI);
return textureLod(pano, st, 0.0); return textureLod(pano, st, 0.0);
} }
#endif #endif
#ifdef USE_SOURCE_DUAL_PARABOLOID_ARRAY #ifdef USE_SOURCE_DUAL_PARABOLOID_ARRAY
vec4 textureDualParaboloidArray(vec3 normal) { vec4 textureDualParaboloidArray(vec3 normal) {
vec3 norm = normalize(normal); vec3 norm = normalize(normal);
@ -208,7 +194,6 @@ vec4 textureDualParaboloidArray(vec3 normal) {
norm.y = 0.5 - norm.y + 0.5; norm.y = 0.5 - norm.y + 0.5;
} }
return textureLod(source_dual_paraboloid_array, vec3(norm.xy, float(source_array_index)), 0.0); return textureLod(source_dual_paraboloid_array, vec3(norm.xy, float(source_array_index)), 0.0);
} }
#endif #endif
@ -226,7 +211,6 @@ void main() {
N.z = -N.z; N.z = -N.z;
} }
#else #else
vec2 uv = (uv_interp * 2.0) - 1.0; vec2 uv = (uv_interp * 2.0) - 1.0;
vec3 N = texelCoordToVec(uv, face_id); vec3 N = texelCoordToVec(uv, face_id);
@ -251,9 +235,6 @@ void main() {
frag_color = vec4(texture(N, source_cube).rgb, 1.0); frag_color = vec4(texture(N, source_cube).rgb, 1.0);
#endif #endif
#else #else
vec4 sum = vec4(0.0, 0.0, 0.0, 0.0); vec4 sum = vec4(0.0, 0.0, 0.0, 0.0);
@ -289,6 +270,4 @@ void main() {
frag_color = vec4(sum.rgb, 1.0); frag_color = vec4(sum.rgb, 1.0);
#endif #endif
} }

View file

@ -1,6 +1,5 @@
[vertex] [vertex]
layout(location = 0) in highp vec4 vertex_attrib; layout(location = 0) in highp vec4 vertex_attrib;
layout(location = 4) in vec2 uv_in; layout(location = 4) in vec2 uv_in;
@ -39,7 +38,6 @@ uniform sampler2D source_ssao; //texunit:1
uniform float lod; uniform float lod;
uniform vec2 pixel_size; uniform vec2 pixel_size;
layout(location = 0) out vec4 frag_color; layout(location = 0) out vec4 frag_color;
#ifdef SSAO_MERGE #ifdef SSAO_MERGE
@ -88,7 +86,6 @@ uniform sampler2D source_dof_original; //texunit:2
#endif #endif
#ifdef GLOW_FIRST_PASS #ifdef GLOW_FIRST_PASS
uniform float exposure; uniform float exposure;
@ -112,8 +109,6 @@ uniform float camera_z_near;
void main() { void main() {
#ifdef GAUSSIAN_HORIZONTAL #ifdef GAUSSIAN_HORIZONTAL
vec2 pix_size = pixel_size; vec2 pix_size = pixel_size;
pix_size *= 0.5; //reading from larger buffer, so use more samples pix_size *= 0.5; //reading from larger buffer, so use more samples
@ -198,8 +193,6 @@ void main() {
k_accum += tap_k * tap_amount; k_accum += tap_k * tap_amount;
color_accum += tap_color * tap_amount; color_accum += tap_color * tap_amount;
} }
if (k_accum > 0.0) { if (k_accum > 0.0) {
@ -245,12 +238,10 @@ void main() {
max_accum = max(max_accum, tap_amount * ofs_influence); max_accum = max(max_accum, tap_amount * ofs_influence);
color_accum += tap_color * tap_k; color_accum += tap_color * tap_k;
} }
color_accum.a = max(color_accum.a, sqrt(max_accum)); color_accum.a = max(color_accum.a, sqrt(max_accum));
#ifdef DOF_NEAR_BLUR_MERGE #ifdef DOF_NEAR_BLUR_MERGE
vec4 original = textureLod(source_dof_original, uv_interp, 0.0); vec4 original = textureLod(source_dof_original, uv_interp, 0.0);
@ -265,8 +256,6 @@ void main() {
#endif #endif
#ifdef GLOW_FIRST_PASS #ifdef GLOW_FIRST_PASS
#ifdef GLOW_USE_AUTO_EXPOSURE #ifdef GLOW_USE_AUTO_EXPOSURE
@ -282,7 +271,6 @@ void main() {
#endif #endif
#ifdef SIMPLE_COPY #ifdef SIMPLE_COPY
vec4 color = textureLod(source_color, uv_interp, 0.0); vec4 color = textureLod(source_color, uv_interp, 0.0);
frag_color = color; frag_color = color;
@ -296,6 +284,4 @@ void main() {
frag_color = vec4(mix(color.rgb, color.rgb * mix(ssao_color.rgb, vec3(1.0), ssao), color.a), 1.0); frag_color = vec4(mix(color.rgb, color.rgb * mix(ssao_color.rgb, vec3(1.0), ssao), color.a), 1.0);
#endif #endif
} }

View file

@ -1,18 +1,14 @@
[vertex] [vertex]
layout(location = 0) in highp vec4 vertex_attrib; layout(location = 0) in highp vec4 vertex_attrib;
void main() { void main() {
gl_Position = vertex_attrib; gl_Position = vertex_attrib;
} }
[fragment] [fragment]
uniform highp sampler2D source_exposure; //texunit:0 uniform highp sampler2D source_exposure; //texunit:0
#ifdef EXPOSURE_BEGIN #ifdef EXPOSURE_BEGIN
@ -33,15 +29,10 @@ uniform highp float max_luminance;
layout(location = 0) out highp float exposure; layout(location = 0) out highp float exposure;
void main() { void main() {
#ifdef EXPOSURE_BEGIN #ifdef EXPOSURE_BEGIN
ivec2 src_pos = ivec2(gl_FragCoord.xy) * source_render_size / target_size; ivec2 src_pos = ivec2(gl_FragCoord.xy) * source_render_size / target_size;
#if 1 #if 1
@ -87,12 +78,7 @@ void main() {
#endif //EXPOSURE_FORCE_SET #endif //EXPOSURE_FORCE_SET
#endif //EXPOSURE_END #endif //EXPOSURE_END
#endif //EXPOSURE_BEGIN #endif //EXPOSURE_BEGIN
} }

View file

@ -1,7 +1,5 @@
[vertex] [vertex]
layout(location = 0) in highp vec4 color; layout(location = 0) in highp vec4 color;
layout(location = 1) in highp vec4 velocity_active; layout(location = 1) in highp vec4 velocity_active;
layout(location = 2) in highp vec4 custom; layout(location = 2) in highp vec4 custom;
@ -9,7 +7,6 @@ layout(location=3) in highp vec4 xform_1;
layout(location = 4) in highp vec4 xform_2; layout(location = 4) in highp vec4 xform_2;
layout(location = 5) in highp vec4 xform_3; layout(location = 5) in highp vec4 xform_3;
struct Attractor { struct Attractor {
vec3 pos; vec3 pos;
@ -39,7 +36,6 @@ uniform float lifetime;
uniform mat4 emission_transform; uniform mat4 emission_transform;
uniform uint random_seed; uniform uint random_seed;
out highp vec4 out_color; //tfb: out highp vec4 out_color; //tfb:
out highp vec4 out_velocity_active; //tfb: out highp vec4 out_velocity_active; //tfb:
out highp vec4 out_custom; //tfb: out highp vec4 out_custom; //tfb:
@ -47,7 +43,6 @@ out highp vec4 out_xform_1; //tfb:
out highp vec4 out_xform_2; //tfb: out highp vec4 out_xform_2; //tfb:
out highp vec4 out_xform_3; //tfb: out highp vec4 out_xform_3; //tfb:
#if defined(USE_MATERIAL) #if defined(USE_MATERIAL)
layout(std140) uniform UniformData { //ubo:0 layout(std140) uniform UniformData { //ubo:0
@ -58,7 +53,6 @@ MATERIAL_UNIFORMS
#endif #endif
VERTEX_SHADER_GLOBALS VERTEX_SHADER_GLOBALS
uint hash(uint x) { uint hash(uint x) {
@ -69,7 +63,6 @@ uint hash(uint x) {
return x; return x;
} }
void main() { void main() {
#ifdef PARTICLES_COPY #ifdef PARTICLES_COPY
@ -160,8 +153,7 @@ void main() {
vec4(1.0, 0.0, 0.0, 0.0), vec4(1.0, 0.0, 0.0, 0.0),
vec4(0.0, 1.0, 0.0, 0.0), vec4(0.0, 1.0, 0.0, 0.0),
vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0),
vec4(0.0,0.0,0.0,1.0) vec4(0.0, 0.0, 0.0, 1.0));
);
} else { } else {
out_color = color; out_color = color;
out_velocity_active = velocity_active; out_velocity_active = velocity_active;
@ -200,7 +192,6 @@ VERTEX_SHADER_CODE
force += attractors[i].strength * rel_vec * attenuation * mass; force += attractors[i].strength * rel_vec * attenuation * mass;
} else { } else {
force += attractors[i].strength * attractors[i].dir * attenuation * mass; force += attractors[i].strength * attractors[i].dir * attenuation * mass;
} }
} }
@ -228,14 +219,12 @@ VERTEX_SHADER_CODE
out_xform_3 = xform[2]; out_xform_3 = xform[2];
#endif //PARTICLES_COPY #endif //PARTICLES_COPY
} }
[fragment] [fragment]
// any code here is never executed, stuff is filled just so it works // any code here is never executed, stuff is filled just so it works
#if defined(USE_MATERIAL) #if defined(USE_MATERIAL)
layout(std140) uniform UniformData { layout(std140) uniform UniformData {

View file

@ -1,12 +1,10 @@
[vertex] [vertex]
layout(location = 0) in highp vec4 vertex_attrib; layout(location = 0) in highp vec4 vertex_attrib;
layout(location = 4) in vec2 uv_in; layout(location = 4) in vec2 uv_in;
out vec2 uv_interp; out vec2 uv_interp;
void main() { void main() {
uv_interp = uv_in; uv_interp = uv_in;
@ -34,11 +32,9 @@ void main() {
vec4 specular = texture(source_specular, uv_interp); vec4 specular = texture(source_specular, uv_interp);
#ifdef USE_SSR #ifdef USE_SSR
vec4 ssr = textureLod(source_ssr, uv_interp, 0.0); vec4 ssr = textureLod(source_ssr, uv_interp, 0.0);
specular.rgb = mix(specular.rgb, ssr.rgb * specular.a, ssr.a); specular.rgb = mix(specular.rgb, ssr.rgb * specular.a, ssr.a);
#endif #endif
frag_color = vec4(specular.rgb, 1.0); frag_color = vec4(specular.rgb, 1.0);
} }

View file

@ -18,7 +18,6 @@ ARRAY_INDEX=8,
// hack to use uv if no uv present so it works with lightmap // hack to use uv if no uv present so it works with lightmap
/* INPUT ATTRIBS */ /* INPUT ATTRIBS */
layout(location = 0) in highp vec4 vertex_attrib; layout(location = 0) in highp vec4 vertex_attrib;
@ -102,12 +101,10 @@ layout(std140) uniform SceneData { //ubo:0
highp float fog_height_min; highp float fog_height_min;
highp float fog_height_max; highp float fog_height_max;
highp float fog_height_curve; highp float fog_height_curve;
}; };
uniform highp mat4 world_transform; uniform highp mat4 world_transform;
#ifdef USE_LIGHT_DIRECTIONAL #ifdef USE_LIGHT_DIRECTIONAL
layout(std140) uniform DirectionalLightData { //ubo:3 layout(std140) uniform DirectionalLightData { //ubo:3
@ -139,10 +136,8 @@ struct LightData {
mediump vec4 light_clamp; mediump vec4 light_clamp;
mediump vec4 shadow_color_contact; mediump vec4 shadow_color_contact;
highp mat4 shadow_matrix; highp mat4 shadow_matrix;
}; };
layout(std140) uniform OmniLightData { //ubo:4 layout(std140) uniform OmniLightData { //ubo:4
LightData omni_lights[MAX_LIGHT_DATA_STRUCTS]; LightData omni_lights[MAX_LIGHT_DATA_STRUCTS];
@ -155,7 +150,6 @@ layout(std140) uniform SpotLightData { //ubo:5
#ifdef USE_FORWARD_LIGHTING #ifdef USE_FORWARD_LIGHTING
uniform int omni_light_indices[MAX_FORWARD_LIGHTS]; uniform int omni_light_indices[MAX_FORWARD_LIGHTS];
uniform int omni_light_count; uniform int omni_light_count;
@ -178,7 +172,6 @@ void light_compute(vec3 N, vec3 L,vec3 V, vec3 light_color, float roughness, ino
float dotNH = max(dot(N, H), 0.0); float dotNH = max(dot(N, H), 0.0);
float intensity = (roughness >= 1.0 ? 1.0 : pow(dotNH, (1.0 - roughness) * 256.0)); float intensity = (roughness >= 1.0 ? 1.0 : pow(dotNH, (1.0 - roughness) * 256.0));
specular += light_color * intensity; specular += light_color * intensity;
} }
} }
@ -190,7 +183,6 @@ void light_process_omni(int idx, vec3 vertex, vec3 eye_vec,vec3 normal, float ro
vec3 light_attenuation = vec3(pow(max(1.0 - normalized_distance, 0.0), omni_lights[idx].light_direction_attenuation.w)); vec3 light_attenuation = vec3(pow(max(1.0 - normalized_distance, 0.0), omni_lights[idx].light_direction_attenuation.w));
light_compute(normal, normalize(light_rel_vec), eye_vec, omni_lights[idx].light_color_energy.rgb * light_attenuation, roughness, diffuse, specular); light_compute(normal, normalize(light_rel_vec), eye_vec, omni_lights[idx].light_color_energy.rgb * light_attenuation, roughness, diffuse, specular);
} }
void light_process_spot(int idx, vec3 vertex, vec3 eye_vec, vec3 normal, float roughness, inout vec3 diffuse, inout vec3 specular) { void light_process_spot(int idx, vec3 vertex, vec3 eye_vec, vec3 normal, float roughness, inout vec3 diffuse, inout vec3 specular) {
@ -205,11 +197,9 @@ void light_process_spot(int idx, vec3 vertex, vec3 eye_vec, vec3 normal, float r
float spot_rim = (1.0 - scos) / (1.0 - spot_cutoff); float spot_rim = (1.0 - scos) / (1.0 - spot_cutoff);
light_attenuation *= 1.0 - pow(max(spot_rim, 0.001), spot_lights[idx].light_params.x); light_attenuation *= 1.0 - pow(max(spot_rim, 0.001), spot_lights[idx].light_params.x);
light_compute(normal, normalize(light_rel_vec), eye_vec, spot_lights[idx].light_color_energy.rgb * light_attenuation, roughness, diffuse, specular); light_compute(normal, normalize(light_rel_vec), eye_vec, spot_lights[idx].light_color_energy.rgb * light_attenuation, roughness, diffuse, specular);
} }
#endif #endif
/* Varyings */ /* Varyings */
@ -229,13 +219,11 @@ out vec2 uv_interp;
out vec2 uv2_interp; out vec2 uv2_interp;
#endif #endif
#if defined(ENABLE_TANGENT_INTERP) || defined(ENABLE_NORMALMAP) || defined(LIGHT_USE_ANISOTROPY) #if defined(ENABLE_TANGENT_INTERP) || defined(ENABLE_NORMALMAP) || defined(LIGHT_USE_ANISOTROPY)
out vec3 tangent_interp; out vec3 tangent_interp;
out vec3 binormal_interp; out vec3 binormal_interp;
#endif #endif
#if defined(USE_MATERIAL) #if defined(USE_MATERIAL)
layout(std140) uniform UniformData { // ubo:1 layout(std140) uniform UniformData { // ubo:1
@ -272,7 +260,6 @@ void main() {
mat4 world_matrix = world_transform; mat4 world_matrix = world_transform;
#ifdef USE_INSTANCING #ifdef USE_INSTANCING
{ {
@ -283,7 +270,6 @@ void main() {
vec3 normal = normal_attrib * normal_mult; vec3 normal = normal_attrib * normal_mult;
#if defined(ENABLE_TANGENT_INTERP) || defined(ENABLE_NORMALMAP) || defined(LIGHT_USE_ANISOTROPY) #if defined(ENABLE_TANGENT_INTERP) || defined(ENABLE_NORMALMAP) || defined(LIGHT_USE_ANISOTROPY)
vec3 tangent = tangent_attrib.xyz; vec3 tangent = tangent_attrib.xyz;
tangent *= normal_mult; tangent *= normal_mult;
@ -298,7 +284,6 @@ void main() {
#endif #endif
#if defined(ENABLE_TANGENT_INTERP) || defined(ENABLE_NORMALMAP) || defined(LIGHT_USE_ANISOTROPY) #if defined(ENABLE_TANGENT_INTERP) || defined(ENABLE_NORMALMAP) || defined(LIGHT_USE_ANISOTROPY)
vec3 binormal = normalize(cross(normal, tangent) * binormalf); vec3 binormal = normalize(cross(normal, tangent) * binormalf);
@ -345,43 +330,42 @@ void main() {
#define projection_matrix local_projection #define projection_matrix local_projection
#define world_transform world_matrix #define world_transform world_matrix
#ifdef USE_SKELETON #ifdef USE_SKELETON
{ {
//skeleton transform //skeleton transform
ivec4 bone_indicesi = ivec4(bone_indices); // cast to signed int ivec4 bone_indicesi = ivec4(bone_indices); // cast to signed int
ivec2 tex_ofs = ivec2(bone_indicesi.x % 256, (bone_indicesi.x / 256) * 3); ivec2 tex_ofs = ivec2(bone_indicesi.x % 256, (bone_indicesi.x / 256) * 3);
highp mat3x4 m = mat3x4( highp mat3x4 m;
m = mat3x4(
texelFetch(skeleton_texture, tex_ofs, 0), texelFetch(skeleton_texture, tex_ofs, 0),
texelFetch(skeleton_texture, tex_ofs + ivec2(0, 1), 0), texelFetch(skeleton_texture, tex_ofs + ivec2(0, 1), 0),
texelFetch(skeleton_texture,tex_ofs+ivec2(0,2),0) texelFetch(skeleton_texture, tex_ofs + ivec2(0, 2), 0))
) * bone_weights.x; * bone_weights.x;
tex_ofs = ivec2(bone_indicesi.y % 256, (bone_indicesi.y / 256) * 3); tex_ofs = ivec2(bone_indicesi.y % 256, (bone_indicesi.y / 256) * 3);
m += mat3x4( m += mat3x4(
texelFetch(skeleton_texture, tex_ofs, 0), texelFetch(skeleton_texture, tex_ofs, 0),
texelFetch(skeleton_texture, tex_ofs + ivec2(0, 1), 0), texelFetch(skeleton_texture, tex_ofs + ivec2(0, 1), 0),
texelFetch(skeleton_texture,tex_ofs+ivec2(0,2),0) texelFetch(skeleton_texture, tex_ofs + ivec2(0, 2), 0))
) * bone_weights.y; * bone_weights.y;
tex_ofs = ivec2(bone_indicesi.z % 256, (bone_indicesi.z / 256) * 3); tex_ofs = ivec2(bone_indicesi.z % 256, (bone_indicesi.z / 256) * 3);
m += mat3x4( m += mat3x4(
texelFetch(skeleton_texture, tex_ofs, 0), texelFetch(skeleton_texture, tex_ofs, 0),
texelFetch(skeleton_texture, tex_ofs + ivec2(0, 1), 0), texelFetch(skeleton_texture, tex_ofs + ivec2(0, 1), 0),
texelFetch(skeleton_texture,tex_ofs+ivec2(0,2),0) texelFetch(skeleton_texture, tex_ofs + ivec2(0, 2), 0))
) * bone_weights.z; * bone_weights.z;
tex_ofs = ivec2(bone_indicesi.w % 256, (bone_indicesi.w / 256) * 3); tex_ofs = ivec2(bone_indicesi.w % 256, (bone_indicesi.w / 256) * 3);
m += mat3x4( m += mat3x4(
texelFetch(skeleton_texture, tex_ofs, 0), texelFetch(skeleton_texture, tex_ofs, 0),
texelFetch(skeleton_texture, tex_ofs + ivec2(0, 1), 0), texelFetch(skeleton_texture, tex_ofs + ivec2(0, 1), 0),
texelFetch(skeleton_texture,tex_ofs+ivec2(0,2),0) texelFetch(skeleton_texture, tex_ofs + ivec2(0, 2), 0))
) * bone_weights.w; * bone_weights.w;
mat4 bone_matrix = transpose(mat4(m[0], m[1], m[2], vec4(0.0, 0.0, 0.0, 1.0))); mat4 bone_matrix = transpose(mat4(m[0], m[1], m[2], vec4(0.0, 0.0, 0.0, 1.0)));
@ -396,8 +380,6 @@ VERTEX_SHADER_CODE
} }
// using local coordinates (default) // using local coordinates (default)
#if !defined(SKIP_TRANSFORM_USED) && !defined(VERTEX_WORLD_COORDS_USED) #if !defined(SKIP_TRANSFORM_USED) && !defined(VERTEX_WORLD_COORDS_USED)
@ -433,16 +415,13 @@ VERTEX_SHADER_CODE
vertex_interp = vertex.xyz; vertex_interp = vertex.xyz;
normal_interp = normal; normal_interp = normal;
#if defined(ENABLE_TANGENT_INTERP) || defined(ENABLE_NORMALMAP) || defined(LIGHT_USE_ANISOTROPY) #if defined(ENABLE_TANGENT_INTERP) || defined(ENABLE_NORMALMAP) || defined(LIGHT_USE_ANISOTROPY)
tangent_interp = tangent; tangent_interp = tangent;
binormal_interp = binormal; binormal_interp = binormal;
#endif #endif
#ifdef RENDER_DEPTH #ifdef RENDER_DEPTH
#ifdef RENDER_DEPTH_DUAL_PARABOLOID #ifdef RENDER_DEPTH_DUAL_PARABOLOID
vertex_interp.z *= shadow_dual_paraboloid_render_side; vertex_interp.z *= shadow_dual_paraboloid_render_side;
@ -461,7 +440,6 @@ VERTEX_SHADER_CODE
vertex_interp = vtx; vertex_interp = vtx;
#else #else
float z_ofs = z_offset; float z_ofs = z_offset;
@ -520,12 +498,9 @@ VERTEX_SHADER_CODE
#endif //USE_LIGHT_DIRECTIONAL #endif //USE_LIGHT_DIRECTIONAL
#endif // USE_VERTEX_LIGHTING #endif // USE_VERTEX_LIGHTING
} }
[fragment] [fragment]
/* texture unit usage, N is max_texture_unity-N /* texture unit usage, N is max_texture_unity-N
@ -569,13 +544,10 @@ in vec3 binormal_interp;
in highp vec3 vertex_interp; in highp vec3 vertex_interp;
in vec3 normal_interp; in vec3 normal_interp;
/* PBR CHANNELS */ /* PBR CHANNELS */
#ifdef USE_RADIANCE_MAP #ifdef USE_RADIANCE_MAP
layout(std140) uniform Radiance { // ubo:2 layout(std140) uniform Radiance { // ubo:2
mat4 radiance_inverse_xform; mat4 radiance_inverse_xform;
@ -634,8 +606,6 @@ vec3 textureDualParaboloid(sampler2D p_tex, vec3 p_vec,float p_roughness) {
/* Material Uniforms */ /* Material Uniforms */
#if defined(USE_MATERIAL) #if defined(USE_MATERIAL)
layout(std140) uniform UniformData { layout(std140) uniform UniformData {
@ -712,7 +682,6 @@ layout(std140) uniform DirectionalLightData {
mediump vec4 shadow_split_offsets; mediump vec4 shadow_split_offsets;
}; };
uniform highp sampler2DShadow directional_shadow; // texunit:-4 uniform highp sampler2DShadow directional_shadow; // texunit:-4
#endif #endif
@ -735,7 +704,6 @@ struct LightData {
}; };
layout(std140) uniform OmniLightData { // ubo:4 layout(std140) uniform OmniLightData { // ubo:4
LightData omni_lights[MAX_LIGHT_DATA_STRUCTS]; LightData omni_lights[MAX_LIGHT_DATA_STRUCTS];
@ -746,10 +714,8 @@ layout(std140) uniform SpotLightData { //ubo:5
LightData spot_lights[MAX_LIGHT_DATA_STRUCTS]; LightData spot_lights[MAX_LIGHT_DATA_STRUCTS];
}; };
uniform highp sampler2DShadow shadow_atlas; // texunit:-5 uniform highp sampler2DShadow shadow_atlas; // texunit:-5
struct ReflectionData { struct ReflectionData {
mediump vec4 box_extents; mediump vec4 box_extents;
@ -767,7 +733,6 @@ layout(std140) uniform ReflectionProbeData { //ubo:6
}; };
uniform mediump sampler2D reflection_atlas; // texunit:-3 uniform mediump sampler2D reflection_atlas; // texunit:-3
#ifdef USE_FORWARD_LIGHTING #ifdef USE_FORWARD_LIGHTING
uniform int omni_light_indices[MAX_FORWARD_LIGHTS]; uniform int omni_light_indices[MAX_FORWARD_LIGHTS];
@ -781,7 +746,6 @@ uniform int reflection_count;
#endif #endif
#if defined(SCREEN_TEXTURE_USED) #if defined(SCREEN_TEXTURE_USED)
uniform highp sampler2D screen_texture; // texunit:-7 uniform highp sampler2D screen_texture; // texunit:-7
@ -825,22 +789,20 @@ float contact_shadow_compute(vec3 pos, vec3 dir, float max_distance) {
if (length(screen_rel) < 0.00001) if (length(screen_rel) < 0.00001)
return 1.0; // too small, don't do anything return 1.0; // too small, don't do anything
/*float pixel_size; //approximate pixel size /*
float pixel_size; // approximate pixel size
if (screen_rel.x > screen_rel.y) { if (screen_rel.x > screen_rel.y) {
pixel_size = abs((pos.x - endpoint.x) / (screen_rel.x / screen_pixel_size.x)); pixel_size = abs((pos.x - endpoint.x) / (screen_rel.x / screen_pixel_size.x));
} else { } else {
pixel_size = abs((pos.y - endpoint.y) / (screen_rel.y / screen_pixel_size.y)); pixel_size = abs((pos.y - endpoint.y) / (screen_rel.y / screen_pixel_size.y));
}
}*/ */
vec4 bias = projection_matrix * vec4(pos+vec3(0.0,0.0,max_distance*0.5), 1.0); //todo un-harcode the 0.04 vec4 bias = projection_matrix * vec4(pos + vec3(0.0, 0.0, max_distance * 0.5), 1.0);
vec2 pixel_incr = normalize(screen_rel) * screen_pixel_size; vec2 pixel_incr = normalize(screen_rel) * screen_pixel_size;
float steps = length(screen_rel) / length(pixel_incr); float steps = length(screen_rel) / length(pixel_incr);
steps = min(2000.0, steps); // put a limit to avoid freezing in some strange situation steps = min(2000.0, steps); // put a limit to avoid freezing in some strange situation
//steps = 10.0; //steps = 10.0;
@ -864,7 +826,6 @@ float contact_shadow_compute(vec3 pos, vec3 dir, float max_distance) {
} }
} }
ratio += ratio_incr; ratio += ratio_incr;
steps -= 1.0; steps -= 1.0;
} }
@ -874,7 +835,6 @@ float contact_shadow_compute(vec3 pos, vec3 dir, float max_distance) {
#endif #endif
// This returns the G_GGX function divided by 2 cos_theta_m, where in practice cos_theta_m is either N.L or N.V. // This returns the G_GGX function divided by 2 cos_theta_m, where in practice cos_theta_m is either N.L or N.V.
// We're dividing this factor off because the overall term we'll end up looks like // We're dividing this factor off because the overall term we'll end up looks like
// (see, for example, the first unnumbered equation in B. Burley, "Physically Based Shading at Disney", SIGGRAPH 2012): // (see, for example, the first unnumbered equation in B. Burley, "Physically Based Shading at Disney", SIGGRAPH 2012):
@ -927,16 +887,13 @@ float D_GGX_anisotropic(float cos_theta_m, float alpha_x, float alpha_y, float c
return 1.0 / max(M_PI * alpha_x * alpha_y * d * d, 0.001); return 1.0 / max(M_PI * alpha_x * alpha_y * d * d, 0.001);
} }
float SchlickFresnel(float u) {
float SchlickFresnel(float u)
{
float m = 1.0 - u; float m = 1.0 - u;
float m2 = m * m; float m2 = m * m;
return m2 * m2 * m; // pow(m,5) return m2 * m2 * m; // pow(m,5)
} }
float GTR1(float NdotH, float a) float GTR1(float NdotH, float a) {
{
if (a >= 1.0) return 1.0 / M_PI; if (a >= 1.0) return 1.0 / M_PI;
float a2 = a * a; float a2 = a * a;
float t = 1.0 + (a2 - 1.0) * NdotH * NdotH; float t = 1.0 + (a2 - 1.0) * NdotH * NdotH;
@ -961,7 +918,6 @@ void light_compute(vec3 N, vec3 L, vec3 V, vec3 B, vec3 T, vec3 light_color, vec
LIGHT_SHADER_CODE LIGHT_SHADER_CODE
#else #else
float NdotL = dot(N, L); float NdotL = dot(N, L);
float cNdotL = max(NdotL, 0.0); // clamped NdotL float cNdotL = max(NdotL, 0.0); // clamped NdotL
@ -975,7 +931,6 @@ LIGHT_SHADER_CODE
float diffuse_brdf_NL; // BRDF times N.L for calculating diffuse radiance float diffuse_brdf_NL; // BRDF times N.L for calculating diffuse radiance
#endif #endif
#if defined(DIFFUSE_LAMBERT_WRAP) #if defined(DIFFUSE_LAMBERT_WRAP)
// energy conserving lambert wrap shader // energy conserving lambert wrap shader
diffuse_brdf_NL = max(0.0, (NdotL + roughness) / ((1.0 + roughness) * (1.0 + roughness))); diffuse_brdf_NL = max(0.0, (NdotL + roughness) / ((1.0 + roughness) * (1.0 + roughness)));
@ -986,7 +941,6 @@ LIGHT_SHADER_CODE
// see http://mimosa-pudica.net/improved-oren-nayar.html // see http://mimosa-pudica.net/improved-oren-nayar.html
float LdotV = dot(L, V); float LdotV = dot(L, V);
float s = LdotV - NdotL * NdotV; float s = LdotV - NdotL * NdotV;
float t = mix(1.0, max(NdotL, NdotV), step(0.0, s)); float t = mix(1.0, max(NdotL, NdotV), step(0.0, s));
@ -1005,7 +959,6 @@ LIGHT_SHADER_CODE
{ {
vec3 H = normalize(V + L); vec3 H = normalize(V + L);
float cLdotH = max(0.0, dot(L, H)); float cLdotH = max(0.0, dot(L, H));
@ -1021,7 +974,8 @@ LIGHT_SHADER_CODE
float lightScatter = f0 + (fd90 - f0) * pow(1.0 - cNdotL, 5.0); float lightScatter = f0 + (fd90 - f0) * pow(1.0 - cNdotL, 5.0);
float viewScatter = f0 + (fd90 - f0) * pow(1.0 - cNdotV, 5.0); float viewScatter = f0 + (fd90 - f0) * pow(1.0 - cNdotV, 5.0);
diffuse_brdf_NL = lightScatter * viewScatter * energyFactor;*/ diffuse_brdf_NL = lightScatter * viewScatter * energyFactor;
*/
} }
#else #else
// lambert // lambert
@ -1034,17 +988,14 @@ LIGHT_SHADER_CODE
diffuse_light += light_color * diffuse_color * (vec3(1.0 / M_PI) - diffuse_brdf_NL) * transmission * attenuation; diffuse_light += light_color * diffuse_color * (vec3(1.0 / M_PI) - diffuse_brdf_NL) * transmission * attenuation;
#endif #endif
#if defined(LIGHT_USE_RIM) #if defined(LIGHT_USE_RIM)
float rim_light = pow(max(0.0, 1.0 - cNdotV), max(0.0, (1.0 - roughness) * 16.0)); float rim_light = pow(max(0.0, 1.0 - cNdotV), max(0.0, (1.0 - roughness) * 16.0));
diffuse_light += rim_light * rim * mix(vec3(1.0), diffuse_color, rim_tint) * light_color; diffuse_light += rim_light * rim * mix(vec3(1.0), diffuse_color, rim_tint) * light_color;
#endif #endif
} }
if (roughness > 0.0) { // FIXME: roughness == 0 should not disable specular light entirely if (roughness > 0.0) { // FIXME: roughness == 0 should not disable specular light entirely
// D // D
#if defined(SPECULAR_BLINN) #if defined(SPECULAR_BLINN)
@ -1122,7 +1073,6 @@ LIGHT_SHADER_CODE
float Fr = mix(.04, 1.0, cLdotH5); float Fr = mix(.04, 1.0, cLdotH5);
float Gr = G_GGX_2cos(cNdotL, .25) * G_GGX_2cos(cNdotV, .25); float Gr = G_GGX_2cos(cNdotL, .25) * G_GGX_2cos(cNdotV, .25);
float specular_brdf_NL = 0.25 * clearcoat * Gr * Fr * Dr * cNdotL; float specular_brdf_NL = 0.25 * clearcoat * Gr * Fr * Dr * cNdotL;
specular_light += specular_brdf_NL * light_color * specular_blob_intensity * attenuation; specular_light += specular_brdf_NL * light_color * specular_blob_intensity * attenuation;
@ -1130,11 +1080,9 @@ LIGHT_SHADER_CODE
#endif #endif
} }
#endif //defined(USE_LIGHT_SHADER_CODE) #endif //defined(USE_LIGHT_SHADER_CODE)
} }
float sample_shadow(highp sampler2DShadow shadow, vec2 shadow_pixel_size, vec2 pos, float depth, vec4 clamp_rect) { float sample_shadow(highp sampler2DShadow shadow, vec2 shadow_pixel_size, vec2 pos, float depth, vec4 clamp_rect) {
#ifdef SHADOW_MODE_PCF_13 #ifdef SHADOW_MODE_PCF_13
@ -1168,7 +1116,6 @@ float sample_shadow(highp sampler2DShadow shadow, vec2 shadow_pixel_size, vec2 p
return textureProj(shadow, vec4(pos, depth, 1.0)); return textureProj(shadow, vec4(pos, depth, 1.0));
#endif #endif
} }
#ifdef RENDER_DEPTH_DUAL_PARABOLOID #ifdef RENDER_DEPTH_DUAL_PARABOLOID
@ -1177,11 +1124,8 @@ in highp float dp_clip;
#endif #endif
#if 0 #if 0
// need to save texture depth for this // need to save texture depth for this
vec3 light_transmittance(float translucency,vec3 light_vec, vec3 normal, vec3 pos, float distance) { vec3 light_transmittance(float translucency,vec3 light_vec, vec3 normal, vec3 pos, float distance) {
float scale = 8.25 * (1.0 - translucency) / subsurface_scatter_width; float scale = 8.25 * (1.0 - translucency) / subsurface_scatter_width;
@ -1193,7 +1137,8 @@ vec3 light_transmittance(float translucency,vec3 light_vec, vec3 normal, vec3 po
* (It can be precomputed into a texture, for maximum performance): * (It can be precomputed into a texture, for maximum performance):
*/ */
float dd = -d * d; float dd = -d * d;
vec3 profile = vec3(0.233, 0.455, 0.649) * exp(dd / 0.0064) + vec3 profile =
vec3(0.233, 0.455, 0.649) * exp(dd / 0.0064) +
vec3(0.1, 0.336, 0.344) * exp(dd / 0.0484) + vec3(0.1, 0.336, 0.344) * exp(dd / 0.0484) +
vec3(0.118, 0.198, 0.0) * exp(dd / 0.187) + vec3(0.118, 0.198, 0.0) * exp(dd / 0.187) +
vec3(0.113, 0.007, 0.007) * exp(dd / 0.567) + vec3(0.113, 0.007, 0.007) * exp(dd / 0.567) +
@ -1242,7 +1187,6 @@ void light_process_omni(int idx, vec3 vertex, vec3 eye_vec,vec3 normal,vec3 bino
clamp_rect.y += clamp_rect.w; clamp_rect.y += clamp_rect.w;
} }
*/ */
} }
splane.xy /= splane.z; splane.xy /= splane.z;
@ -1258,15 +1202,12 @@ void light_process_omni(int idx, vec3 vertex, vec3 eye_vec,vec3 normal,vec3 bino
float contact_shadow = contact_shadow_compute(vertex, normalize(light_rel_vec), min(light_length, omni_lights[idx].shadow_color_contact.a)); float contact_shadow = contact_shadow_compute(vertex, normalize(light_rel_vec), min(light_length, omni_lights[idx].shadow_color_contact.a));
shadow = min(shadow, contact_shadow); shadow = min(shadow, contact_shadow);
} }
#endif #endif
light_attenuation *= mix(omni_lights[idx].shadow_color_contact.rgb, vec3(1.0), shadow); light_attenuation *= mix(omni_lights[idx].shadow_color_contact.rgb, vec3(1.0), shadow);
} }
#endif //SHADOWS_DISABLED #endif //SHADOWS_DISABLED
light_compute(normal, normalize(light_rel_vec), eye_vec, binormal, tangent, omni_lights[idx].light_color_energy.rgb, light_attenuation, albedo, transmission, omni_lights[idx].light_params.z * p_blob_intensity, roughness, metallic, rim * omni_attenuation, rim_tint, clearcoat, clearcoat_gloss, anisotropy, diffuse_light, specular_light); light_compute(normal, normalize(light_rel_vec), eye_vec, binormal, tangent, omni_lights[idx].light_color_energy.rgb, light_attenuation, albedo, transmission, omni_lights[idx].light_params.z * p_blob_intensity, roughness, metallic, rim * omni_attenuation, rim_tint, clearcoat, clearcoat_gloss, anisotropy, diffuse_light, specular_light);
} }
void light_process_spot(int idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 binormal, vec3 tangent, vec3 albedo, vec3 transmission, float roughness, float metallic, float rim, float rim_tint, float clearcoat, float clearcoat_gloss, float anisotropy, float p_blob_intensity, inout vec3 diffuse_light, inout vec3 specular_light) { void light_process_spot(int idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 binormal, vec3 tangent, vec3 albedo, vec3 transmission, float roughness, float metallic, float rim, float rim_tint, float clearcoat, float clearcoat_gloss, float anisotropy, float p_blob_intensity, inout vec3 diffuse_light, inout vec3 specular_light) {
@ -1295,7 +1236,6 @@ void light_process_spot(int idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 bi
float contact_shadow = contact_shadow_compute(vertex, normalize(light_rel_vec), min(light_length, spot_lights[idx].shadow_color_contact.a)); float contact_shadow = contact_shadow_compute(vertex, normalize(light_rel_vec), min(light_length, spot_lights[idx].shadow_color_contact.a));
shadow = min(shadow, contact_shadow); shadow = min(shadow, contact_shadow);
} }
#endif #endif
light_attenuation *= mix(spot_lights[idx].shadow_color_contact.rgb, vec3(1.0), shadow); light_attenuation *= mix(spot_lights[idx].shadow_color_contact.rgb, vec3(1.0), shadow);
@ -1303,7 +1243,6 @@ void light_process_spot(int idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 bi
#endif //SHADOWS_DISABLED #endif //SHADOWS_DISABLED
light_compute(normal, normalize(light_rel_vec), eye_vec, binormal, tangent, spot_lights[idx].light_color_energy.rgb, light_attenuation, albedo, transmission, spot_lights[idx].light_params.z * p_blob_intensity, roughness, metallic, rim * spot_attenuation, rim_tint, clearcoat, clearcoat_gloss, anisotropy, diffuse_light, specular_light); light_compute(normal, normalize(light_rel_vec), eye_vec, binormal, tangent, spot_lights[idx].light_color_energy.rgb, light_attenuation, albedo, transmission, spot_lights[idx].light_params.z * p_blob_intensity, roughness, metallic, rim * spot_attenuation, rim_tint, clearcoat, clearcoat_gloss, anisotropy, diffuse_light, specular_light);
} }
void reflection_process(int idx, vec3 vertex, vec3 normal, vec3 binormal, vec3 tangent, float roughness, float anisotropy, vec3 ambient, vec3 skybox, inout highp vec4 reflection_accum, inout highp vec4 ambient_accum) { void reflection_process(int idx, vec3 vertex, vec3 normal, vec3 binormal, vec3 tangent, float roughness, float anisotropy, vec3 ambient, vec3 skybox, inout highp vec4 reflection_accum, inout highp vec4 ambient_accum) {
@ -1333,7 +1272,6 @@ void reflection_process(int idx, vec3 vertex, vec3 normal,vec3 binormal, vec3 ta
vec3 rbmax = (box_extents - local_pos) / nrdir; vec3 rbmax = (box_extents - local_pos) / nrdir;
vec3 rbmin = (-box_extents - local_pos) / nrdir; vec3 rbmin = (-box_extents - local_pos) / nrdir;
vec3 rbminmax = mix(rbmin, rbmax, greaterThan(nrdir, vec3(0.0, 0.0, 0.0))); vec3 rbminmax = mix(rbmin, rbmax, greaterThan(nrdir, vec3(0.0, 0.0, 0.0)));
float fa = min(min(rbminmax.x, rbminmax.y), rbminmax.z); float fa = min(min(rbminmax.x, rbminmax.y), rbminmax.z);
@ -1341,7 +1279,6 @@ void reflection_process(int idx, vec3 vertex, vec3 normal,vec3 binormal, vec3 ta
local_ref_vec = posonbox - reflections[idx].box_offset.xyz; local_ref_vec = posonbox - reflections[idx].box_offset.xyz;
} }
vec4 clamp_rect = reflections[idx].atlas_clamp; vec4 clamp_rect = reflections[idx].atlas_clamp;
vec3 norm = normalize(local_ref_vec); vec3 norm = normalize(local_ref_vec);
norm.xy /= 1.0 + abs(norm.z); norm.xy /= 1.0 + abs(norm.z);
@ -1368,7 +1305,6 @@ void reflection_process(int idx, vec3 vertex, vec3 normal,vec3 binormal, vec3 ta
#ifndef USE_LIGHTMAP #ifndef USE_LIGHTMAP
if (reflections[idx].ambient.a > 0.0) { //compute ambient using skybox if (reflections[idx].ambient.a > 0.0) { //compute ambient using skybox
vec3 local_amb_vec = (reflections[idx].local_matrix * vec4(normal, 0.0)).xyz; vec3 local_amb_vec = (reflections[idx].local_matrix * vec4(normal, 0.0)).xyz;
vec3 splane = normalize(local_amb_vec); vec3 splane = normalize(local_amb_vec);
@ -1409,7 +1345,6 @@ void reflection_process(int idx, vec3 vertex, vec3 normal,vec3 binormal, vec3 ta
} }
ambient_out.rgb *= ambient_out.a; ambient_out.rgb *= ambient_out.a;
ambient_accum += ambient_out; ambient_accum += ambient_out;
} }
#endif #endif
} }
@ -1470,8 +1405,6 @@ vec3 voxel_cone_trace(mediump sampler3D probe, vec3 cell_size, vec3 pos, vec3 am
void gi_probe_compute(mediump sampler3D probe, mat4 probe_xform, vec3 bounds, vec3 cell_size, vec3 pos, vec3 ambient, vec3 environment, bool blend_ambient, float multiplier, mat3 normal_mtx, vec3 ref_vec, float roughness, float p_bias, float p_normal_bias, inout vec4 out_spec, inout vec4 out_diff) { void gi_probe_compute(mediump sampler3D probe, mat4 probe_xform, vec3 bounds, vec3 cell_size, vec3 pos, vec3 ambient, vec3 environment, bool blend_ambient, float multiplier, mat3 normal_mtx, vec3 ref_vec, float roughness, float p_bias, float p_normal_bias, inout vec4 out_spec, inout vec4 out_diff) {
vec3 probe_pos = (probe_xform * vec4(pos, 1.0)).xyz; vec3 probe_pos = (probe_xform * vec4(pos, 1.0)).xyz;
vec3 ref_pos = (probe_xform * vec4(pos + ref_vec, 1.0)).xyz; vec3 ref_pos = (probe_xform * vec4(pos + ref_vec, 1.0)).xyz;
ref_vec = normalize(ref_pos - probe_pos); ref_vec = normalize(ref_pos - probe_pos);
@ -1505,8 +1438,7 @@ void gi_probe_compute(mediump sampler3D probe, mat4 probe_xform, vec3 bounds,vec
vec3(0.267617, 0.823639, 0.5), vec3(0.267617, 0.823639, 0.5),
vec3(-0.700629, 0.509037, 0.5), vec3(-0.700629, 0.509037, 0.5),
vec3(-0.700629, -0.509037, 0.5), vec3(-0.700629, -0.509037, 0.5),
vec3(0.267617, -0.823639, 0.5) vec3(0.267617, -0.823639, 0.5));
);
float cone_weights[MAX_CONE_DIRS] = float[](0.25, 0.15, 0.15, 0.15, 0.15, 0.15); float cone_weights[MAX_CONE_DIRS] = float[](0.25, 0.15, 0.15, 0.15, 0.15, 0.15);
float cone_angle_tan = 0.577; float cone_angle_tan = 0.577;
@ -1519,8 +1451,7 @@ void gi_probe_compute(mediump sampler3D probe, mat4 probe_xform, vec3 bounds,vec
vec3(0.707107, 0, 0.707107), vec3(0.707107, 0, 0.707107),
vec3(0, 0.707107, 0.707107), vec3(0, 0.707107, 0.707107),
vec3(-0.707107, 0, 0.707107), vec3(-0.707107, 0, 0.707107),
vec3(0, -0.707107, 0.707107) vec3(0, -0.707107, 0.707107));
);
float cone_weights[MAX_CONE_DIRS] = float[](0.25, 0.25, 0.25, 0.25); float cone_weights[MAX_CONE_DIRS] = float[](0.25, 0.25, 0.25, 0.25);
float cone_angle_tan = 0.98269; float cone_angle_tan = 0.98269;
@ -1533,7 +1464,6 @@ void gi_probe_compute(mediump sampler3D probe, mat4 probe_xform, vec3 bounds,vec
vec3 dir = normalize((probe_xform * vec4(pos + normal_mtx * cone_dirs[i], 1.0)).xyz - probe_pos); vec3 dir = normalize((probe_xform * vec4(pos + normal_mtx * cone_dirs[i], 1.0)).xyz - probe_pos);
light += cone_weights[i] * voxel_cone_trace(probe, cell_size, probe_pos, ambient, blend_ambient, dir, cone_angle_tan, max_distance, p_bias); light += cone_weights[i] * voxel_cone_trace(probe, cell_size, probe_pos, ambient, blend_ambient, dir, cone_angle_tan, max_distance, p_bias);
} }
light *= multiplier; light *= multiplier;
@ -1548,10 +1478,8 @@ void gi_probe_compute(mediump sampler3D probe, mat4 probe_xform, vec3 bounds,vec
//irr_light=vec3(0.0); //irr_light=vec3(0.0);
out_spec += vec4(irr_light * blend, blend); out_spec += vec4(irr_light * blend, blend);
} }
void gi_probes_compute(vec3 pos, vec3 normal, float roughness, inout vec3 out_specular, inout vec3 out_ambient) { void gi_probes_compute(vec3 pos, vec3 normal, float roughness, inout vec3 out_specular, inout vec3 out_ambient) {
roughness = roughness * roughness; roughness = roughness * roughness;
@ -1591,13 +1519,10 @@ void gi_probes_compute(vec3 pos, vec3 normal, float roughness, inout vec3 out_sp
out_specular += spec_accum.rgb; out_specular += spec_accum.rgb;
out_ambient += diff_accum.rgb; out_ambient += diff_accum.rgb;
} }
#endif #endif
void main() { void main() {
#ifdef RENDER_DEPTH_DUAL_PARABOLOID #ifdef RENDER_DEPTH_DUAL_PARABOLOID
@ -1634,7 +1559,6 @@ void main() {
float side = 1.0; float side = 1.0;
#endif #endif
#if defined(ALPHA_SCISSOR_USED) #if defined(ALPHA_SCISSOR_USED)
float alpha_scissor = 0.5; float alpha_scissor = 0.5;
#endif #endif
@ -1677,12 +1601,10 @@ void main() {
{ {
FRAGMENT_SHADER_CODE FRAGMENT_SHADER_CODE
} }
#if defined(ALPHA_SCISSOR_USED) #if defined(ALPHA_SCISSOR_USED)
if (alpha < alpha_scissor) { if (alpha < alpha_scissor) {
discard; discard;
@ -1745,8 +1667,6 @@ FRAGMENT_SHADER_CODE
vec3 eye_vec = -normalize(vertex_interp); vec3 eye_vec = -normalize(vertex_interp);
#ifdef USE_RADIANCE_MAP #ifdef USE_RADIANCE_MAP
#ifdef AMBIENT_LIGHT_DISABLED #ifdef AMBIENT_LIGHT_DISABLED
@ -1760,11 +1680,9 @@ FRAGMENT_SHADER_CODE
ref_vec = normalize((radiance_inverse_xform * vec4(ref_vec, 0.0)).xyz); ref_vec = normalize((radiance_inverse_xform * vec4(ref_vec, 0.0)).xyz);
vec3 radiance = textureDualParaboloid(radiance_map, ref_vec, roughness) * bg_energy; vec3 radiance = textureDualParaboloid(radiance_map, ref_vec, roughness) * bg_energy;
env_reflection_light = radiance; env_reflection_light = radiance;
} }
//no longer a cubemap //no longer a cubemap
//vec3 radiance = textureLod(radiance_cube, r, lod).xyz * ( brdf.x + brdf.y); //vec3 radiance = textureLod(radiance_cube, r, lod).xyz * ( brdf.x + brdf.y);
} }
#ifndef USE_LIGHTMAP #ifndef USE_LIGHTMAP
{ {
@ -1820,10 +1738,8 @@ FRAGMENT_SHADER_CODE
bool use_blend = true; bool use_blend = true;
#endif #endif
#ifdef LIGHT_USE_PSSM4 #ifdef LIGHT_USE_PSSM4
if (depth_z < shadow_split_offsets.y) { if (depth_z < shadow_split_offsets.y) {
if (depth_z < shadow_split_offsets.x) { if (depth_z < shadow_split_offsets.x) {
@ -1831,7 +1747,6 @@ FRAGMENT_SHADER_CODE
highp vec4 splane = (shadow_matrix1 * vec4(vertex, 1.0)); highp vec4 splane = (shadow_matrix1 * vec4(vertex, 1.0));
pssm_coord = splane.xyz / splane.w; pssm_coord = splane.xyz / splane.w;
#if defined(LIGHT_USE_PSSM_BLEND) #if defined(LIGHT_USE_PSSM_BLEND)
splane = (shadow_matrix2 * vec4(vertex, 1.0)); splane = (shadow_matrix2 * vec4(vertex, 1.0));
@ -1849,11 +1764,9 @@ FRAGMENT_SHADER_CODE
pssm_coord2 = splane.xyz / splane.w; pssm_coord2 = splane.xyz / splane.w;
pssm_blend = smoothstep(shadow_split_offsets.x, shadow_split_offsets.y, depth_z); pssm_blend = smoothstep(shadow_split_offsets.x, shadow_split_offsets.y, depth_z);
#endif #endif
} }
} else { } else {
if (depth_z < shadow_split_offsets.z) { if (depth_z < shadow_split_offsets.z) {
highp vec4 splane = (shadow_matrix3 * vec4(vertex, 1.0)); highp vec4 splane = (shadow_matrix3 * vec4(vertex, 1.0));
@ -1875,12 +1788,9 @@ FRAGMENT_SHADER_CODE
use_blend = false; use_blend = false;
#endif #endif
} }
} }
#endif //LIGHT_USE_PSSM4 #endif //LIGHT_USE_PSSM4
#ifdef LIGHT_USE_PSSM2 #ifdef LIGHT_USE_PSSM2
@ -1890,7 +1800,6 @@ FRAGMENT_SHADER_CODE
highp vec4 splane = (shadow_matrix1 * vec4(vertex, 1.0)); highp vec4 splane = (shadow_matrix1 * vec4(vertex, 1.0));
pssm_coord = splane.xyz / splane.w; pssm_coord = splane.xyz / splane.w;
#if defined(LIGHT_USE_PSSM_BLEND) #if defined(LIGHT_USE_PSSM_BLEND)
splane = (shadow_matrix2 * vec4(vertex, 1.0)); splane = (shadow_matrix2 * vec4(vertex, 1.0));
@ -1906,7 +1815,6 @@ FRAGMENT_SHADER_CODE
use_blend = false; use_blend = false;
#endif #endif
} }
#endif //LIGHT_USE_PSSM2 #endif //LIGHT_USE_PSSM2
@ -1918,7 +1826,6 @@ FRAGMENT_SHADER_CODE
} }
#endif #endif
//one one sample //one one sample
float shadow = sample_shadow(directional_shadow, directional_shadow_pixel_size, pssm_coord.xy, pssm_coord.z, light_clamp); float shadow = sample_shadow(directional_shadow, directional_shadow_pixel_size, pssm_coord.xy, pssm_coord.z, light_clamp);
@ -1935,15 +1842,11 @@ FRAGMENT_SHADER_CODE
float contact_shadow = contact_shadow_compute(vertex, -light_direction_attenuation.xyz, shadow_color_contact.a); float contact_shadow = contact_shadow_compute(vertex, -light_direction_attenuation.xyz, shadow_color_contact.a);
shadow = min(shadow, contact_shadow); shadow = min(shadow, contact_shadow);
} }
#endif #endif
light_attenuation = mix(mix(shadow_color_contact.rgb, vec3(1.0), shadow), vec3(1.0), pssm_fade); light_attenuation = mix(mix(shadow_color_contact.rgb, vec3(1.0), shadow), vec3(1.0), pssm_fade);
} }
#endif // !defined(SHADOWS_DISABLED) #endif // !defined(SHADOWS_DISABLED)
#endif //LIGHT_DIRECTIONAL_SHADOW #endif //LIGHT_DIRECTIONAL_SHADOW
@ -1955,7 +1858,6 @@ FRAGMENT_SHADER_CODE
light_compute(normal, -light_direction_attenuation.xyz, eye_vec, binormal, tangent, light_color_energy.rgb, light_attenuation, albedo, transmission, light_params.z * specular_blob_intensity, roughness, metallic, rim, rim_tint, clearcoat, clearcoat_gloss, anisotropy, diffuse_light, specular_light); light_compute(normal, -light_direction_attenuation.xyz, eye_vec, binormal, tangent, light_color_energy.rgb, light_attenuation, albedo, transmission, light_params.z * specular_blob_intensity, roughness, metallic, rim, rim_tint, clearcoat, clearcoat_gloss, anisotropy, diffuse_light, specular_light);
#endif #endif
#endif //#USE_LIGHT_DIRECTIONAL #endif //#USE_LIGHT_DIRECTIONAL
#ifdef USE_GI_PROBES #ifdef USE_GI_PROBES
@ -1981,9 +1883,7 @@ FRAGMENT_SHADER_CODE
vec3(0.267617, 0.823639, -0.5), vec3(0.267617, 0.823639, -0.5),
vec3(-0.700629, 0.509037, -0.5), vec3(-0.700629, 0.509037, -0.5),
vec3(-0.700629, -0.509037, -0.5), vec3(-0.700629, -0.509037, -0.5),
vec3(0.267617, -0.823639, -0.5) vec3(0.267617, -0.823639, -0.5));
);
vec3 local_normal = normalize(camera_matrix * vec4(normal, 0.0)).xyz; vec3 local_normal = normalize(camera_matrix * vec4(normal, 0.0)).xyz;
vec4 captured = vec4(0.0); vec4 captured = vec4(0.0);
@ -2001,13 +1901,11 @@ FRAGMENT_SHADER_CODE
} else { } else {
ambient_light = captured.rgb; ambient_light = captured.rgb;
} }
} }
#endif #endif
#ifdef USE_FORWARD_LIGHTING #ifdef USE_FORWARD_LIGHTING
highp vec4 reflection_accum = vec4(0.0, 0.0, 0.0, 0.0); highp vec4 reflection_accum = vec4(0.0, 0.0, 0.0, 0.0);
highp vec4 ambient_accum = vec4(0.0, 0.0, 0.0, 0.0); highp vec4 ambient_accum = vec4(0.0, 0.0, 0.0, 0.0);
for (int i = 0; i < reflection_count; i++) { for (int i = 0; i < reflection_count; i++) {
@ -2025,7 +1923,6 @@ FRAGMENT_SHADER_CODE
} }
#endif #endif
#ifdef USE_VERTEX_LIGHTING #ifdef USE_VERTEX_LIGHTING
diffuse_light *= albedo; diffuse_light *= albedo;
@ -2043,9 +1940,6 @@ FRAGMENT_SHADER_CODE
#endif #endif
#ifdef RENDER_DEPTH #ifdef RENDER_DEPTH
//nothing happens, so a tree-ssa optimizer will result in no fragment shader :) //nothing happens, so a tree-ssa optimizer will result in no fragment shader :)
#else #else
@ -2060,13 +1954,10 @@ FRAGMENT_SHADER_CODE
diffuse_light *= ao_light_affect; diffuse_light *= ao_light_affect;
#endif #endif
//energy conservation //energy conservation
diffuse_light *= 1.0 - metallic; // TODO: avoid all diffuse and ambient light calculations when metallic == 1 up to this point diffuse_light *= 1.0 - metallic; // TODO: avoid all diffuse and ambient light calculations when metallic == 1 up to this point
ambient_light *= 1.0 - metallic; ambient_light *= 1.0 - metallic;
{ {
#if defined(DIFFUSE_TOON) #if defined(DIFFUSE_TOON)
@ -2085,15 +1976,12 @@ FRAGMENT_SHADER_CODE
vec3 specular_color = metallic_to_specular_color(metallic, specular, albedo); vec3 specular_color = metallic_to_specular_color(metallic, specular, albedo);
specular_light *= AB.x * specular_color + AB.y; specular_light *= AB.x * specular_color + AB.y;
#endif #endif
} }
if (fog_color_enabled.a > 0.5) { if (fog_color_enabled.a > 0.5) {
float fog_amount = 0.0; float fog_amount = 0.0;
#ifdef USE_LIGHT_DIRECTIONAL #ifdef USE_LIGHT_DIRECTIONAL
vec3 fog_color = mix(fog_color_enabled.rgb, fog_sun_color_amount.rgb, fog_sun_color_amount.a * pow(max(dot(normalize(vertex), -light_direction_attenuation.xyz), 0.0), 8.0)); vec3 fog_color = mix(fog_color_enabled.rgb, fog_sun_color_amount.rgb, fog_sun_color_amount.a * pow(max(dot(normalize(vertex), -light_direction_attenuation.xyz), 0.0), 8.0));
@ -2123,25 +2011,20 @@ FRAGMENT_SHADER_CODE
float rev_amount = 1.0 - fog_amount; float rev_amount = 1.0 - fog_amount;
emission = emission * rev_amount + fog_color * fog_amount; emission = emission * rev_amount + fog_color * fog_amount;
ambient_light *= rev_amount; ambient_light *= rev_amount;
specular_light *rev_amount; specular_light *rev_amount;
diffuse_light *= rev_amount; diffuse_light *= rev_amount;
} }
#ifdef USE_MULTIPLE_RENDER_TARGETS #ifdef USE_MULTIPLE_RENDER_TARGETS
#ifdef SHADELESS #ifdef SHADELESS
diffuse_buffer = vec4(albedo.rgb, 0.0); diffuse_buffer = vec4(albedo.rgb, 0.0);
specular_buffer = vec4(0.0); specular_buffer = vec4(0.0);
#else #else
//approximate ambient scale for SSAO, since we will lack full ambient //approximate ambient scale for SSAO, since we will lack full ambient
float max_emission = max(emission.r, max(emission.g, emission.b)); float max_emission = max(emission.r, max(emission.g, emission.b));
float max_ambient = max(ambient_light.r, max(ambient_light.g, ambient_light.b)); float max_ambient = max(ambient_light.r, max(ambient_light.g, ambient_light.b));
@ -2163,10 +2046,8 @@ FRAGMENT_SHADER_CODE
sss_buffer = sss_strength; sss_buffer = sss_strength;
#endif #endif
#else //USE_MULTIPLE_RENDER_TARGETS #else //USE_MULTIPLE_RENDER_TARGETS
#ifdef SHADELESS #ifdef SHADELESS
frag_color = vec4(albedo, alpha); frag_color = vec4(albedo, alpha);
#else #else
@ -2175,9 +2056,5 @@ FRAGMENT_SHADER_CODE
#endif //USE_MULTIPLE_RENDER_TARGETS #endif //USE_MULTIPLE_RENDER_TARGETS
#endif //RENDER_DEPTH #endif //RENDER_DEPTH
} }

View file

@ -1,6 +1,5 @@
[vertex] [vertex]
layout(location = 0) in highp vec4 vertex_attrib; layout(location = 0) in highp vec4 vertex_attrib;
layout(location = 4) in vec2 uv_in; layout(location = 4) in vec2 uv_in;
@ -16,7 +15,6 @@ void main() {
[fragment] [fragment]
in vec2 uv_interp; in vec2 uv_interp;
in vec2 pos_interp; in vec2 pos_interp;
@ -40,10 +38,8 @@ uniform float depth_tolerance;
uniform float distance_fade; uniform float distance_fade;
uniform float curve_fade_in; uniform float curve_fade_in;
layout(location = 0) out vec4 frag_color; layout(location = 0) out vec4 frag_color;
vec2 view_to_screen(vec3 view_pos, out float w) { vec2 view_to_screen(vec3 view_pos, out float w) {
vec4 projected = projection * vec4(view_pos, 1.0); vec4 projected = projection * vec4(view_pos, 1.0);
projected.xyz /= projected.w; projected.xyz /= projected.w;
@ -52,20 +48,14 @@ vec2 view_to_screen(vec3 view_pos,out float w) {
return projected.xy; return projected.xy;
} }
#define M_PI 3.14159265359 #define M_PI 3.14159265359
void main() { void main() {
////
vec4 diffuse = texture(source_diffuse, uv_interp); vec4 diffuse = texture(source_diffuse, uv_interp);
vec4 normal_roughness = texture(source_normal_roughness, uv_interp); vec4 normal_roughness = texture(source_normal_roughness, uv_interp);
vec3 normal; vec3 normal;
normal = normal_roughness.xyz * 2.0 - 1.0; normal = normal_roughness.xyz * 2.0 - 1.0;
float roughness = normal_roughness.w; float roughness = normal_roughness.w;
@ -83,13 +73,10 @@ void main() {
return; return;
} }
//ray_dir = normalize(view_dir - normal * dot(normal,view_dir) * 2.0); //ray_dir = normalize(view_dir - normal * dot(normal,view_dir) * 2.0);
//ray_dir = normalize(vec3(1, 1, -1)); //ray_dir = normalize(vec3(1, 1, -1));
//////////////// ////////////////
// make ray length and clip it against the near plane (don't want to trace beyond visible) // make ray length and clip it against the near plane (don't want to trace beyond visible)
float ray_len = (vertex.z + ray_dir.z * camera_z_far) > -camera_z_near ? (-camera_z_near - vertex.z) / ray_dir.z : camera_z_far; float ray_len = (vertex.z + ray_dir.z * camera_z_far) > -camera_z_near ? (-camera_z_near - vertex.z) / ray_dir.z : camera_z_far;
vec3 ray_end = vertex + ray_dir * ray_len; vec3 ray_end = vertex + ray_dir * ray_len;
@ -101,11 +88,9 @@ void main() {
vec2 vp_line_dir = vp_line_end - vp_line_begin; vec2 vp_line_dir = vp_line_end - vp_line_begin;
// we need to interpolate w along the ray, to generate perspective correct reflections // we need to interpolate w along the ray, to generate perspective correct reflections
w_begin = 1.0 / w_begin; w_begin = 1.0 / w_begin;
w_end = 1.0 / w_end; w_end = 1.0 / w_end;
float z_begin = vertex.z * w_begin; float z_begin = vertex.z * w_begin;
float z_end = ray_end.z * w_end; float z_end = ray_end.z * w_end;
@ -114,7 +99,6 @@ void main() {
float z_dir = z_end - z_begin; float z_dir = z_end - z_begin;
float w_dir = w_end - w_begin; float w_dir = w_end - w_begin;
// clip the line to the viewport edges // clip the line to the viewport edges
float scale_max_x = min(1.0, 0.99 * (1.0 - vp_line_begin.x) / max(1e-5, vp_line_dir.x)); float scale_max_x = min(1.0, 0.99 * (1.0 - vp_line_begin.x) / max(1e-5, vp_line_dir.x));
@ -182,14 +166,10 @@ void main() {
prev_pos = pos; prev_pos = pos;
} }
if (found) { if (found) {
float margin_blend = 1.0; float margin_blend = 1.0;
vec2 margin = vec2((viewport_size.x + viewport_size.y) * 0.5 * 0.05); // make a uniform margin vec2 margin = vec2((viewport_size.x + viewport_size.y) * 0.5 * 0.05); // make a uniform margin
if (any(bvec4(lessThan(pos, -margin), greaterThan(pos, viewport_size + margin)))) { if (any(bvec4(lessThan(pos, -margin), greaterThan(pos, viewport_size + margin)))) {
// clip outside screen + margin // clip outside screen + margin
@ -202,7 +182,6 @@ void main() {
vec2 margin_grad = mix(pos - viewport_size, -pos, lessThan(pos, vec2(0.0))); vec2 margin_grad = mix(pos - viewport_size, -pos, lessThan(pos, vec2(0.0)));
margin_blend = 1.0 - smoothstep(0.0, margin.x, max(margin_grad.x, margin_grad.y)); margin_blend = 1.0 - smoothstep(0.0, margin.x, max(margin_grad.x, margin_grad.y));
//margin_blend = 1.0; //margin_blend = 1.0;
} }
vec2 final_pos; vec2 final_pos;
@ -212,15 +191,8 @@ void main() {
float fade = pow(clamp(1.0 - grad, 0.0, 1.0), distance_fade) * initial_fade; float fade = pow(clamp(1.0 - grad, 0.0, 1.0), distance_fade) * initial_fade;
final_pos = pos; final_pos = pos;
#ifdef REFLECT_ROUGHNESS #ifdef REFLECT_ROUGHNESS
vec4 final_color; vec4 final_color;
// if roughness is enabled, do screen space cone tracing // if roughness is enabled, do screen space cone tracing
if (roughness > 0.001) { if (roughness > 0.001) {
@ -261,8 +233,8 @@ void main() {
vec2 sample_pos = (line_begin + cone_dir * (cone_len - radius)) * pixel_size; vec2 sample_pos = (line_begin + cone_dir * (cone_len - radius)) * pixel_size;
// radius is in pixels, so it's natural that log2(radius) maps to the right mipmap for the amount of pixels // radius is in pixels, so it's natural that log2(radius) maps to the right mipmap for the amount of pixels
float mipmap = clamp(log2(radius), 0.0, max_mipmap); float mipmap = clamp(log2(radius), 0.0, max_mipmap);
//mipmap = max(mipmap - 1.0, 0.0); //mipmap = max(mipmap - 1.0, 0.0);
// do sampling // do sampling
vec4 sample_color; vec4 sample_color;
@ -293,8 +265,6 @@ void main() {
cone_len -= radius * 2.0; // go to next (smaller) circle. cone_len -= radius * 2.0; // go to next (smaller) circle.
gloss_mult *= gloss; gloss_mult *= gloss;
} }
} else { } else {
final_color = textureLod(source_diffuse, final_pos * pixel_size, 0.0); final_color = textureLod(source_diffuse, final_pos * pixel_size, 0.0);
@ -306,13 +276,7 @@ void main() {
frag_color = vec4(textureLod(source_diffuse, final_pos * pixel_size, 0.0).rgb, fade * margin_blend); frag_color = vec4(textureLod(source_diffuse, final_pos * pixel_size, 0.0).rgb, fade * margin_blend);
#endif #endif
} else { } else {
frag_color = vec4(0.0, 0.0, 0.0, 0.0); frag_color = vec4(0.0, 0.0, 0.0, 0.0);
} }
} }

View file

@ -1,6 +1,5 @@
[vertex] [vertex]
layout(location = 0) in highp vec4 vertex_attrib; layout(location = 0) in highp vec4 vertex_attrib;
void main() { void main() {
@ -14,21 +13,15 @@ void main() {
#define TWO_PI 6.283185307179586476925286766559 #define TWO_PI 6.283185307179586476925286766559
#ifdef SSAO_QUALITY_HIGH #ifdef SSAO_QUALITY_HIGH
#define NUM_SAMPLES (80) #define NUM_SAMPLES (80)
#endif #endif
#ifdef SSAO_QUALITY_LOW #ifdef SSAO_QUALITY_LOW
#define NUM_SAMPLES (15) #define NUM_SAMPLES (15)
#endif #endif
#if !defined(SSAO_QUALITY_LOW) && !defined(SSAO_QUALITY_HIGH) #if !defined(SSAO_QUALITY_LOW) && !defined(SSAO_QUALITY_HIGH)
#define NUM_SAMPLES (40) #define NUM_SAMPLES (40)
#endif #endif
// If using depth mip levels, the log of the maximum pixel offset before we need to switch to a lower // If using depth mip levels, the log of the maximum pixel offset before we need to switch to a lower
@ -43,7 +36,8 @@ void main() {
// This is the number of turns around the circle that the spiral pattern makes. This should be prime to prevent // This is the number of turns around the circle that the spiral pattern makes. This should be prime to prevent
// taps from lining up. This particular choice was tuned for NUM_SAMPLES == 9 // taps from lining up. This particular choice was tuned for NUM_SAMPLES == 9
const int ROTATIONS[] = int[]( 1, 1, 2, 3, 2, 5, 2, 3, 2, const int ROTATIONS[] = int[](
1, 1, 2, 3, 2, 5, 2, 3, 2,
3, 3, 5, 5, 3, 4, 7, 5, 5, 7, 3, 3, 5, 5, 3, 4, 7, 5, 5, 7,
9, 8, 5, 5, 7, 7, 7, 8, 5, 8, 9, 8, 5, 5, 7, 7, 7, 8, 5, 8,
11, 12, 7, 10, 13, 8, 11, 8, 7, 14, 11, 12, 7, 10, 13, 8, 11, 8, 7, 14,
@ -52,7 +46,8 @@ const int ROTATIONS[] = int[]( 1, 1, 2, 3, 2, 5, 2, 3, 2,
13, 17, 11, 17, 19, 18, 25, 18, 19, 19, 13, 17, 11, 17, 19, 18, 25, 18, 19, 19,
29, 21, 19, 27, 31, 29, 21, 18, 17, 29, 29, 21, 19, 27, 31, 29, 21, 18, 17, 29,
31, 31, 23, 18, 25, 26, 25, 23, 19, 34, 31, 31, 23, 18, 25, 26, 25, 23, 19, 34,
19, 27, 21, 25, 39, 29, 17, 21, 27 ); 19, 27, 21, 25, 39, 29, 17, 21, 27
);
//#define NUM_SPIRAL_TURNS (7) //#define NUM_SPIRAL_TURNS (7)
const int NUM_SPIRAL_TURNS = ROTATIONS[NUM_SAMPLES - 1]; const int NUM_SPIRAL_TURNS = ROTATIONS[NUM_SAMPLES - 1];
@ -111,8 +106,6 @@ vec3 reconstructCSFaceNormal(vec3 C) {
return normalize(cross(dFdy(C), dFdx(C))); return normalize(cross(dFdy(C), dFdx(C)));
} }
/** Returns a unit vector and a screen-space radius for the tap on a unit disk (the caller should scale by the actual disk radius) */ /** Returns a unit vector and a screen-space radius for the tap on a unit disk (the caller should scale by the actual disk radius) */
vec2 tapLocation(int sampleNumber, float spinAngle, out float ssR) { vec2 tapLocation(int sampleNumber, float spinAngle, out float ssR) {
// Radius relative to ssR // Radius relative to ssR
@ -123,7 +116,6 @@ vec2 tapLocation(int sampleNumber, float spinAngle, out float ssR){
return vec2(cos(angle), sin(angle)); return vec2(cos(angle), sin(angle));
} }
/** Read the camera-space position of the point at screen-space pixel ssP + unitOffset * ssR. Assumes length(unitOffset) == 1 */ /** Read the camera-space position of the point at screen-space pixel ssP + unitOffset * ssR. Assumes length(unitOffset) == 1 */
vec3 getOffsetPosition(ivec2 ssC, vec2 unitOffset, float ssR) { vec3 getOffsetPosition(ivec2 ssC, vec2 unitOffset, float ssR) {
// Derivation: // Derivation:
@ -138,7 +130,6 @@ vec3 getOffsetPosition(ivec2 ssC, vec2 unitOffset, float ssR) {
// Manually clamp to the texture size because texelFetch bypasses the texture unit // Manually clamp to the texture size because texelFetch bypasses the texture unit
ivec2 mipP = clamp(ssP >> mipLevel, ivec2(0), (screen_size >> mipLevel) - ivec2(1)); ivec2 mipP = clamp(ssP >> mipLevel, ivec2(0), (screen_size >> mipLevel) - ivec2(1));
if (mipLevel < 1) { if (mipLevel < 1) {
//read from depth buffer //read from depth buffer
P.z = texelFetch(source_depth, mipP, 0).r; P.z = texelFetch(source_depth, mipP, 0).r;
@ -147,7 +138,6 @@ vec3 getOffsetPosition(ivec2 ssC, vec2 unitOffset, float ssR) {
P.z = ((P.z + (camera_z_far + camera_z_near) / (camera_z_far - camera_z_near)) * (camera_z_far - camera_z_near)) / 2.0; P.z = ((P.z + (camera_z_far + camera_z_near) / (camera_z_far - camera_z_near)) * (camera_z_far - camera_z_near)) / 2.0;
#else #else
P.z = 2.0 * camera_z_near * camera_z_far / (camera_z_far + camera_z_near - P.z * (camera_z_far - camera_z_near)); P.z = 2.0 * camera_z_near * camera_z_far / (camera_z_far + camera_z_near - P.z * (camera_z_far - camera_z_near));
#endif #endif
P.z = -P.z; P.z = -P.z;
@ -157,15 +147,12 @@ vec3 getOffsetPosition(ivec2 ssC, vec2 unitOffset, float ssR) {
P.z = -(float(d) / 65535.0) * camera_z_far; P.z = -(float(d) / 65535.0) * camera_z_far;
} }
// Offset to pixel center // Offset to pixel center
P = reconstructCSPosition(vec2(ssP) + vec2(0.5), P.z); P = reconstructCSPosition(vec2(ssP) + vec2(0.5), P.z);
return P; return P;
} }
/** Compute the occlusion due to sample with index \a i about the pixel at \a ssC that corresponds /** Compute the occlusion due to sample with index \a i about the pixel at \a ssC that corresponds
to camera-space point \a C with unit normal \a n_C, using maximum screen-space sampling radius \a ssDiskRadius to camera-space point \a C with unit normal \a n_C, using maximum screen-space sampling radius \a ssDiskRadius
@ -209,22 +196,20 @@ float sampleAO(in ivec2 ssC, in vec3 C, in vec3 n_C, in float ssDiskRadius,in fl
// return 2.0 * float(vv < radius * radius) * max(vn - bias, 0.0); // return 2.0 * float(vv < radius * radius) * max(vn - bias, 0.0);
} }
void main() { void main() {
// Pixel being shaded // Pixel being shaded
ivec2 ssC = ivec2(gl_FragCoord.xy); ivec2 ssC = ivec2(gl_FragCoord.xy);
// World space point being shaded // World space point being shaded
vec3 C = getPosition(ssC); vec3 C = getPosition(ssC);
/* if (C.z <= -camera_z_far*0.999) { /*
if (C.z <= -camera_z_far * 0.999) {
// We're on the skybox // We're on the skybox
visibility=1.0; visibility=1.0;
return; return;
}*/ }
*/
//visibility = -C.z / camera_z_far; //visibility = -C.z / camera_z_far;
//return; //return;
@ -286,8 +271,4 @@ void main() {
} }
visibility = A; visibility = A;
} }

View file

@ -1,9 +1,7 @@
[vertex] [vertex]
layout(location = 0) in highp vec4 vertex_attrib; layout(location = 0) in highp vec4 vertex_attrib;
void main() { void main() {
gl_Position = vertex_attrib; gl_Position = vertex_attrib;
@ -12,15 +10,12 @@ void main() {
[fragment] [fragment]
uniform sampler2D source_ssao; //texunit:0 uniform sampler2D source_ssao; //texunit:0
uniform sampler2D source_depth; //texunit:1 uniform sampler2D source_depth; //texunit:1
uniform sampler2D source_normal; //texunit:3 uniform sampler2D source_normal; //texunit:3
layout(location = 0) out float visibility; layout(location = 0) out float visibility;
////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////
// Tunable Parameters: // Tunable Parameters:
@ -110,9 +105,7 @@ void main() {
//weight *= max(0.0, dot(temp_normal, normal)); //weight *= max(0.0, dot(temp_normal, normal));
// range domain (the "bilateral" weight). As depth difference increases, decrease weight. // range domain (the "bilateral" weight). As depth difference increases, decrease weight.
weight *= max(0.0, 1.0 weight *= max(0.0, 1.0 - edge_sharpness * abs(temp_depth - depth));
- edge_sharpness * abs(temp_depth - depth)
);
sum += value * weight; sum += value * weight;
totalWeight += weight; totalWeight += weight;

View file

@ -1,6 +1,5 @@
[vertex] [vertex]
layout(location = 0) in highp vec4 vertex_attrib; layout(location = 0) in highp vec4 vertex_attrib;
void main() { void main() {
@ -10,7 +9,6 @@ void main() {
[fragment] [fragment]
#ifdef MINIFY_START #ifdef MINIFY_START
#define SDEPTH_TYPE highp sampler2D #define SDEPTH_TYPE highp sampler2D
@ -32,7 +30,6 @@ layout(location = 0) out mediump uint depth;
void main() { void main() {
ivec2 ssP = ivec2(gl_FragCoord.xy); ivec2 ssP = ivec2(gl_FragCoord.xy);
// Rotated grid subsampling to avoid XY directional bias or Z precision bias while downsampling. // Rotated grid subsampling to avoid XY directional bias or Z precision bias while downsampling.
@ -52,8 +49,4 @@ void main() {
#else #else
depth = texelFetch(source_depth, clamp(ssP * 2 + ivec2(ssP.y & 1, ssP.x & 1), ivec2(0), from_size - ivec2(1)), source_mipmap).r; depth = texelFetch(source_depth, clamp(ssP * 2 + ivec2(ssP.y & 1, ssP.x & 1), ivec2(0), from_size - ivec2(1)), source_mipmap).r;
#endif #endif
} }

View file

@ -1,12 +1,10 @@
[vertex] [vertex]
layout(location = 0) in highp vec4 vertex_attrib; layout(location = 0) in highp vec4 vertex_attrib;
layout(location = 4) in vec2 uv_in; layout(location = 4) in vec2 uv_in;
out vec2 uv_interp; out vec2 uv_interp;
void main() { void main() {
uv_interp = uv_in; uv_interp = uv_in;
@ -19,7 +17,6 @@ void main() {
#define QUALIFIER const #define QUALIFIER const
#ifdef USE_25_SAMPLES #ifdef USE_25_SAMPLES
const int kernel_size = 25; const int kernel_size = 25;
QUALIFIER vec2 kernel[25] = vec2[] ( QUALIFIER vec2 kernel[25] = vec2[] (
vec2(0.530605, 0.0), vec2(0.530605, 0.0),
@ -48,13 +45,10 @@ QUALIFIER vec2 kernel[25] = vec2[] (
vec2(0.00333804, 2.52083), vec2(0.00333804, 2.52083),
vec2(0.000973794, 3.0) vec2(0.000973794, 3.0)
); );
#endif //USE_25_SAMPLES #endif //USE_25_SAMPLES
#ifdef USE_17_SAMPLES #ifdef USE_17_SAMPLES
const int kernel_size = 17; const int kernel_size = 17;
QUALIFIER vec2 kernel[17] = vec2[]( QUALIFIER vec2 kernel[17] = vec2[](
vec2(0.536343, 0.0), vec2(0.536343, 0.0),
vec2(0.00317394, -2.0), vec2(0.00317394, -2.0),
@ -74,14 +68,11 @@ QUALIFIER vec2 kernel[17] = vec2[](
vec2(0.0100386, 1.53125), vec2(0.0100386, 1.53125),
vec2(0.00317394, 2.0) vec2(0.00317394, 2.0)
); );
#endif //USE_17_SAMPLES #endif //USE_17_SAMPLES
#ifdef USE_11_SAMPLES #ifdef USE_11_SAMPLES
const int kernel_size = 11; const int kernel_size = 11;
QUALIFIER vec2 kernel[11] = vec2[]( QUALIFIER vec2 kernel[11] = vec2[](
vec2(0.560479, 0.0), vec2(0.560479, 0.0),
vec2(0.00471691, -2.0), vec2(0.00471691, -2.0),
@ -95,11 +86,8 @@ QUALIFIER vec2 kernel[11] = vec2[](
vec2(0.0192831, 1.28), vec2(0.0192831, 1.28),
vec2(0.00471691, 2.0) vec2(0.00471691, 2.0)
); );
#endif //USE_11_SAMPLES #endif //USE_11_SAMPLES
uniform float max_radius; uniform float max_radius;
uniform float camera_z_far; uniform float camera_z_far;
uniform float camera_z_near; uniform float camera_z_near;
@ -121,10 +109,8 @@ void main() {
// Fetch color of current pixel: // Fetch color of current pixel:
vec4 base_color = texture(source_diffuse, uv_interp); vec4 base_color = texture(source_diffuse, uv_interp);
if (strength > 0.0) { if (strength > 0.0) {
// Fetch linear depth of current pixel: // Fetch linear depth of current pixel:
float depth = texture(source_depth, uv_interp).r * 2.0 - 1.0; float depth = texture(source_depth, uv_interp).r * 2.0 - 1.0;
#ifdef USE_ORTHOGONAL_PROJECTION #ifdef USE_ORTHOGONAL_PROJECTION
@ -135,8 +121,6 @@ void main() {
float scale = unit_size / depth; //remember depth is negative by default in OpenGL float scale = unit_size / depth; //remember depth is negative by default in OpenGL
#endif #endif
// Calculate the final step to fetch the surrounding pixels: // Calculate the final step to fetch the surrounding pixels:
vec2 step = max_radius * scale * dir; vec2 step = max_radius * scale * dir;
step *= strength; // Modulate it using the alpha channel. step *= strength; // Modulate it using the alpha channel.
@ -165,8 +149,7 @@ void main() {
depth_cmp = 2.0 * camera_z_near * camera_z_far / (camera_z_far + camera_z_near - depth_cmp * (camera_z_far - camera_z_near)); depth_cmp = 2.0 * camera_z_near * camera_z_far / (camera_z_far + camera_z_near - depth_cmp * (camera_z_far - camera_z_near));
#endif #endif
float s = clamp(300.0f * scale * float s = clamp(300.0f * scale * max_radius * abs(depth - depth_cmp), 0.0, 1.0);
max_radius * abs(depth - depth_cmp),0.0,1.0);
color = mix(color, base_color.rgb, s); color = mix(color, base_color.rgb, s);
#endif #endif
@ -179,7 +162,6 @@ void main() {
color *= color_s; color *= color_s;
#endif #endif
color_accum += color; color_accum += color;
} }
#ifdef ENABLE_STRENGTH_WEIGHTING #ifdef ENABLE_STRENGTH_WEIGHTING

View file

@ -5,8 +5,7 @@ layout (location = 4) in vec2 uv_in;
out vec2 uv_interp; out vec2 uv_interp;
void main() void main() {
{
gl_Position = vertex_attrib; gl_Position = vertex_attrib;
uv_interp = uv_in; uv_interp = uv_in;
@ -53,52 +52,43 @@ layout (location = 0) out vec4 frag_color;
#ifdef USE_GLOW_FILTER_BICUBIC #ifdef USE_GLOW_FILTER_BICUBIC
// w0, w1, w2, and w3 are the four cubic B-spline basis functions // w0, w1, w2, and w3 are the four cubic B-spline basis functions
float w0(float a) float w0(float a) {
{
return (1.0f / 6.0f) * (a * (a * (-a + 3.0f) - 3.0f) + 1.0f); return (1.0f / 6.0f) * (a * (a * (-a + 3.0f) - 3.0f) + 1.0f);
} }
float w1(float a) float w1(float a) {
{
return (1.0f / 6.0f) * (a * a * (3.0f * a - 6.0f) + 4.0f); return (1.0f / 6.0f) * (a * a * (3.0f * a - 6.0f) + 4.0f);
} }
float w2(float a) float w2(float a) {
{
return (1.0f / 6.0f) * (a * (a * (-3.0f * a + 3.0f) + 3.0f) + 1.0f); return (1.0f / 6.0f) * (a * (a * (-3.0f * a + 3.0f) + 3.0f) + 1.0f);
} }
float w3(float a) float w3(float a) {
{
return (1.0f / 6.0f) * (a * a * a); return (1.0f / 6.0f) * (a * a * a);
} }
// g0 and g1 are the two amplitude functions // g0 and g1 are the two amplitude functions
float g0(float a) float g0(float a) {
{
return w0(a) + w1(a); return w0(a) + w1(a);
} }
float g1(float a) float g1(float a) {
{
return w2(a) + w3(a); return w2(a) + w3(a);
} }
// h0 and h1 are the two offset functions // h0 and h1 are the two offset functions
float h0(float a) float h0(float a) {
{
return -1.0f + w1(a) / (w0(a) + w1(a)); return -1.0f + w1(a) / (w0(a) + w1(a));
} }
float h1(float a) float h1(float a) {
{
return 1.0f + w3(a) / (w2(a) + w3(a)); return 1.0f + w3(a) / (w2(a) + w3(a));
} }
uniform ivec2 glow_texture_size; uniform ivec2 glow_texture_size;
vec4 texture2D_bicubic(sampler2D tex, vec2 uv, int p_lod) vec4 texture2D_bicubic(sampler2D tex, vec2 uv, int p_lod) {
{
float lod = float(p_lod); float lod = float(p_lod);
vec2 tex_size = vec2(glow_texture_size >> p_lod); vec2 tex_size = vec2(glow_texture_size >> p_lod);
vec2 pixel_size = vec2(1.0f) / tex_size; vec2 pixel_size = vec2(1.0f) / tex_size;
@ -131,8 +121,7 @@ layout (location = 0) out vec4 frag_color;
#define GLOW_TEXTURE_SAMPLE(m_tex, m_uv, m_lod) textureLod(m_tex, m_uv, float(m_lod)) #define GLOW_TEXTURE_SAMPLE(m_tex, m_uv, m_lod) textureLod(m_tex, m_uv, float(m_lod))
#endif #endif
vec3 tonemap_filmic(vec3 color, float white) vec3 tonemap_filmic(vec3 color, float white) {
{
const float A = 0.15f; const float A = 0.15f;
const float B = 0.50f; const float B = 0.50f;
const float C = 0.10f; const float C = 0.10f;
@ -147,8 +136,7 @@ vec3 tonemap_filmic(vec3 color, float white)
return clamp(color_tonemapped / white_tonemapped, vec3(0.0f), vec3(1.0f)); return clamp(color_tonemapped / white_tonemapped, vec3(0.0f), vec3(1.0f));
} }
vec3 tonemap_aces(vec3 color, float white) vec3 tonemap_aces(vec3 color, float white) {
{
const float A = 2.51f; const float A = 2.51f;
const float B = 0.03f; const float B = 0.03f;
const float C = 2.43f; const float C = 2.43f;
@ -161,19 +149,16 @@ vec3 tonemap_aces(vec3 color, float white)
return clamp(color_tonemapped / white_tonemapped, vec3(0.0f), vec3(1.0f)); return clamp(color_tonemapped / white_tonemapped, vec3(0.0f), vec3(1.0f));
} }
vec3 tonemap_reindhart(vec3 color, float white) vec3 tonemap_reindhart(vec3 color, float white) {
{
return clamp((color) / (1.0f + color) * (1.0f + (color / (white))), vec3(0.0f), vec3(1.0f)); // whitepoint is probably not in linear space here! return clamp((color) / (1.0f + color) * (1.0f + (color / (white))), vec3(0.0f), vec3(1.0f)); // whitepoint is probably not in linear space here!
} }
vec3 linear_to_srgb(vec3 color) // convert linear rgb to srgb, assumes clamped input in range [0;1] vec3 linear_to_srgb(vec3 color) { // convert linear rgb to srgb, assumes clamped input in range [0;1]
{
const vec3 a = vec3(0.055f); const vec3 a = vec3(0.055f);
return mix((vec3(1.0f) + a) * pow(color.rgb, vec3(1.0f / 2.4f)) - a, 12.92f * color.rgb, lessThan(color.rgb, vec3(0.0031308f))); return mix((vec3(1.0f) + a) * pow(color.rgb, vec3(1.0f / 2.4f)) - a, 12.92f * color.rgb, lessThan(color.rgb, vec3(0.0031308f)));
} }
vec3 apply_tonemapping(vec3 color, float white) // inputs are LINEAR, always outputs clamped [0;1] color vec3 apply_tonemapping(vec3 color, float white) { // inputs are LINEAR, always outputs clamped [0;1] color
{
#ifdef USE_REINDHART_TONEMAPPER #ifdef USE_REINDHART_TONEMAPPER
return tonemap_reindhart(color, white); return tonemap_reindhart(color, white);
#endif #endif
@ -189,8 +174,7 @@ vec3 apply_tonemapping(vec3 color, float white) // inputs are LINEAR, always out
return clamp(color, vec3(0.0f), vec3(1.0f)); // no other seleced -> linear return clamp(color, vec3(0.0f), vec3(1.0f)); // no other seleced -> linear
} }
vec3 gather_glow(sampler2D tex, vec2 uv) // sample all selected glow levels vec3 gather_glow(sampler2D tex, vec2 uv) { // sample all selected glow levels
{
vec3 glow = vec3(0.0f); vec3 glow = vec3(0.0f);
#ifdef USE_GLOW_LEVEL1 #ifdef USE_GLOW_LEVEL1
@ -224,8 +208,7 @@ vec3 gather_glow(sampler2D tex, vec2 uv) // sample all selected glow levels
return glow; return glow;
} }
vec3 apply_glow(vec3 color, vec3 glow) // apply glow using the selected blending mode vec3 apply_glow(vec3 color, vec3 glow) { // apply glow using the selected blending mode
{
#ifdef USE_GLOW_REPLACE #ifdef USE_GLOW_REPLACE
color = glow; color = glow;
#endif #endif
@ -249,8 +232,7 @@ vec3 apply_glow(vec3 color, vec3 glow) // apply glow using the selected blending
return color; return color;
} }
vec3 apply_bcs(vec3 color, vec3 bcs) vec3 apply_bcs(vec3 color, vec3 bcs) {
{
color = mix(vec3(0.0f), color, bcs.x); color = mix(vec3(0.0f), color, bcs.x);
color = mix(vec3(0.5f), color, bcs.y); color = mix(vec3(0.5f), color, bcs.y);
color = mix(vec3(dot(vec3(1.0f), color) * 0.33333f), color, bcs.z); color = mix(vec3(dot(vec3(1.0f), color) * 0.33333f), color, bcs.z);
@ -258,8 +240,7 @@ vec3 apply_bcs(vec3 color, vec3 bcs)
return color; return color;
} }
vec3 apply_color_correction(vec3 color, sampler2D correction_tex) vec3 apply_color_correction(vec3 color, sampler2D correction_tex) {
{
color.r = texture(correction_tex, vec2(color.r, 0.0f)).r; color.r = texture(correction_tex, vec2(color.r, 0.0f)).r;
color.g = texture(correction_tex, vec2(color.g, 0.0f)).g; color.g = texture(correction_tex, vec2(color.g, 0.0f)).g;
color.b = texture(correction_tex, vec2(color.b, 0.0f)).b; color.b = texture(correction_tex, vec2(color.b, 0.0f)).b;
@ -267,8 +248,7 @@ vec3 apply_color_correction(vec3 color, sampler2D correction_tex)
return color; return color;
} }
void main() void main() {
{
vec3 color = textureLod(source, uv_interp, 0.0f).rgb; vec3 color = textureLod(source, uv_interp, 0.0f).rgb;
// Exposure // Exposure