Filtered SSR.

This commit is contained in:
Lubos Lenco 2016-06-21 13:29:27 +02:00
parent b9d860b7be
commit 3106ca3dfe
33 changed files with 635 additions and 234 deletions

View file

@ -28,6 +28,22 @@ def parse(self, material, c, defs):
if output_node.inputs[2].is_linked:
displace_node = find_node_by_link(tree, output_node, output_node.inputs[2])
parse_material_displacement(self, material, c, defs, tree, displace_node, 1.0)
# No albedo color parsed, append white
if parse.const_color == None:
make_albedo_const([1.0, 1.0, 1.0, 1.0], c)
if parse.const_occlusion == None and '_OMTex' not in defs:
make_occlusion_const(1.0, c)
if parse.const_roughness == None and '_RMTex' not in defs:
make_roughness_const(0.0, c)
if parse.const_metalness == None and '_MMTex' not in defs:
make_metalness_const(0.0, c)
# Enable texcoords
if '_Tex' not in defs:
for d in defs:
if d == '_AMTex' or d == '_NMTex' or d == '_OMTex' or d == '_RMTex' or d == '_MMTex' or d == '_HMTex':
defs.append('_Tex')
break
def make_albedo_const(col, c):
const = Object()
@ -42,7 +58,14 @@ def make_roughness_const(f, c):
c.bind_constants.append(const)
const.id = 'roughness'
const.float = f
def make_occlusion_const(f, c):
const = Object()
parse.const_occlusion = const
c.bind_constants.append(const)
const.id = 'occlusion'
const.float = f
def make_metalness_const(f, c):
const = Object()
parse.const_metalness = const
@ -53,19 +76,12 @@ def make_metalness_const(f, c):
# Manualy set starting material point
def parse_from(self, material, c, defs, surface_node):
parse.const_color = None
parse.const_occlusion = None
parse.const_roughness = None
parse.const_metalness = None
tree = material.node_tree
parse_material_surface(self, material, c, defs, tree, surface_node, 1.0)
# No albedo color parsed, append white
if parse.const_color == None:
make_albedo_const([1.0, 1.0, 1.0, 1.0], c)
if parse.const_roughness == None and '_RMTex' not in defs:
make_roughness_const(0.0, c)
if parse.const_metalness == None and '_MMTex' not in defs:
make_metalness_const(0.0, c)
def make_texture(self, id, image_node, material):
tex = Object()
@ -366,10 +382,20 @@ def parse_normal_map_socket(self, normal_input, material, c, defs, tree, node, f
normal_node = find_node_by_link(tree, node, normal_input)
add_normal_tex(self, normal_node, material, c, defs)
def add_occlusion_const(res, c, factor):
if parse.const_occlusion == None:
make_occlusion_const(res * factor, c)
else:
const = parse.const_occlusion
const.float = mix_float(res, const.float, factor=factor)
def parse_occlusion_socket(self, occlusion_input, material, c, defs, tree, node, factor):
if occlusion_input.is_linked:
occlusion_node = find_node_by_link(tree, node, occlusion_input)
add_occlusion_tex(self, occlusion_node, material, c, defs)
elif '_OMTex' not in defs:
res = occlusion_input.default_value[0] # Take only one channel
add_occlusion_const(res, c, factor)
def parse_height_socket(self, height_input, material, c, defs, tree, node, factor):
if height_input.is_linked:
@ -396,5 +422,6 @@ def parse_pbr_group(self, material, c, defs, tree, node, factor):
height_input = node.inputs[7]
parse_height_socket(self, height_input, material, c, defs, tree, node, factor)
# Height Strength
height_strength_input = node.inputs[8]
add_height_strength(self, c, height_strength_input.default_value)
if height_input.is_linked:
height_strength_input = node.inputs[8]
add_height_strength(self, c, height_strength_input.default_value)

View file

@ -767,7 +767,7 @@ def get_render_targets(root_node, node_group):
def traverse_for_rt(node, node_group, render_targets, depth_buffers):
# Collect render targets
if node.bl_idname == 'SetTargetNodeType':
if node.bl_idname == 'SetTargetNodeType' or node.bl_idname == 'QuadPassNodeType':
if node.inputs[1].is_linked:
tnode = findNodeByLink(node_group, node, node.inputs[1])
parse_render_target(tnode, node_group, render_targets, depth_buffers)

View file

@ -97,8 +97,8 @@ class DataPropsPanel(bpy.types.Panel):
layout.operator("cg.reset_pipelines")
elif obj.type == 'MESH':
layout.prop(obj.data, 'static_usage')
layout.operator("cg.invalidate_cache")
# Reset pipelines
class OBJECT_OT_RESETPIPELINESButton(bpy.types.Operator):
bl_idname = "cg.reset_pipelines"
bl_label = "Reset Pipelines"
@ -107,6 +107,14 @@ class OBJECT_OT_RESETPIPELINESButton(bpy.types.Operator):
nodes_pipeline.reset_pipelines()
return{'FINISHED'}
class OBJECT_OT_INVALIDATECACHEButton(bpy.types.Operator):
bl_idname = "cg.invalidate_cache"
bl_label = "Invalidate Cache"
def execute(self, context):
context.object.geometry_cached = False
return{'FINISHED'}
# Menu in materials region
class MatsPropsPanel(bpy.types.Panel):
bl_label = "Cycles Props"

View file

@ -0,0 +1,47 @@
#version 450
#ifdef GL_ES
precision mediump float;
#endif
uniform sampler2D tex;
uniform sampler2D gbuffer1; // Roughness
uniform vec2 dir;
uniform vec2 screenSize;
in vec2 texCoord;
vec2 unpackFloat(float f) {
float index = floor(f) / 1000.0;
float alpha = fract(f);
return vec2(index, alpha);
}
void main() {
float roughness = unpackFloat(texture(gbuffer1, texCoord).a).x;
if (roughness == 0.0) {
// gl_FragColor = texture(tex, texCoord);
// return;
discard;
}
vec2 step = dir / screenSize;
vec3 result = texture(tex, texCoord + (step * 6.0)).rgb;
result += texture(tex, texCoord + (step * 5.0)).rgb;
result += texture(tex, texCoord + (step * 4.0)).rgb;
result += texture(tex, texCoord + (step * 3.0)).rgb;
result += texture(tex, texCoord + (step * 2.0)).rgb;
result += texture(tex, texCoord + step).rgb;
result += texture(tex, texCoord).rgb;
result += texture(tex, texCoord - step).rgb;
result += texture(tex, texCoord - (step * 2.0)).rgb;
result += texture(tex, texCoord - (step * 3.0)).rgb;
result += texture(tex, texCoord - (step * 4.0)).rgb;
result += texture(tex, texCoord - (step * 5.0)).rgb;
result += texture(tex, texCoord - (step * 6.0)).rgb;
result /= vec3(13.0);
gl_FragColor.rgb = vec3(result);
}

View file

@ -0,0 +1,126 @@
{
"contexts": [
{
"id": "blur_adaptive_pass_x",
"params": [
{
"id": "depth_write",
"value": "true"
},
{
"id": "compare_mode",
"value": "always"
},
{
"id": "cull_mode",
"value": "none"
}
],
"links": [
{
"id": "dir",
"link": "_vec2x"
},
{
"id": "screenSize",
"link": "_screenSize"
}
],
"texture_params": [],
"vertex_shader": "blur_adaptive_pass.vert.glsl",
"fragment_shader": "blur_adaptive_pass.frag.glsl"
},
{
"id": "blur_adaptive_pass_y",
"params": [
{
"id": "depth_write",
"value": "true"
},
{
"id": "compare_mode",
"value": "always"
},
{
"id": "cull_mode",
"value": "none"
}
],
"links": [
{
"id": "dir",
"link": "_vec2y"
},
{
"id": "screenSize",
"link": "_screenSize"
}
],
"texture_params": [],
"vertex_shader": "blur_adaptive_pass.vert.glsl",
"fragment_shader": "blur_adaptive_pass.frag.glsl"
},
{
"id": "blur_adaptive_pass_x2",
"params": [
{
"id": "depth_write",
"value": "true"
},
{
"id": "compare_mode",
"value": "always"
},
{
"id": "cull_mode",
"value": "none"
}
],
"links": [
{
"id": "dir",
"link": "_vec2x2"
},
{
"id": "screenSize",
"link": "_screenSize"
}
],
"texture_params": [],
"vertex_shader": "blur_adaptive_pass.vert.glsl",
"fragment_shader": "blur_adaptive_pass.frag.glsl"
},
{
"id": "blur_adaptive_pass_y2",
"params": [
{
"id": "depth_write",
"value": "true"
},
{
"id": "compare_mode",
"value": "always"
},
{
"id": "cull_mode",
"value": "none"
}
],
"links": [
{
"id": "dir",
"link": "_vec2y2"
},
{
"id": "screenSize",
"link": "_screenSize"
}
],
"texture_params": [],
"vertex_shader": "blur_adaptive_pass.vert.glsl",
"fragment_shader": "blur_adaptive_pass.frag.glsl"
}
]
}

View file

@ -0,0 +1,18 @@
#version 450
#ifdef GL_ES
precision highp float;
#endif
in vec2 pos;
out vec2 texCoord;
const vec2 madd = vec2(0.5, 0.5);
void main() {
// Scale vertex attribute to [0-1] range
texCoord = pos.xy * madd + madd;
gl_Position = vec4(pos.xy, 0.0, 1.0);
}

View file

@ -6,7 +6,9 @@ precision mediump float;
uniform sampler2D tex;
uniform sampler2D gbuffer0;
uniform vec2 dir;
uniform vec2 screenSize;
in vec2 texCoord;
@ -28,16 +30,15 @@ vec3 getNor(vec2 enc) {
}
float doBlur(float blurWeight, int pos, vec3 nor) {
vec2 texstep = dir / vec2(1920.0, 1080.0);
vec2 texstep2 = dir / vec2(1920.0, 1080.0);
vec2 texstep = dir / screenSize;
vec3 nor2 = getNor(texture(gbuffer0, texCoord + pos * texstep2).rg);
vec3 nor2 = getNor(texture(gbuffer0, texCoord + pos * texstep).rg);
float influenceFactor = step(discardThreshold, dot(nor2, nor));
vec3 col = texture(tex, texCoord + pos * texstep).rgb;
result += col * blurWeight * influenceFactor;
float weight = blurWeight * influenceFactor;
nor2 = getNor(texture(gbuffer0, texCoord - pos * texstep2).rg);
nor2 = getNor(texture(gbuffer0, texCoord - pos * texstep).rg);
influenceFactor = step(discardThreshold, dot(nor2, nor));
col = texture(tex, texCoord - pos * texstep).rgb;
result += col * blurWeight * influenceFactor;
@ -47,12 +48,7 @@ float doBlur(float blurWeight, int pos, vec3 nor) {
}
void main() {
vec2 texstep = dir / vec2(800, 600);
vec2 texstep2 = dir / vec2(800, 600);
vec3 nor = getNor(texture(gbuffer0, texCoord).rg);
float weight = 0.0;
// for (int i = 0; i < 9; i++) {

View file

@ -20,6 +20,10 @@
{
"id": "dir",
"link": "_vec2x"
},
{
"id": "screenSize",
"link": "_screenSize"
}
],
"texture_params": [],
@ -40,16 +44,16 @@
{
"id": "cull_mode",
"value": "none"
},
{
"id": "dir",
"link": "_vec2y"
}
],
"links": [
{
"id": "dir",
"link": "_vec2y"
},
{
"id": "screenSize",
"link": "_screenSize"
}
],
"texture_params": [],

View file

@ -40,10 +40,6 @@
{
"id": "cull_mode",
"value": "none"
},
{
"id": "dir",
"link": "_vec2y"
}
],
"links": [

View file

@ -5,16 +5,18 @@ precision mediump float;
#endif
uniform sampler2D tex;
uniform vec2 dir;
uniform vec2 screenSize;
in vec2 texCoord;
const vec2 screenSize = vec2(800, 600);
void main() {
vec2 step = dir / screenSize;
vec3 result = texture(tex, texCoord + (step * 4.0)).rgb;
vec3 result = texture(tex, texCoord + (step * 6.0)).rgb;
result += texture(tex, texCoord + (step * 5.0)).rgb;
result += texture(tex, texCoord + (step * 4.0)).rgb;
result += texture(tex, texCoord + (step * 3.0)).rgb;
result += texture(tex, texCoord + (step * 2.0)).rgb;
result += texture(tex, texCoord + step).rgb;
@ -23,7 +25,9 @@ void main() {
result += texture(tex, texCoord - (step * 2.0)).rgb;
result += texture(tex, texCoord - (step * 3.0)).rgb;
result += texture(tex, texCoord - (step * 4.0)).rgb;
result /= vec3(9.0);
result += texture(tex, texCoord - (step * 5.0)).rgb;
result += texture(tex, texCoord - (step * 6.0)).rgb;
result /= vec3(13.0);
// vec3 result = texture(tex, texCoord + (step * 8.0)).rgb;
// result += texture(tex, texCoord + (step * 7.0)).rgb;

View file

@ -20,6 +20,10 @@
{
"id": "dir",
"link": "_vec2x"
},
{
"id": "screenSize",
"link": "_screenSize"
}
],
"texture_params": [],
@ -40,16 +44,78 @@
{
"id": "cull_mode",
"value": "none"
},
{
"id": "dir",
"link": "_vec2y"
}
],
"links": [
{
"id": "dir",
"link": "_vec2y"
},
{
"id": "screenSize",
"link": "_screenSize"
}
],
"texture_params": [],
"vertex_shader": "blur_pass.vert.glsl",
"fragment_shader": "blur_pass.frag.glsl"
},
{
"id": "blur_pass_x2",
"params": [
{
"id": "depth_write",
"value": "true"
},
{
"id": "compare_mode",
"value": "always"
},
{
"id": "cull_mode",
"value": "none"
}
],
"links": [
{
"id": "dir",
"link": "_vec2x2"
},
{
"id": "screenSize",
"link": "_screenSize"
}
],
"texture_params": [],
"vertex_shader": "blur_pass.vert.glsl",
"fragment_shader": "blur_pass.frag.glsl"
},
{
"id": "blur_pass_y2",
"params": [
{
"id": "depth_write",
"value": "true"
},
{
"id": "compare_mode",
"value": "always"
},
{
"id": "cull_mode",
"value": "none"
}
],
"links": [
{
"id": "dir",
"link": "_vec2y2"
},
{
"id": "screenSize",
"link": "_screenSize"
}
],
"texture_params": [],

View file

@ -0,0 +1,13 @@
#version 450
#ifdef GL_ES
precision mediump float;
#endif
uniform sampler2D tex;
in vec2 texCoord;
void main() {
gl_FragColor = texture(tex, texCoord);
}

View file

@ -0,0 +1,25 @@
{
"contexts": [
{
"id": "copy_pass",
"params": [
{
"id": "depth_write",
"value": "true"
},
{
"id": "compare_mode",
"value": "always"
},
{
"id": "cull_mode",
"value": "none"
}
],
"links": [],
"texture_params": [],
"vertex_shader": "copy_pass.vert.glsl",
"fragment_shader": "copy_pass.frag.glsl"
}
]
}

View file

@ -0,0 +1,18 @@
#version 450
#ifdef GL_ES
precision highp float;
#endif
in vec2 pos;
out vec2 texCoord;
const vec2 madd = vec2(0.5, 0.5);
void main() {
// Scale vertex attribute to [0-1] range
texCoord = pos.xy * madd + madd;
gl_Position = vec4(pos.xy, 0.0, 1.0);
}

View file

@ -7,9 +7,9 @@ precision mediump float;
#ifdef _HMTex
#define _NMTex
#endif
#ifdef _NMTex
#define _AMTex
#endif
// #ifdef _NMTex
// #define _Tex
// #endif
#ifdef _AMTex
uniform sampler2D salbedo;
@ -19,6 +19,8 @@ precision mediump float;
#endif
#ifdef _OMTex
uniform sampler2D som;
#else
uniform float occlusion;
#endif
#ifdef _RMTex
uniform sampler2D srm;
@ -42,7 +44,7 @@ precision mediump float;
#endif
in vec4 mvpposition;
#ifdef _AMTex
#ifdef _Tex
in vec2 texCoord;
#endif
in vec4 lPos;
@ -172,7 +174,7 @@ float parallaxShadow(vec3 L, vec2 initialTexCoord, float initialHeight) {
#endif
void main() {
#ifdef _AMTex
#ifdef _Tex
vec2 newCoord = texCoord;
#endif
@ -211,16 +213,16 @@ void main() {
#endif
#ifdef _OMTex
float occlusion = texture(som, newCoord).r;
float occ = texture(som, newCoord).r;
#else
float occlusion = 1.0;
float occ = occlusion;
#endif
#ifdef _HMTex
occlusion *= shadowMultiplier;
occ *= shadowMultiplier;
#endif
// occlusion - pack with mask
// occ - pack with mask
n /= (abs(n.x) + abs(n.y) + abs(n.z));
n.xy = n.z >= 0.0 ? n.xy : octahedronWrap(n.xy);
@ -236,9 +238,9 @@ void main() {
}
if (dist > 0) mask_probe = 0;
}
gl_FragData[0] = vec4(n.xy, occlusion, mask_probe);
gl_FragData[0] = vec4(n.xy, occ, mask_probe);
#else
gl_FragData[0] = vec4(n.xy, occlusion, mask);
gl_FragData[0] = vec4(n.xy, occ, mask);
#endif
gl_FragData[1] = vec4(baseColor.rgb, packFloat(roughness, metalness));
}

View file

@ -7,13 +7,13 @@ precision highp float;
#ifdef _HMTex
#define _NMTex
#endif
#ifdef _NMTex
#define _AMTex
#endif
// #ifdef _NMTex
// #define _Tex
// #endif
in vec3 pos;
in vec3 nor;
#ifdef _AMTex
#ifdef _Tex
in vec2 tex;
#endif
#ifdef _VCols
@ -49,7 +49,7 @@ uniform vec4 albedo_color;
out vec4 mvpposition;
#ifdef _AMTex
#ifdef _Tex
out vec2 texCoord;
#endif
out vec4 lPos;
@ -131,7 +131,7 @@ void main() {
gl_Position = P * MV * sPos;
#ifdef _AMTex
#ifdef _Tex
texCoord = tex;
#endif

View file

@ -419,7 +419,8 @@ float shadowTest(vec4 lPos) {
lPosH.x = (lPosH.x + 1.0) / 2.0;
lPosH.y = (lPosH.y + 1.0) / 2.0;
const float bias = 0.00015; // Persp
// const float bias = 0.00015; // Persp
const float bias = 0.00005; // Persp
// const float bias = 0.01; // Ortho
#ifdef _PCSS

View file

@ -47,7 +47,7 @@ void main() {
// }
vec3 n = normalize(normal);
gl_FragColor = texture(envmap, envMapEquirect(n)) * envmapStrength;
gl_FragColor = texture(envmap, envMapEquirect(n)) * 3.0;// envmapStrength;
#ifdef _Hosek
vec3 sunDir = vec3(sunDirection.x, -sunDirection.y, sunDirection.z);

View file

@ -7,12 +7,12 @@ precision mediump float;
#define PI 3.1415926535
#define TwoPI (2.0 * PI)
#ifdef _NMTex
#define _AMTex
#endif
// #ifdef _NMTex
// #define _Tex
// #endif
#ifdef _AMTex
uniform sampler2D salbedo;
uniform sampler2D salbedo;
#endif
uniform sampler2D shadowMap;
uniform sampler2D senvmapRadiance;
@ -21,20 +21,26 @@ uniform sampler2D senvmapBrdf;
// uniform sampler2D sltcMat;
// uniform sampler2D sltcMag;
#ifdef _NMTex
uniform sampler2D snormal;
uniform sampler2D snormal;
#endif
#ifdef _OMTex
uniform sampler2D som;
uniform sampler2D som;
#else
uniform float occlusion;
#endif
#ifdef _RMTex
uniform sampler2D srm;
#else
uniform float roughness;
uniform float roughness;
#endif
#ifdef _MMTex
uniform sampler2D smm;
uniform sampler2D smm;
#else
uniform float metalness;
uniform float metalness;
#endif
#ifdef _HMTex
uniform sampler2D shm;
uniform float heightStrength;
#endif
uniform float envmapStrength;
@ -67,17 +73,17 @@ vec3 L4 = vec3(0.0);
in vec3 position;
#ifdef _AMTex
in vec2 texCoord;
#ifdef _Tex
in vec2 texCoord;
#endif
in vec4 lPos;
in vec4 matColor;
in vec3 lightDir;
in vec3 eyeDir;
#ifdef _NMTex
in mat3 TBN;
in mat3 TBN;
#else
in vec3 normal;
in vec3 normal;
#endif
// float linstep(float low, float high, float v) {
@ -657,7 +663,9 @@ void main() {
outColor = vec4(vec3(direct * visibility + indirect), 1.0);
#ifdef _OMTex
vec3 occlusion = texture(som, texCoord).rgb;
vec3 occ = texture(som, texCoord).rgb;
outColor.rgb *= occ;
#else
outColor.rgb *= occlusion;
#endif
// LTC

View file

@ -5,7 +5,7 @@ precision highp float;
#endif
#ifdef _NMTex
#define _AMTex
#define _Tex
#endif
in vec3 pos;
@ -40,7 +40,7 @@ uniform float skinBones[50 * 12];
#endif
out vec3 position;
#ifdef _AMTex
#ifdef _Tex
out vec2 texCoord;
#endif
out vec4 lPos;
@ -113,7 +113,7 @@ void main() {
gl_Position = P * VM * sPos;
#ifdef _AMTex
#ifdef _Tex
texCoord = tex;
#endif

View file

@ -10,12 +10,11 @@ const float FXAA_SPAN_MAX = 8.0;
uniform sampler2D tex;
uniform vec2 texStep; // screenSizeInv
in vec2 texCoord;
void main() {
const vec2 resolution = vec2(1920.0, 1080.0);
vec2 texStep = 1.0 / resolution.xy;
void main() {
vec2 tcrgbNW = (texCoord + vec2(-1.0, -1.0) * texStep);
vec2 tcrgbNE = (texCoord + vec2(1.0, -1.0) * texStep);
vec2 tcrgbSW = (texCoord + vec2(-1.0, 1.0) * texStep);

View file

@ -16,7 +16,12 @@
"value": "none"
}
],
"links": [],
"links": [
{
"id": "texStep",
"link": "_screenSizeInv"
}
],
"texture_params": [],
"vertex_shader": "fxaa_pass.vert.glsl",
"fragment_shader": "fxaa_pass.frag.glsl"

View file

@ -16,8 +16,8 @@ precision mediump float;
#define SMAA_AREATEX_SELECT(sample) sample.rg
#define SMAA_SEARCHTEX_SELECT(sample) sample.r
#define SMAA_RT_METRICS vec4(1.0 / 1920.0, 1.0 / 1080.0, 1920.0, 1080.0)
#define SMAASampleLevelZeroOffset(tex, coord, offset) textureLod(tex, coord + offset * SMAA_RT_METRICS.xy, 0.0)
// #define SMAA_RT_METRICS vec4(1.0 / 800.0, 1.0 / 600.0, 800.0, 600.0)
#define SMAASampleLevelZeroOffset(tex, coord, offset) textureLod(tex, coord + offset * screenSizeInv.xy, 0.0)
#define mad(a, b, c) (a * b + c)
#define saturate(a) clamp(a, 0.0, 1.0)
#define round(a) floor(a + 0.5)
@ -28,6 +28,9 @@ uniform sampler2D edgesTex;
uniform sampler2D areaTex;
uniform sampler2D searchTex;
uniform vec2 screenSize;
uniform vec2 screenSizeInv;
in vec2 texCoord;
in vec2 pixcoord;
// in vec4 offset[3];
@ -83,7 +86,7 @@ vec4 SMAADecodeDiagBilinearAccess(vec4 e) {
*/
vec2 SMAASearchDiag1(/*sampler2D edgesTex,*/ vec2 texcoord, vec2 dir/*, out vec2 e*/) {
vec4 coord = vec4(texcoord, -1.0, 1.0);
vec3 t = vec3(SMAA_RT_METRICS.xy, 1.0);
vec3 t = vec3(screenSizeInv.xy, 1.0);
if (coord.w <= 0.9) return coord.zw; //
if (coord.z >= float(SMAA_MAX_SEARCH_STEPS_DIAG - 1)) return coord.zw; //
@ -123,8 +126,8 @@ vec2 SMAASearchDiag1(/*sampler2D edgesTex,*/ vec2 texcoord, vec2 dir/*, out vec2
vec2 SMAASearchDiag2(/*sampler2D edgesTex,*/ vec2 texcoord, vec2 dir/*, out vec2 e*/) {
vec4 coord = vec4(texcoord, -1.0, 1.0);
coord.x += 0.25 * SMAA_RT_METRICS.x; // See @SearchDiag2Optimization
vec3 t = vec3(SMAA_RT_METRICS.xy, 1.0);
coord.x += 0.25 * screenSizeInv.x; // See @SearchDiag2Optimization
vec3 t = vec3(screenSizeInv.xy, 1.0);
if (coord.w <= 0.9) return coord.zw; //
if (coord.z >= float(SMAA_MAX_SEARCH_STEPS_DIAG - 1)) return coord.zw; //
@ -214,7 +217,7 @@ vec2 SMAACalculateDiagWeights(/*sampler2D edgesTex, sampler2D areaTex,*/ vec2 te
//SMAA_BRANCH
if (d.x + d.y > 2.0) { // d.x + d.y + 1 > 3
// Fetch the crossing edges:
vec4 coords = mad(vec4(-d.x + 0.25, d.x, d.y, -d.y - 0.25), SMAA_RT_METRICS.xyxy, texcoord.xyxy);
vec4 coords = mad(vec4(-d.x + 0.25, d.x, d.y, -d.y - 0.25), screenSizeInv.xyxy, texcoord.xyxy);
vec4 c;
c.xy = SMAASampleLevelZeroOffset(edgesTex, coords.xy, ivec2(-1, 0)).rg;
@ -222,7 +225,7 @@ vec2 SMAACalculateDiagWeights(/*sampler2D edgesTex, sampler2D areaTex,*/ vec2 te
c.yxwz = SMAADecodeDiagBilinearAccess(c.xyzw);
// Non-optimized version:
// vec4 coords = mad(vec4(-d.x, d.x, d.y, -d.y), SMAA_RT_METRICS.xyxy, texcoord.xyxy);
// vec4 coords = mad(vec4(-d.x, d.x, d.y, -d.y), screenSizeInv.xyxy, texcoord.xyxy);
// vec4 c;
// c.x = SMAASampleLevelZeroOffset(edgesTex, coords.xy, ivec2(-1, 0)).g;
// c.y = SMAASampleLevelZeroOffset(edgesTex, coords.xy, ivec2( 0, 0)).r;
@ -256,7 +259,7 @@ vec2 SMAACalculateDiagWeights(/*sampler2D edgesTex, sampler2D areaTex,*/ vec2 te
// SMAA_BRANCH
if (d.x + d.y > 2.0) { // d.x + d.y + 1 > 3
// Fetch the crossing edges:
vec4 coords = mad(vec4(-d.x, -d.x, d.y, d.y), SMAA_RT_METRICS.xyxy, texcoord.xyxy);
vec4 coords = mad(vec4(-d.x, -d.x, d.y, d.y), screenSizeInv.xyxy, texcoord.xyxy);
vec4 c;
c.x = SMAASampleLevelZeroOffset(edgesTex, coords.xy, ivec2(-1, 0)).g;
c.y = SMAASampleLevelZeroOffset(edgesTex, coords.xy, ivec2( 0, -1)).r;
@ -311,7 +314,7 @@ float SMAASearchLength(/*sampler2D searchTex,*/ vec2 e, float offset) {
*/
float endLoopXLeft(vec2 texcoord, vec2 e) {
float offset = mad(-(255.0 / 127.0), SMAASearchLength(/*searchTex,*/ e, 0.0), 3.25);
return mad(SMAA_RT_METRICS.x, offset, texcoord.x);
return mad(screenSizeInv.x, offset, texcoord.x);
}
float SMAASearchXLeft(/*sampler2D edgesTex, sampler2D searchTex,*/ vec2 texcoord, float end) {
/**
@ -330,65 +333,65 @@ float SMAASearchXLeft(/*sampler2D edgesTex, sampler2D searchTex,*/ vec2 texcoord
// e.g > 0.8281 && // Is there some edge not activated?
// e.r == 0.0) { // Or is there a crossing edge that breaks the line?
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(-vec2(2.0, 0.0), SMAA_RT_METRICS.xy, texcoord);
texcoord = mad(-vec2(2.0, 0.0), screenSizeInv.xy, texcoord);
// Waiting for loops
if (texcoord.x <= end) return endLoopXLeft(texcoord, e); //
if (e.g <= 0.8281) return endLoopXLeft(texcoord, e);
if (e.r != 0.0) return endLoopXLeft(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(-vec2(2.0, 0.0), SMAA_RT_METRICS.xy, texcoord);
texcoord = mad(-vec2(2.0, 0.0), screenSizeInv.xy, texcoord);
if (texcoord.x <= end) return endLoopXLeft(texcoord, e); //
if (e.g <= 0.8281) return endLoopXLeft(texcoord, e);
if (e.r != 0.0) return endLoopXLeft(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(-vec2(2.0, 0.0), SMAA_RT_METRICS.xy, texcoord);
texcoord = mad(-vec2(2.0, 0.0), screenSizeInv.xy, texcoord);
if (texcoord.x <= end) return endLoopXLeft(texcoord, e); //
if (e.g <= 0.8281) return endLoopXLeft(texcoord, e);
if (e.r != 0.0) return endLoopXLeft(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(-vec2(2.0, 0.0), SMAA_RT_METRICS.xy, texcoord);
texcoord = mad(-vec2(2.0, 0.0), screenSizeInv.xy, texcoord);
if (texcoord.x <= end) return endLoopXLeft(texcoord, e); //
if (e.g <= 0.8281) return endLoopXLeft(texcoord, e);
if (e.r != 0.0) return endLoopXLeft(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(-vec2(2.0, 0.0), SMAA_RT_METRICS.xy, texcoord);
texcoord = mad(-vec2(2.0, 0.0), screenSizeInv.xy, texcoord);
if (texcoord.x <= end) return endLoopXLeft(texcoord, e); //
if (e.g <= 0.8281) return endLoopXLeft(texcoord, e);
if (e.r != 0.0) return endLoopXLeft(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(-vec2(2.0, 0.0), SMAA_RT_METRICS.xy, texcoord);
texcoord = mad(-vec2(2.0, 0.0), screenSizeInv.xy, texcoord);
if (texcoord.x <= end) return endLoopXLeft(texcoord, e); //
if (e.g <= 0.8281) return endLoopXLeft(texcoord, e);
if (e.r != 0.0) return endLoopXLeft(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(-vec2(2.0, 0.0), SMAA_RT_METRICS.xy, texcoord);
texcoord = mad(-vec2(2.0, 0.0), screenSizeInv.xy, texcoord);
if (texcoord.x <= end) return endLoopXLeft(texcoord, e); //
if (e.g <= 0.8281) return endLoopXLeft(texcoord, e);
if (e.r != 0.0) return endLoopXLeft(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(-vec2(2.0, 0.0), SMAA_RT_METRICS.xy, texcoord);
texcoord = mad(-vec2(2.0, 0.0), screenSizeInv.xy, texcoord);
// }
float offset = mad(-(255.0 / 127.0), SMAASearchLength(/*searchTex,*/ e, 0.0), 3.25);
return mad(SMAA_RT_METRICS.x, offset, texcoord.x);
return mad(screenSizeInv.x, offset, texcoord.x);
// Non-optimized version:
// We correct the previous (-0.25, -0.125) offset we applied:
// texcoord.x += 0.25 * SMAA_RT_METRICS.x;
// texcoord.x += 0.25 * screenSizeInv.x;
// The searches are bias by 1, so adjust the coords accordingly:
// texcoord.x += SMAA_RT_METRICS.x;
// texcoord.x += screenSizeInv.x;
// Disambiguate the length added by the last step:
// texcoord.x += 2.0 * SMAA_RT_METRICS.x; // Undo last step
// texcoord.x -= SMAA_RT_METRICS.x * (255.0 / 127.0) * SMAASearchLength(/*searchTex,*/ e, 0.0);
// return mad(SMAA_RT_METRICS.x, offset, texcoord.x);
// texcoord.x += 2.0 * screenSizeInv.x; // Undo last step
// texcoord.x -= screenSizeInv.x * (255.0 / 127.0) * SMAASearchLength(/*searchTex,*/ e, 0.0);
// return mad(screenSizeInv.x, offset, texcoord.x);
}
float endLoopXRight(vec2 texcoord, vec2 e) {
float offset = mad(-(255.0 / 127.0), SMAASearchLength(/*searchTex,*/ e, 0.5), 3.25);
return mad(-SMAA_RT_METRICS.x, offset, texcoord.x);
return mad(-screenSizeInv.x, offset, texcoord.x);
}
float SMAASearchXRight(/*sampler2D edgesTex, sampler2D searchTex,*/ vec2 texcoord, float end) {
vec2 e = vec2(0.0, 1.0);
@ -400,53 +403,53 @@ float SMAASearchXRight(/*sampler2D edgesTex, sampler2D searchTex,*/ vec2 texcoor
// e.g > 0.8281 && // Is there some edge not activated?
// e.r == 0.0) { // Or is there a crossing edge that breaks the line?
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(vec2(2.0, 0.0), SMAA_RT_METRICS.xy, texcoord);
texcoord = mad(vec2(2.0, 0.0), screenSizeInv.xy, texcoord);
// Waiting for loops
if (texcoord.x >= end) return endLoopXRight(texcoord, e); //
if (e.g <= 0.8281) return endLoopXRight(texcoord, e);
if (e.r != 0.0) return endLoopXRight(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(vec2(2.0, 0.0), SMAA_RT_METRICS.xy, texcoord);
texcoord = mad(vec2(2.0, 0.0), screenSizeInv.xy, texcoord);
if (texcoord.x >= end) return endLoopXRight(texcoord, e); //
if (e.g <= 0.8281) return endLoopXRight(texcoord, e);
if (e.r != 0.0) return endLoopXRight(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(vec2(2.0, 0.0), SMAA_RT_METRICS.xy, texcoord);
texcoord = mad(vec2(2.0, 0.0), screenSizeInv.xy, texcoord);
if (texcoord.x >= end) return endLoopXRight(texcoord, e); //
if (e.g <= 0.8281) return endLoopXRight(texcoord, e);
if (e.r != 0.0) return endLoopXRight(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(vec2(2.0, 0.0), SMAA_RT_METRICS.xy, texcoord);
texcoord = mad(vec2(2.0, 0.0), screenSizeInv.xy, texcoord);
if (texcoord.x >= end) return endLoopXRight(texcoord, e); //
if (e.g <= 0.8281) return endLoopXRight(texcoord, e);
if (e.r != 0.0) return endLoopXRight(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(vec2(2.0, 0.0), SMAA_RT_METRICS.xy, texcoord);
texcoord = mad(vec2(2.0, 0.0), screenSizeInv.xy, texcoord);
if (texcoord.x >= end) return endLoopXRight(texcoord, e); //
if (e.g <= 0.8281) return endLoopXRight(texcoord, e);
if (e.r != 0.0) return endLoopXRight(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(vec2(2.0, 0.0), SMAA_RT_METRICS.xy, texcoord);
texcoord = mad(vec2(2.0, 0.0), screenSizeInv.xy, texcoord);
if (texcoord.x >= end) return endLoopXRight(texcoord, e); //
if (e.g <= 0.8281) return endLoopXRight(texcoord, e);
if (e.r != 0.0) return endLoopXRight(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(vec2(2.0, 0.0), SMAA_RT_METRICS.xy, texcoord);
texcoord = mad(vec2(2.0, 0.0), screenSizeInv.xy, texcoord);
if (texcoord.x >= end) return endLoopXRight(texcoord, e); //
if (e.g <= 0.8281) return endLoopXRight(texcoord, e);
if (e.r != 0.0) return endLoopXRight(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(vec2(2.0, 0.0), SMAA_RT_METRICS.xy, texcoord);
texcoord = mad(vec2(2.0, 0.0), screenSizeInv.xy, texcoord);
// }
float offset = mad(-(255.0 / 127.0), SMAASearchLength(/*searchTex,*/ e, 0.5), 3.25);
return mad(-SMAA_RT_METRICS.x, offset, texcoord.x);
return mad(-screenSizeInv.x, offset, texcoord.x);
}
float endLoopYUp(vec2 texcoord, vec2 e) {
float offset = mad(-(255.0 / 127.0), SMAASearchLength(/*searchTex,*/ e.gr, 0.0), 3.25);
return mad(SMAA_RT_METRICS.y, offset, texcoord.y);
return mad(screenSizeInv.y, offset, texcoord.y);
}
float SMAASearchYUp(/*sampler2D edgesTex, sampler2D searchTex,*/ vec2 texcoord, float end) {
vec2 e = vec2(1.0, 0.0);
@ -458,53 +461,53 @@ float SMAASearchYUp(/*sampler2D edgesTex, sampler2D searchTex,*/ vec2 texcoord,
// e.r > 0.8281 && // Is there some edge not activated?
// e.g == 0.0) { // Or is there a crossing edge that breaks the line?
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(-vec2(0.0, 2.0), SMAA_RT_METRICS.xy, texcoord);
texcoord = mad(-vec2(0.0, 2.0), screenSizeInv.xy, texcoord);
// Waiting for loops
if (texcoord.y <= end) return endLoopYUp(texcoord, e); //
if (e.r <= 0.8281) return endLoopYUp(texcoord, e);
if (e.g != 0.0) return endLoopYUp(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(-vec2(0.0, 2.0), SMAA_RT_METRICS.xy, texcoord);
texcoord = mad(-vec2(0.0, 2.0), screenSizeInv.xy, texcoord);
if (texcoord.y <= end) return endLoopYUp(texcoord, e); //
if (e.r <= 0.8281) return endLoopYUp(texcoord, e);
if (e.g != 0.0) return endLoopYUp(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(-vec2(0.0, 2.0), SMAA_RT_METRICS.xy, texcoord);
texcoord = mad(-vec2(0.0, 2.0), screenSizeInv.xy, texcoord);
if (texcoord.y <= end) return endLoopYUp(texcoord, e); //
if (e.r <= 0.8281) return endLoopYUp(texcoord, e);
if (e.g != 0.0) return endLoopYUp(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(-vec2(0.0, 2.0), SMAA_RT_METRICS.xy, texcoord);
texcoord = mad(-vec2(0.0, 2.0), screenSizeInv.xy, texcoord);
if (texcoord.y <= end) return endLoopYUp(texcoord, e); //
if (e.r <= 0.8281) return endLoopYUp(texcoord, e);
if (e.g != 0.0) return endLoopYUp(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(-vec2(0.0, 2.0), SMAA_RT_METRICS.xy, texcoord);
texcoord = mad(-vec2(0.0, 2.0), screenSizeInv.xy, texcoord);
if (texcoord.y <= end) return endLoopYUp(texcoord, e); //
if (e.r <= 0.8281) return endLoopYUp(texcoord, e);
if (e.g != 0.0) return endLoopYUp(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(-vec2(0.0, 2.0), SMAA_RT_METRICS.xy, texcoord);
texcoord = mad(-vec2(0.0, 2.0), screenSizeInv.xy, texcoord);
if (texcoord.y <= end) return endLoopYUp(texcoord, e); //
if (e.r <= 0.8281) return endLoopYUp(texcoord, e);
if (e.g != 0.0) return endLoopYUp(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(-vec2(0.0, 2.0), SMAA_RT_METRICS.xy, texcoord);
texcoord = mad(-vec2(0.0, 2.0), screenSizeInv.xy, texcoord);
if (texcoord.y <= end) return endLoopYUp(texcoord, e); //
if (e.r <= 0.8281) return endLoopYUp(texcoord, e);
if (e.g != 0.0) return endLoopYUp(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(-vec2(0.0, 2.0), SMAA_RT_METRICS.xy, texcoord);
texcoord = mad(-vec2(0.0, 2.0), screenSizeInv.xy, texcoord);
// }
float offset = mad(-(255.0 / 127.0), SMAASearchLength(/*searchTex,*/ e.gr, 0.0), 3.25);
return mad(SMAA_RT_METRICS.y, offset, texcoord.y);
return mad(screenSizeInv.y, offset, texcoord.y);
}
float endLoopYDown(vec2 texcoord, vec2 e) {
float offset = mad(-(255.0 / 127.0), SMAASearchLength(/*searchTex,*/ e.gr, 0.5), 3.25);
return mad(-SMAA_RT_METRICS.y, offset, texcoord.y);
return mad(-screenSizeInv.y, offset, texcoord.y);
}
float SMAASearchYDown(/*sampler2D edgesTex, sampler2D searchTex,*/ vec2 texcoord, float end) {
vec2 e = vec2(1.0, 0.0);
@ -516,48 +519,48 @@ float SMAASearchYDown(/*sampler2D edgesTex, sampler2D searchTex,*/ vec2 texcoord
// e.r > 0.8281 && // Is there some edge not activated?
// e.g == 0.0) { // Or is there a crossing edge that breaks the line?
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(vec2(0.0, 2.0), SMAA_RT_METRICS.xy, texcoord);
texcoord = mad(vec2(0.0, 2.0), screenSizeInv.xy, texcoord);
// Waiting for loops
if (texcoord.y >= end) return endLoopYDown(texcoord, e); //
if (e.r <= 0.8281) return endLoopYDown(texcoord, e);
if (e.g != 0.0) return endLoopYDown(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(vec2(0.0, 2.0), SMAA_RT_METRICS.xy, texcoord);
texcoord = mad(vec2(0.0, 2.0), screenSizeInv.xy, texcoord);
if (texcoord.y >= end) return endLoopYDown(texcoord, e); //
if (e.r <= 0.8281) return endLoopYDown(texcoord, e);
if (e.g != 0.0) return endLoopYDown(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(vec2(0.0, 2.0), SMAA_RT_METRICS.xy, texcoord);
texcoord = mad(vec2(0.0, 2.0), screenSizeInv.xy, texcoord);
if (texcoord.y >= end) return endLoopYDown(texcoord, e); //
if (e.r <= 0.8281) return endLoopYDown(texcoord, e);
if (e.g != 0.0) return endLoopYDown(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(vec2(0.0, 2.0), SMAA_RT_METRICS.xy, texcoord);
texcoord = mad(vec2(0.0, 2.0), screenSizeInv.xy, texcoord);
if (texcoord.y >= end) return endLoopYDown(texcoord, e); //
if (e.r <= 0.8281) return endLoopYDown(texcoord, e);
if (e.g != 0.0) return endLoopYDown(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(vec2(0.0, 2.0), SMAA_RT_METRICS.xy, texcoord);
texcoord = mad(vec2(0.0, 2.0), screenSizeInv.xy, texcoord);
if (texcoord.y >= end) return endLoopYDown(texcoord, e); //
if (e.r <= 0.8281) return endLoopYDown(texcoord, e);
if (e.g != 0.0) return endLoopYDown(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(vec2(0.0, 2.0), SMAA_RT_METRICS.xy, texcoord);
texcoord = mad(vec2(0.0, 2.0), screenSizeInv.xy, texcoord);
if (texcoord.y >= end) return endLoopYDown(texcoord, e); //
if (e.r <= 0.8281) return endLoopYDown(texcoord, e);
if (e.g != 0.0) return endLoopYDown(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(vec2(0.0, 2.0), SMAA_RT_METRICS.xy, texcoord);
texcoord = mad(vec2(0.0, 2.0), screenSizeInv.xy, texcoord);
if (texcoord.y >= end) return endLoopYDown(texcoord, e); //
if (e.r <= 0.8281) return endLoopYDown(texcoord, e);
if (e.g != 0.0) return endLoopYDown(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(vec2(0.0, 2.0), SMAA_RT_METRICS.xy, texcoord);
texcoord = mad(vec2(0.0, 2.0), screenSizeInv.xy, texcoord);
// }
float offset = mad(-(255.0 / 127.0), SMAASearchLength(/*searchTex,*/ e.gr, 0.5), 3.25);
return mad(-SMAA_RT_METRICS.y, offset, texcoord.y);
return mad(-screenSizeInv.y, offset, texcoord.y);
}
/**
@ -643,7 +646,7 @@ vec4 SMAABlendingWeightCalculationPS(vec2 texcoord, vec2 pixcoord, /*vec4 offset
// Find the distance to the left:
vec3 coords;
coords.x = SMAASearchXLeft(/*edgesTex, searchTex,*/ offset0.xy, offset2.x);
coords.y = offset1.y; // offset[1].y = texcoord.y - 0.25 * SMAA_RT_METRICS.y (@CROSSING_OFFSET)
coords.y = offset1.y; // offset[1].y = texcoord.y - 0.25 * screenSizeInv.y (@CROSSING_OFFSET)
d.x = coords.x;
// Now fetch the left crossing edges, two at a time using bilinear
@ -657,7 +660,7 @@ vec4 SMAABlendingWeightCalculationPS(vec2 texcoord, vec2 pixcoord, /*vec4 offset
// We want the distances to be in pixel units (doing this here allow to
// better interleave arithmetic and memory accesses):
d = abs(round(mad(SMAA_RT_METRICS.zz, d, -pixcoord.xx)));
d = abs(round(mad(screenSize.xx, d, -pixcoord.xx)));
// SMAAArea below needs a sqrt, as the areas texture is compressed
// quadratically:
@ -689,7 +692,7 @@ vec4 SMAABlendingWeightCalculationPS(vec2 texcoord, vec2 pixcoord, /*vec4 offset
// Find the distance to the top:
vec3 coords;
coords.y = SMAASearchYUp(/*edgesTex, searchTex,*/ offset1.xy, offset2.z);
coords.x = offset0.x; // offset[1].x = texcoord.x - 0.25 * SMAA_RT_METRICS.x;
coords.x = offset0.x; // offset[1].x = texcoord.x - 0.25 * screenSizeInv.x;
d.x = coords.y;
// Fetch the top crossing edges:
@ -700,7 +703,7 @@ vec4 SMAABlendingWeightCalculationPS(vec2 texcoord, vec2 pixcoord, /*vec4 offset
d.y = coords.z;
// We want the distances to be in pixel units:
d = abs(round(mad(SMAA_RT_METRICS.ww, d, -pixcoord.yy)));
d = abs(round(mad(screenSize.yy, d, -pixcoord.yy)));
// SMAAArea below needs a sqrt, as the areas texture is compressed
// quadratically:

View file

@ -24,6 +24,14 @@
{
"id": "searchTex",
"link": "_smaaSearch"
},
{
"id": "screenSize",
"link": "_screenSize"
},
{
"id": "screenSizeInv",
"link": "_screenSizeInv"
}
],
"texture_params": [],

View file

@ -4,11 +4,11 @@
precision highp float;
#endif
#define SMAA_RT_METRICS vec4(1.0 / 1920.0, 1.0 / 1080.0, 1920.0, 1080.0)
#define SMAA_MAX_SEARCH_STEPS 16
in vec2 pos;
uniform vec2 screenSize;
uniform vec2 screenSizeInv;
out vec2 texCoord;
out vec2 pixcoord;
// out vec4 offset[3];
@ -16,6 +16,7 @@ out vec4 offset0;
out vec4 offset1;
out vec4 offset2;
const int SMAA_MAX_SEARCH_STEPS = 16;
const vec2 madd = vec2(0.5, 0.5);
void main() {
@ -24,14 +25,14 @@ void main() {
// Blend Weight Calculation Vertex Shader
// void SMAABlendingWeightCalculationVS(vec2 texcoord, out vec2 pixcoord, out vec4 offset[3]) {
pixcoord = texCoord * SMAA_RT_METRICS.zw;
pixcoord = texCoord * screenSize;
// We will use these offsets for the searches later on (see @PSEUDO_GATHER4):
offset0 = SMAA_RT_METRICS.xyxy * vec4(-0.25, -0.125, 1.25, -0.125) + texCoord.xyxy;
offset1 = SMAA_RT_METRICS.xyxy * vec4(-0.125, -0.25, -0.125, 1.25) + texCoord.xyxy;
offset0 = screenSizeInv.xyxy * vec4(-0.25, -0.125, 1.25, -0.125) + texCoord.xyxy;
offset1 = screenSizeInv.xyxy * vec4(-0.125, -0.25, -0.125, 1.25) + texCoord.xyxy;
// And these for the searches, they indicate the ends of the loops:
offset2 = SMAA_RT_METRICS.xxyy *
offset2 = screenSizeInv.xxyy *
(vec4(-2.0, 2.0, -2.0, 2.0) * float(SMAA_MAX_SEARCH_STEPS)) +
vec4(offset0.xz, offset1.yw);
// }

View file

@ -16,7 +16,12 @@
"value": "none"
}
],
"links": [],
"links": [
{
"id": "screenSizeInv",
"link": "_screenSizeInv"
}
],
"texture_params": [],
"vertex_shader": "smaa_edge_detect.vert.glsl",
"fragment_shader": "smaa_edge_detect.frag.glsl"

View file

@ -4,10 +4,10 @@
precision highp float;
#endif
#define SMAA_RT_METRICS vec4(1.0 / 1920.0, 1.0 / 1080.0, 1920.0, 1080.0)
in vec2 pos;
uniform vec2 screenSizeInv;
out vec2 texCoord;
// out vec4 offset[3];
out vec4 offset0;
@ -22,9 +22,9 @@ void main() {
// Edge Detection Vertex Shader
//void SMAAEdgeDetectionVS(vec2 texcoord, out vec4 offset[3]) {
offset0 = SMAA_RT_METRICS.xyxy * vec4(-1.0, 0.0, 0.0, -1.0) + texCoord.xyxy;
offset1 = SMAA_RT_METRICS.xyxy * vec4( 1.0, 0.0, 0.0, 1.0) + texCoord.xyxy;
offset2 = SMAA_RT_METRICS.xyxy * vec4(-2.0, 0.0, 0.0, -2.0) + texCoord.xyxy;
offset0 = screenSizeInv.xyxy * vec4(-1.0, 0.0, 0.0, -1.0) + texCoord.xyxy;
offset1 = screenSizeInv.xyxy * vec4( 1.0, 0.0, 0.0, 1.0) + texCoord.xyxy;
offset2 = screenSizeInv.xyxy * vec4(-2.0, 0.0, 0.0, -2.0) + texCoord.xyxy;
//}
gl_Position = vec4(pos.xy, 0.0, 1.0);

View file

@ -4,11 +4,11 @@
precision mediump float;
#endif
#define SMAA_RT_METRICS vec4(1.0 / 1920.0, 1.0 / 1080.0, 1920.0, 1080.0)
uniform sampler2D colorTex;
uniform sampler2D blendTex;
uniform vec2 screenSizeInv;
in vec2 texCoord;
in vec4 offset;
@ -69,7 +69,7 @@ vec4 SMAANeighborhoodBlendingPS(vec2 texcoord, vec4 offset/*, sampler2D colorTex
blendingWeight /= dot(blendingWeight, vec2(1.0, 1.0));
// Calculate the texture coordinates:
vec4 blendingCoord = blendingOffset * vec4(SMAA_RT_METRICS.xy, -SMAA_RT_METRICS.xy) + texcoord.xyxy;
vec4 blendingCoord = blendingOffset * vec4(screenSizeInv.xy, -screenSizeInv.xy) + texcoord.xyxy;
// We exploit bilinear filtering to mix current pixel with the chosen
// neighbor:

View file

@ -16,7 +16,12 @@
"value": "none"
}
],
"links": [],
"links": [
{
"id": "screenSizeInv",
"link": "_screenSizeInv"
}
],
"texture_params": [],
"vertex_shader": "smaa_neighborhood_blend.vert.glsl",
"fragment_shader": "smaa_neighborhood_blend.frag.glsl"

View file

@ -4,10 +4,10 @@
precision highp float;
#endif
#define SMAA_RT_METRICS vec4(1.0 / 1920.0, 1.0 / 1080.0, 1920.0, 1080.0)
in vec2 pos;
uniform vec2 screenSizeInv;
out vec2 texCoord;
out vec4 offset;
@ -19,7 +19,7 @@ void main() {
// Neighborhood Blending Vertex Shader
//void SMAANeighborhoodBlendingVS(vec2 texcoord, out vec4 offset) {
offset = SMAA_RT_METRICS.xyxy * vec4( 1.0, 0.0, 0.0, 1.0) + texCoord.xyxy;
offset = screenSizeInv.xyxy * vec4(1.0, 0.0, 0.0, 1.0) + texCoord.xyxy;
//}
gl_Position = vec4(pos.xy, 0.0, 1.0);

View file

@ -21,13 +21,13 @@ uniform sampler2D gbufferD;
uniform sampler2D gbuffer0;
uniform sampler2D gbuffer1;
uniform sampler2D snoise;
uniform mat4 invVP;
uniform vec3 eye;
uniform vec2 screenSize;
uniform vec2 aspectRatio;
const float PI = 3.1415926535;
const vec2 screenSize = vec2(1920.0, 1080.0);
const vec2 aspectRatio = vec2(min(1.0, screenSize.y / screenSize.x), min(1.0, screenSize.x / screenSize.y));
const int kernelSize = 20;//12;
const float aoSize = 0.12;
const float strength = 0.55;//0.7;

View file

@ -28,6 +28,14 @@
{
"id": "eye",
"link": "_cameraPosition"
},
{
"id": "screenSize",
"link": "_screenSize"
},
{
"id": "aspectRatio",
"link": "_aspectRatio"
}
],
"texture_params": [],

View file

@ -16,8 +16,8 @@ const int numBinarySearchSteps = 5;
const float rayStep = 0.04;
const float minRayStep = 0.05;
const float searchDist = 2.0;//4.4;
const float falloffExp = 6.0;//3.0;
const float searchDist = 5.0;
const float falloffExp = 5.0;
in vec3 viewRay;
in vec2 texCoord;
@ -25,9 +25,9 @@ in vec2 texCoord;
vec3 hitCoord;
float depth;
// float rand(vec2 co) { // Unreliable
// return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
// }
float rand(vec2 co) { // Unreliable
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}
vec4 getProjectedCoord(vec3 hitCoord) {
vec4 projectedCoord = P * vec4(hitCoord, 1.0);
@ -52,7 +52,7 @@ float getDeltaDepth(vec3 hitCoord) {
return viewPos.z - hitCoord.z;
}
vec3 binarySearch(vec3 dir) {
vec4 binarySearch(vec3 dir) {
// for (int i = 0; i < numBinarySearchSteps; i++) {
dir *= 0.5;
hitCoord -= dir;
@ -61,29 +61,47 @@ vec3 binarySearch(vec3 dir) {
dir *= 0.5;
hitCoord -= dir;
if (getDeltaDepth(hitCoord) < 0.0) hitCoord += dir;
dir *= 0.5;
hitCoord -= dir;
if (getDeltaDepth(hitCoord) < 0.0) hitCoord += dir;
dir *= 0.5;
hitCoord -= dir;
if (getDeltaDepth(hitCoord) < 0.0) hitCoord += dir;
dir *= 0.5;
hitCoord -= dir;
if (getDeltaDepth(hitCoord) < 0.0) hitCoord += dir;
dir *= 0.5;
hitCoord -= dir;
if (getDeltaDepth(hitCoord) < 0.0) hitCoord += dir;
dir *= 0.5;
hitCoord -= dir;
if (getDeltaDepth(hitCoord) < 0.0) hitCoord += dir;
////
// dir *= 0.5;
// hitCoord -= dir;
// if (getDeltaDepth(hitCoord) < 0.0) hitCoord += dir;
// dir *= 0.5;
// hitCoord -= dir;
// if (getDeltaDepth(hitCoord) < 0.0) hitCoord += dir;
// dir *= 0.5;
// hitCoord -= dir;
// if (getDeltaDepth(hitCoord) < 0.0) hitCoord += dir;
// dir *= 0.5;
// hitCoord -= dir;
// if (getDeltaDepth(hitCoord) < 0.0) hitCoord += dir;
// dir *= 0.5;
// hitCoord -= dir;
// if (getDeltaDepth(hitCoord) < 0.0) hitCoord += dir;
// dir *= 0.5;
// hitCoord -= dir;
// if (getDeltaDepth(hitCoord) < 0.0) hitCoord += dir;
// Ugly discard of hits too far away
if (abs(getDeltaDepth(hitCoord)) > 0.01) {
return vec4(0.0);
}
// }
return vec3(getProjectedCoord(hitCoord).xy, 0.0);
return vec4(getProjectedCoord(hitCoord).xy, 0.0, 1.0);
}
vec4 rayCast(vec3 dir) {
@ -91,87 +109,67 @@ vec4 rayCast(vec3 dir) {
// for (int i = 0; i < maxSteps; i++) {
hitCoord += dir;
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
if (getDeltaDepth(hitCoord) > 0.0) return binarySearch(dir);
hitCoord += dir;
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
if (getDeltaDepth(hitCoord) > 0.0) return binarySearch(dir);
hitCoord += dir;
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
if (getDeltaDepth(hitCoord) > 0.0) return binarySearch(dir);
hitCoord += dir;
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
if (getDeltaDepth(hitCoord) > 0.0) return binarySearch(dir);
hitCoord += dir;
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
if (getDeltaDepth(hitCoord) > 0.0) return binarySearch(dir);
hitCoord += dir;
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
if (getDeltaDepth(hitCoord) > 0.0) return binarySearch(dir);
hitCoord += dir;
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
if (getDeltaDepth(hitCoord) > 0.0) return binarySearch(dir);
hitCoord += dir;
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
if (getDeltaDepth(hitCoord) > 0.0) return binarySearch(dir);
hitCoord += dir;
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
if (getDeltaDepth(hitCoord) > 0.0) return binarySearch(dir);
hitCoord += dir;
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
if (getDeltaDepth(hitCoord) > 0.0) return binarySearch(dir);
hitCoord += dir;
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
if (getDeltaDepth(hitCoord) > 0.0) return binarySearch(dir);
hitCoord += dir;
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
if (getDeltaDepth(hitCoord) > 0.0) return binarySearch(dir);
hitCoord += dir;
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
if (getDeltaDepth(hitCoord) > 0.0) return binarySearch(dir);
hitCoord += dir;
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
if (getDeltaDepth(hitCoord) > 0.0) return binarySearch(dir);
hitCoord += dir;
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
if (getDeltaDepth(hitCoord) > 0.0) return binarySearch(dir);
hitCoord += dir;
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
if (getDeltaDepth(hitCoord) > 0.0) return binarySearch(dir);
hitCoord += dir;
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
if (getDeltaDepth(hitCoord) > 0.0) return binarySearch(dir);
hitCoord += dir;
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
hitCoord += dir;
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
hitCoord += dir;
if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
if (getDeltaDepth(hitCoord) > 0.0) return binarySearch(dir);
////
// hitCoord += dir;
// if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
// if (getDeltaDepth(hitCoord) > 0.0) return binarySearch(dir);
// hitCoord += dir;
// if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
// if (getDeltaDepth(hitCoord) > 0.0) return binarySearch(dir);
// hitCoord += dir;
// if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
// if (getDeltaDepth(hitCoord) > 0.0) return binarySearch(dir);
// hitCoord += dir;
// if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
// if (getDeltaDepth(hitCoord) > 0.0) return binarySearch(dir);
// hitCoord += dir;
// if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
// if (getDeltaDepth(hitCoord) > 0.0) return binarySearch(dir);
// hitCoord += dir;
// if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
// if (getDeltaDepth(hitCoord) > 0.0) return binarySearch(dir);
// hitCoord += dir;
// if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
// if (getDeltaDepth(hitCoord) > 0.0) return binarySearch(dir);
// hitCoord += dir;
// if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
// if (getDeltaDepth(hitCoord) > 0.0) return binarySearch(dir);
// hitCoord += dir;
// if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
// if (getDeltaDepth(hitCoord) > 0.0) return binarySearch(dir);
// hitCoord += dir;
// if (getDeltaDepth(hitCoord) > 0.0) return vec4(binarySearch(dir), 1.0);
// if (getDeltaDepth(hitCoord) > 0.0) return binarySearch(dir);
// hitCoord += dir;
// if (getDeltaDepth(hitCoord) > 0.0) return binarySearch(dir);
// hitCoord += dir;
// if (getDeltaDepth(hitCoord) > 0.0) return binarySearch(dir);
// }
return vec4(0.0, 0.0, 0.0, 0.0);
}
@ -189,7 +187,8 @@ vec2 unpackFloat(float f) {
void main() {
float roughness = unpackFloat(texture(gbuffer1, texCoord).a).x;
if (roughness == 1.0) {
gl_FragColor = texture(tex, texCoord);
// gl_FragColor = texture(tex, texCoord);
gl_FragColor = vec4(0.0);
return;
// discard;
}
@ -203,11 +202,12 @@ void main() {
n = normalize(n);
vec4 viewNormal = vec4(n, 1.0);
if (viewNormal.z <= 0.9) {
gl_FragColor = texture(tex, texCoord);
return;
// if (viewNormal.z <= 0.9) {
// gl_FragColor = texture(tex, texCoord);
// gl_FragColor = vec4(0.0);
// return;
// discard; // Only up facing surfaces for now
}
// }
viewNormal = tiV * normalize(viewNormal);
// float d = 1.0 - g0.a;
@ -217,8 +217,8 @@ void main() {
vec3 reflected = normalize(reflect((viewPos.xyz), normalize(viewNormal.xyz)));
hitCoord = viewPos.xyz;
vec3 dir = reflected * max(minRayStep, -viewPos.z);
// vec3 dir = reflected * max(minRayStep, -viewPos.z) * (1.0 - rand(texCoord) * 0.3);
// vec3 dir = reflected * max(minRayStep, -viewPos.z);
vec3 dir = reflected * max(minRayStep, -viewPos.z) * (1.0 - rand(texCoord) * 0.4);
vec4 coords = rayCast(dir);
vec2 deltaCoords = abs(vec2(0.5, 0.5) - coords.xy);
@ -228,12 +228,20 @@ void main() {
screenEdgeFactor * clamp(-reflected.z, 0.0, 1.0) *
clamp((searchDist - length(viewPos.xyz - hitCoord)) * (1.0 / searchDist), 0.0, 1.0) * coords.w;
vec4 texColor = texture(tex, texCoord);
float brightness = dot(texColor.rgb, vec3(0.2126, 0.7152, 0.0722));
intensity *= min(brightness, 1.0);
// float brightness = dot(texColor.rgb, vec3(0.2126, 0.7152, 0.0722));
// intensity *= min(brightness, 1.0);
intensity = clamp(intensity, 0.0, 1.0);
if (intensity == 0.0) { //
gl_FragColor = vec4(0.0);
return;
// discard;
}
vec4 reflCol = vec4(texture(tex, coords.xy).rgb, 1.0);
gl_FragColor = texColor * (1.0 - intensity) + reflCol * intensity;
reflCol = clamp(reflCol, 0.0, 1.0);
// gl_FragColor = texColor * (1.0 - intensity) + reflCol * intensity;
gl_FragColor = reflCol * intensity; //
}