Separate SSRS
This commit is contained in:
parent
fc7528ea9f
commit
5ebaab0a85
|
@ -26,6 +26,9 @@ precision mediump float;
|
|||
#ifdef _SSS
|
||||
#include "../std/sss.glsl"
|
||||
#endif
|
||||
#ifdef _SSRS
|
||||
#include "../std/ssrs.glsl"
|
||||
#endif
|
||||
#include "../std/gbuffer.glsl"
|
||||
|
||||
// #ifdef _VoxelGI
|
||||
|
@ -69,7 +72,7 @@ uniform vec2 spotlightData;
|
|||
#endif
|
||||
uniform vec3 eye;
|
||||
#ifdef _SSRS
|
||||
uniform mat4 VP;
|
||||
//!uniform mat4 VP;
|
||||
#endif
|
||||
|
||||
#ifdef _LampColTex
|
||||
|
@ -103,46 +106,6 @@ float shadowTestCube(const vec3 lp, const vec3 l) {
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef _SSRS
|
||||
vec2 getProjectedCoord(vec3 hitCoord) {
|
||||
vec4 projectedCoord = VP * vec4(hitCoord, 1.0);
|
||||
projectedCoord.xy /= projectedCoord.w;
|
||||
projectedCoord.xy = projectedCoord.xy * 0.5 + 0.5;
|
||||
#ifdef _InvY
|
||||
projectedCoord.y = 1.0 - projectedCoord.y;
|
||||
#endif
|
||||
return projectedCoord.xy;
|
||||
}
|
||||
float getDeltaDepth(vec3 hitCoord) {
|
||||
vec2 texCoord = getProjectedCoord(hitCoord);
|
||||
// #ifdef _InvY // D3D
|
||||
// float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
|
||||
// #else
|
||||
// TODO: store_depth
|
||||
vec4 g0 = texture(gbuffer0, texCoord);
|
||||
float depth = (1.0 - g0.a) * 2.0 - 1.0;
|
||||
// #endif
|
||||
vec3 wpos = getPos2(invVP, depth, texCoord);
|
||||
float d1 = length(eye - wpos);
|
||||
float d2 = length(eye - hitCoord);
|
||||
return d1 - d2;
|
||||
}
|
||||
float traceShadow(vec3 dir, vec3 hitCoord) {
|
||||
dir *= ssrsRayStep;
|
||||
// for (int i = 0; i < maxSteps; i++) {
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) return 0.0;
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) return 0.0;
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) return 0.0;
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) return 0.0;
|
||||
//}
|
||||
return 1.0;
|
||||
}
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
vec2 texCoord = wvpposition.xy / wvpposition.w;
|
||||
texCoord = texCoord * 0.5 + 0.5;
|
||||
|
@ -337,7 +300,7 @@ void main() {
|
|||
#endif
|
||||
|
||||
#ifdef _SSRS
|
||||
float tvis = traceShadow(-l, p);
|
||||
float tvis = traceShadow(-l, p, gbuffer0, invVP, eye);
|
||||
// vec2 coords = getProjectedCoord(hitCoord);
|
||||
// vec2 deltaCoords = abs(vec2(0.5, 0.5) - coords.xy);
|
||||
// float screenEdgeFactor = clamp(1.0 - (deltaCoords.x + deltaCoords.y), 0.0, 1.0);
|
||||
|
|
|
@ -17,6 +17,9 @@ precision mediump float;
|
|||
#ifdef _SSS
|
||||
#include "../std/sss.glsl"
|
||||
#endif
|
||||
#ifdef _SSRS
|
||||
#include "../std/ssrs.glsl"
|
||||
#endif
|
||||
#include "../std/gbuffer.glsl"
|
||||
|
||||
uniform sampler2D gbufferD;
|
||||
|
@ -39,7 +42,8 @@ uniform float shadowsBias;
|
|||
uniform vec3 eye;
|
||||
uniform vec3 eyeLook;
|
||||
#ifdef _SSRS
|
||||
uniform mat4 VP;
|
||||
//!uniform mat4 VP;
|
||||
uniform mat4 invVP;
|
||||
#endif
|
||||
|
||||
#ifdef _LampColTex
|
||||
|
@ -71,43 +75,6 @@ float shadowTest(const vec3 lPos) {
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef _SSRS
|
||||
vec2 getProjectedCoord(vec3 hitCoord) {
|
||||
vec4 projectedCoord = VP * vec4(hitCoord, 1.0);
|
||||
projectedCoord.xy /= projectedCoord.w;
|
||||
projectedCoord.xy = projectedCoord.xy * 0.5 + 0.5;
|
||||
#ifdef _InvY
|
||||
projectedCoord.y = 1.0 - projectedCoord.y;
|
||||
#endif
|
||||
return projectedCoord.xy;
|
||||
}
|
||||
float getDeltaDepth(vec3 hitCoord) {
|
||||
vec2 texCoord = getProjectedCoord(hitCoord);
|
||||
float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
|
||||
// TODO: store_depth
|
||||
// vec4 g0 = texture(gbuffer0, texCoord);
|
||||
// float depth = (1.0 - g0.a) * 2.0 - 1.0;
|
||||
vec3 wpos = getPos(eye, eyeLook, viewRay, depth);
|
||||
float d1 = length(eye - wpos);
|
||||
float d2 = length(eye - hitCoord);
|
||||
return d1 - d2;
|
||||
}
|
||||
float traceShadow(vec3 dir, vec3 hitCoord) {
|
||||
dir *= ssrsRayStep;
|
||||
// for (int i = 0; i < maxSteps; i++) {
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) return 0.0;
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) return 0.0;
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) return 0.0;
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord) > 0.0) return 0.0;
|
||||
//}
|
||||
return 1.0;
|
||||
}
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
vec4 g0 = texture(gbuffer0, texCoord); // Normal.xy, metallic/roughness, occlusion
|
||||
vec4 g1 = texture(gbuffer1, texCoord); // Basecolor.rgb,
|
||||
|
@ -176,7 +143,7 @@ void main() {
|
|||
#endif
|
||||
|
||||
#ifdef _SSRS
|
||||
float tvis = traceShadow(-l, p);
|
||||
float tvis = traceShadow(-l, p, gbuffer0, invVP, eye);
|
||||
// vec2 coords = getProjectedCoord(hitCoord);
|
||||
// vec2 deltaCoords = abs(vec2(0.5, 0.5) - coords.xy);
|
||||
// float screenEdgeFactor = clamp(1.0 - (deltaCoords.x + deltaCoords.y), 0.0, 1.0);
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
#ifndef _GBUFFER_GLSL_
|
||||
#define _GBUFFER_GLSL_
|
||||
|
||||
#include "../compiled.glsl"
|
||||
|
||||
vec2 octahedronWrap(const vec2 v) {
|
||||
|
@ -97,3 +100,5 @@ vec3 decodeRGBM(const vec4 rgbm) {
|
|||
const float maxRange = 6.0;
|
||||
return rgbm.rgb * rgbm.a * maxRange;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
43
Shaders/std/ssrs.glsl
Normal file
43
Shaders/std/ssrs.glsl
Normal file
|
@ -0,0 +1,43 @@
|
|||
#include "../std/gbuffer.glsl"
|
||||
|
||||
uniform mat4 VP;
|
||||
|
||||
vec2 getProjectedCoord(vec3 hitCoord) {
|
||||
vec4 projectedCoord = VP * vec4(hitCoord, 1.0);
|
||||
projectedCoord.xy /= projectedCoord.w;
|
||||
projectedCoord.xy = projectedCoord.xy * 0.5 + 0.5;
|
||||
#ifdef _InvY
|
||||
projectedCoord.y = 1.0 - projectedCoord.y;
|
||||
#endif
|
||||
return projectedCoord.xy;
|
||||
}
|
||||
|
||||
float getDeltaDepth(vec3 hitCoord, sampler2D gbuffer0, mat4 invVP, vec3 eye) {
|
||||
vec2 texCoord = getProjectedCoord(hitCoord);
|
||||
// #ifdef _InvY // D3D
|
||||
// float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
|
||||
// #else
|
||||
// TODO: store_depth
|
||||
vec4 g0 = texture(gbuffer0, texCoord);
|
||||
float depth = (1.0 - g0.a) * 2.0 - 1.0;
|
||||
// #endif
|
||||
vec3 wpos = getPos2(invVP, depth, texCoord);
|
||||
float d1 = length(eye - wpos);
|
||||
float d2 = length(eye - hitCoord);
|
||||
return d1 - d2;
|
||||
}
|
||||
|
||||
float traceShadow(vec3 dir, vec3 hitCoord, sampler2D gbuffer0, mat4 invVP, vec3 eye) {
|
||||
dir *= ssrsRayStep;
|
||||
// for (int i = 0; i < maxSteps; i++) {
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord, gbuffer0, invVP, eye) > 0.0) return 0.6;
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord, gbuffer0, invVP, eye) > 0.0) return 0.7;
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord, gbuffer0, invVP, eye) > 0.0) return 0.8;
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord, gbuffer0, invVP, eye) > 0.0) return 0.9;
|
||||
//}
|
||||
return 1.0;
|
||||
}
|
|
@ -205,11 +205,14 @@ def write_norpos(con_mesh, vert, declare=False):
|
|||
def make_deferred(con_mesh):
|
||||
wrd = bpy.data.worlds['Arm']
|
||||
make_base(con_mesh, parse_opacity=False)
|
||||
# make_base(con_mesh, parse_opacity=True) #### Discarded transparency
|
||||
|
||||
frag = con_mesh.frag
|
||||
vert = con_mesh.vert
|
||||
tese = con_mesh.tese
|
||||
|
||||
# frag.write('if (opacity < 0.2) {discard;}') #### Discarded transparency
|
||||
|
||||
gapi = arm.utils.get_gapi()
|
||||
if '_Veloc' in wrd.rp_defs:
|
||||
frag.add_out('vec4[3] fragColor')
|
||||
|
@ -238,6 +241,10 @@ def make_deferred(con_mesh):
|
|||
|
||||
# Pack gbuffer
|
||||
frag.add_include('../../Shaders/std/gbuffer.glsl')
|
||||
|
||||
# frag.add_uniform('vec3 v', link='_cameraLook') #### Double sided shading
|
||||
# frag.write('if (dot(n, v) > 0.0) n = -n;')
|
||||
|
||||
frag.write('n /= (abs(n.x) + abs(n.y) + abs(n.z));')
|
||||
frag.write('n.xy = n.z >= 0.0 ? n.xy : octahedronWrap(n.xy);')
|
||||
# TODO: store_depth
|
||||
|
|
|
@ -15,11 +15,6 @@ def make(context_id, rpasses):
|
|||
if is_disp:
|
||||
vs.append({'name': 'nor', 'size': 3})
|
||||
|
||||
# TODO: interleaved buffer has to match vertex structure of mesh context
|
||||
if not bpy.data.worlds['Arm'].arm_deinterleaved_buffers:
|
||||
vs.append({'name': 'nor', 'size': 3})
|
||||
# vs.append({'name': 'tex', 'size': 2})
|
||||
|
||||
con_shadowmap = mat_state.data.add_context({ 'name': context_id, 'vertex_structure': vs, 'depth_write': True, 'compare_mode': 'less', 'cull_mode': 'clockwise', 'color_write_red': False, 'color_write_green': False, 'color_write_blue': False, 'color_write_alpha': False })
|
||||
|
||||
vert = con_shadowmap.make_vert()
|
||||
|
@ -34,6 +29,7 @@ def make(context_id, rpasses):
|
|||
vert.write_main_header('vec4 spos = vec4(pos, 1.0);')
|
||||
|
||||
parse_opacity = 'translucent' in rpasses
|
||||
# parse_opacity = True #### Discarded transparency
|
||||
if parse_opacity:
|
||||
frag.write('vec3 n;') # Discard at compile time
|
||||
frag.write('float dotNV;')
|
||||
|
@ -116,6 +112,11 @@ def make(context_id, rpasses):
|
|||
vert.add_out('vec3 vcolor')
|
||||
vert.write('vcolor = col;')
|
||||
|
||||
# TODO: interleaved buffer has to match vertex structure of mesh context
|
||||
if not bpy.data.worlds['Arm'].arm_deinterleaved_buffers:
|
||||
con_shadowmap.add_elem('nor', 3)
|
||||
con_shadowmap.add_elem('tex', 2)
|
||||
|
||||
# TODO: pass vbuf with proper struct
|
||||
if gapi.startswith('direct3d') and bpy.data.worlds['Arm'].arm_deinterleaved_buffers == False:
|
||||
vert.write('vec3 t1 = nor; // TODO: Temp for d3d')
|
||||
|
@ -123,7 +124,7 @@ def make(context_id, rpasses):
|
|||
vert.write('vec2 t2 = tex; // TODO: Temp for d3d')
|
||||
|
||||
if parse_opacity:
|
||||
frag.write('if (opacity < 0.5) discard;')
|
||||
frag.write('if (opacity < 0.1) discard;')
|
||||
|
||||
# frag.write('fragColor = vec4(0.0);')
|
||||
|
||||
|
|
Loading…
Reference in a new issue