Save gbuffer slot
This commit is contained in:
parent
c396267e8a
commit
7f261b4365
|
@ -8,7 +8,9 @@
|
|||
#endif
|
||||
|
||||
uniform sampler2D tex;
|
||||
#ifdef _CDepth
|
||||
uniform sampler2D gbufferD;
|
||||
#endif
|
||||
|
||||
#ifdef _CLensTex
|
||||
uniform sampler2D lensTexture;
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
#include "std/ltc.glsl"
|
||||
#endif
|
||||
|
||||
// uniform sampler2D gbufferD;
|
||||
uniform sampler2D gbufferD;
|
||||
uniform sampler2D gbuffer0;
|
||||
uniform sampler2D gbuffer1;
|
||||
|
||||
|
@ -135,8 +135,8 @@ const vec3 clusterSlices = vec3(16, 16, 16);
|
|||
// uniform mat4 LWVPSpot2;
|
||||
// uniform mat4 LWVPSpot3;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif // _ShadowMap
|
||||
#endif // _Clusters
|
||||
|
||||
#ifdef _Sun
|
||||
uniform vec3 sunDir;
|
||||
|
@ -178,11 +178,7 @@ void main() {
|
|||
vec3 albedo = surfaceAlbedo(g1.rgb, metrough.x); // g1.rgb - basecolor
|
||||
vec3 f0 = surfaceF0(g1.rgb, metrough.x);
|
||||
|
||||
// #ifdef _InvY // D3D
|
||||
// float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
|
||||
// #else
|
||||
float depth = (1.0 - g0.a) * 2.0 - 1.0;
|
||||
// #endif
|
||||
float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
|
||||
vec3 p = getPos(eye, eyeLook, viewRay, depth, cameraProj);
|
||||
vec3 v = normalize(eye - p);
|
||||
float dotNV = max(dot(n, v), 0.0);
|
||||
|
@ -306,6 +302,7 @@ void main() {
|
|||
// svisibility = texture(svisibility, texCoord).r;
|
||||
// #endif
|
||||
|
||||
#ifdef _ShadowMap
|
||||
// if (lightShadow == 1) {
|
||||
#ifdef _CSM
|
||||
svisibility = shadowTestCascade(shadowMap, eye, p + n * shadowsBias * 10, shadowsBias, shadowmapSize * vec2(shadowmapCascades, 1.0));
|
||||
|
@ -314,6 +311,7 @@ void main() {
|
|||
if (lPos.w > 0.0) svisibility = shadowTest(shadowMap, lPos.xyz / lPos.w, shadowsBias, shadowmapSize);
|
||||
#endif
|
||||
// }
|
||||
#endif
|
||||
|
||||
#ifdef _VoxelGIShadow // #else
|
||||
#ifdef _VoxelGICam
|
||||
|
@ -353,7 +351,7 @@ void main() {
|
|||
#endif
|
||||
|
||||
#ifdef _SSRS
|
||||
float tvis = traceShadowSS(-l, p, gbuffer0, invVP, eye);
|
||||
float tvis = traceShadowSS(-l, p, gbufferD, 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);
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
{
|
||||
"name": "deferred_light",
|
||||
"depth_write": false,
|
||||
"color_write_alpha": false,
|
||||
"compare_mode": "always",
|
||||
"cull_mode": "none",
|
||||
"links": [
|
||||
|
@ -172,7 +171,7 @@
|
|||
{
|
||||
"name": "lightProj",
|
||||
"link": "_lightPlaneProj",
|
||||
"ifdef": ["_ShadowMapCube"]
|
||||
"ifdef": ["_Clusters", "_ShadowMapCube"]
|
||||
}
|
||||
],
|
||||
"vertex_shader": "deferred_light.vert.glsl",
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
uniform samplerCube probeTex;
|
||||
uniform sampler2D gbuffer0;
|
||||
uniform sampler2D gbuffer1;
|
||||
uniform sampler2D gbufferD;
|
||||
uniform mat4 invVP;
|
||||
uniform vec3 probep;
|
||||
uniform vec3 eye;
|
||||
|
@ -34,7 +35,7 @@ void main() {
|
|||
return;
|
||||
}
|
||||
|
||||
float depth = (1.0 - g0.a) * 2.0 - 1.0;
|
||||
float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
|
||||
vec3 wp = getPos2(invVP, depth, texCoord);
|
||||
|
||||
vec2 enc = g0.rg;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "std/gbuffer.glsl"
|
||||
|
||||
uniform sampler2D probeTex;
|
||||
uniform sampler2D gbufferD;
|
||||
uniform sampler2D gbuffer0;
|
||||
uniform sampler2D gbuffer1;
|
||||
uniform mat4 probeVP;
|
||||
|
@ -34,7 +35,7 @@ void main() {
|
|||
return;
|
||||
}
|
||||
|
||||
float depth = (1.0 - g0.a) * 2.0 - 1.0;
|
||||
float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
|
||||
vec3 wp = getPos2(invVP, depth, texCoord);
|
||||
vec4 pp = probeVP * vec4(wp.xyz, 1.0);
|
||||
vec2 tc = (pp.xy / pp.w) * 0.5 + 0.5;
|
||||
|
|
|
@ -12,32 +12,26 @@ vec2 getProjectedCoord(vec3 hitCoord) {
|
|||
return projectedCoord.xy;
|
||||
}
|
||||
|
||||
float getDeltaDepth(vec3 hitCoord, sampler2D gbuffer0, mat4 invVP, vec3 eye) {
|
||||
float getDeltaDepth(vec3 hitCoord, sampler2D gbufferD, 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
|
||||
float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
|
||||
vec3 wpos = getPos2(invVP, depth, texCoord);
|
||||
float d1 = length(eye - wpos);
|
||||
float d2 = length(eye - hitCoord);
|
||||
return d1 - d2;
|
||||
}
|
||||
|
||||
float traceShadowSS(vec3 dir, vec3 hitCoord, sampler2D gbuffer0, mat4 invVP, vec3 eye) {
|
||||
float traceShadowSS(vec3 dir, vec3 hitCoord, sampler2D gbufferD, 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;
|
||||
if (getDeltaDepth(hitCoord, gbufferD, invVP, eye) > 0.0) return 0.6;
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord, gbuffer0, invVP, eye) > 0.0) return 0.7;
|
||||
if (getDeltaDepth(hitCoord, gbufferD, invVP, eye) > 0.0) return 0.7;
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord, gbuffer0, invVP, eye) > 0.0) return 0.8;
|
||||
if (getDeltaDepth(hitCoord, gbufferD, invVP, eye) > 0.0) return 0.8;
|
||||
hitCoord += dir;
|
||||
if (getDeltaDepth(hitCoord, gbuffer0, invVP, eye) > 0.0) return 0.9;
|
||||
if (getDeltaDepth(hitCoord, gbufferD, invVP, eye) > 0.0) return 0.9;
|
||||
//}
|
||||
return 1.0;
|
||||
}
|
||||
|
|
|
@ -8,9 +8,7 @@
|
|||
uniform sampler2D shadowMap;
|
||||
uniform samplerCube shadowMapCube;
|
||||
uniform sampler2D dilate;
|
||||
// uniform sampler2D gbufferD;
|
||||
uniform sampler2D gbuffer0;
|
||||
// uniform sampler2D gbuffer1;
|
||||
uniform sampler2D gbufferD;
|
||||
uniform vec2 cameraProj;
|
||||
uniform float shadowsBias;
|
||||
uniform vec3 eye;
|
||||
|
@ -26,12 +24,7 @@ in vec3 viewRay;
|
|||
out float fragColor[2];
|
||||
|
||||
void main() {
|
||||
vec4 g0 = texture(gbuffer0, texCoord);
|
||||
// #ifdef _InvY // D3D
|
||||
// float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
|
||||
// #else
|
||||
float depth = (1.0 - g0.a) * 2.0 - 1.0;
|
||||
// #endif
|
||||
float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
|
||||
vec3 p = getPos(eye, eyeLook, viewRay, depth, cameraProj);
|
||||
|
||||
vec4 lightPosition = LWVP * vec4(p, 1.0);
|
||||
|
|
|
@ -43,10 +43,6 @@ class Inc {
|
|||
}
|
||||
|
||||
public static function bindShadowMap() {
|
||||
if (path.sun != null && path.sun.data.raw.cast_shadow) {
|
||||
path.bindTarget("shadowMap", "shadowMap");
|
||||
}
|
||||
|
||||
for (l in iron.Scene.active.lights) {
|
||||
if (!l.visible || !l.data.raw.cast_shadow) continue;
|
||||
var n = shadowMapName(l);
|
||||
|
|
|
@ -67,6 +67,18 @@ class RenderPathDeferred {
|
|||
{
|
||||
path.createDepthBuffer("main", "DEPTH24");
|
||||
|
||||
var t = new RenderTargetRaw();
|
||||
t.name = "gbuffer0";
|
||||
t.width = 0;
|
||||
t.height = 0;
|
||||
t.displayp = Inc.getDisplayp();
|
||||
t.format = "RGBA64";
|
||||
t.scale = Inc.getSuperSampling();
|
||||
t.depth_buffer = "main";
|
||||
path.createRenderTarget(t);
|
||||
}
|
||||
|
||||
{
|
||||
var t = new RenderTargetRaw();
|
||||
t.name = "tex";
|
||||
t.width = 0;
|
||||
|
@ -96,18 +108,6 @@ class RenderPathDeferred {
|
|||
path.createRenderTarget(t);
|
||||
}
|
||||
|
||||
{
|
||||
var t = new RenderTargetRaw();
|
||||
t.name = "gbuffer0";
|
||||
t.width = 0;
|
||||
t.height = 0;
|
||||
t.displayp = Inc.getDisplayp();
|
||||
t.format = "RGBA64";
|
||||
t.scale = Inc.getSuperSampling();
|
||||
t.depth_buffer = "main";
|
||||
path.createRenderTarget(t);
|
||||
}
|
||||
|
||||
{
|
||||
var t = new RenderTargetRaw();
|
||||
t.name = "gbuffer1";
|
||||
|
@ -554,7 +554,7 @@ class RenderPathDeferred {
|
|||
#end
|
||||
|
||||
path.setTarget("tex");
|
||||
// path.bindTarget("_main", "gbufferD");
|
||||
path.bindTarget("_main", "gbufferD");
|
||||
path.bindTarget("gbuffer0", "gbuffer0");
|
||||
path.bindTarget("gbuffer1", "gbuffer1");
|
||||
// #if rp_gbuffer2_direct
|
||||
|
@ -597,11 +597,19 @@ class RenderPathDeferred {
|
|||
// }
|
||||
}
|
||||
#end
|
||||
|
||||
#if kha_webgl
|
||||
path.setDepthFrom("tex", "gbuffer1"); // Even with depth_write set to false, depth can not be attached..
|
||||
#end
|
||||
|
||||
voxelao_pass ?
|
||||
path.drawShader("shader_datas/deferred_light/deferred_light_VoxelAOvar") :
|
||||
path.drawShader("shader_datas/deferred_light/deferred_light");
|
||||
|
||||
#if kha_webgl
|
||||
path.setDepthFrom("tex", "gbuffer0");
|
||||
#end
|
||||
|
||||
#if rp_probes
|
||||
if (!path.isProbe) {
|
||||
var probes = iron.Scene.active.probes;
|
||||
|
|
|
@ -43,6 +43,11 @@ class Starter {
|
|||
#end
|
||||
|
||||
kha.System.start({title: Main.projectName, width: c.window_w, height: c.window_h, window: {mode: windowMode, windowFeatures: windowFeatures}, framebuffer: {samplesPerPixel: c.window_msaa, verticalSync: c.window_vsync}}, function(window:kha.Window) {
|
||||
|
||||
#if kha_webgl
|
||||
if (!kha.SystemImpl.gl2) trace("WebGL 2 is not supported on this browser");
|
||||
#end
|
||||
|
||||
iron.App.init(function() {
|
||||
#if arm_loadscreen
|
||||
function load(g:kha.graphics2.Graphics) {
|
||||
|
|
|
@ -108,7 +108,12 @@ def parse_shader(sres, c, con, defs, lines, parse_attributes):
|
|||
stack.pop()
|
||||
continue
|
||||
|
||||
if len(stack) > 0 and stack[-1] == 0:
|
||||
skip = False
|
||||
for i in stack:
|
||||
if i == 0:
|
||||
skip = True
|
||||
break
|
||||
if skip:
|
||||
continue
|
||||
|
||||
if vertex_structure_parsed == False and line.startswith('in '):
|
||||
|
|
|
@ -384,11 +384,7 @@ def make_deferred(con_mesh):
|
|||
|
||||
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
|
||||
if gapi.startswith('direct3d'):
|
||||
frag.write('fragColor[0] = vec4(n.xy, packFloat(metallic, roughness), 1.0 - ((wvpposition.z / wvpposition.w) * 0.5 + 0.5));')
|
||||
else:
|
||||
frag.write('fragColor[0] = vec4(n.xy, packFloat(metallic, roughness), 1.0 - gl_FragCoord.z);')
|
||||
frag.write('fragColor[0] = vec4(n.xy, packFloat(metallic, roughness), 1.0);')
|
||||
frag.write('fragColor[1] = vec4(basecol.rgb, packFloat2(occlusion, specular));')
|
||||
|
||||
if '_gbuffer2' in wrd.world_defs:
|
||||
|
@ -731,7 +727,7 @@ def make_forward_base(con_mesh, parse_opacity=False):
|
|||
frag.write('direct += specularBRDF(f0, roughness, sdotNL, sdotNH, dotNV, sdotVH) * specular;')
|
||||
# sun
|
||||
|
||||
if '_Clusters' in wrd.world_defs and '_Sun' not in wrd.world_defs:
|
||||
if '_Clusters' in wrd.world_defs:
|
||||
frag.add_uniform('vec3 lightCol', '_lightColor')
|
||||
frag.add_uniform('vec3 lightPos', '_lightPosition')
|
||||
frag.write('float visibility = 1.0;')
|
||||
|
@ -765,6 +761,9 @@ def make_forward_base(con_mesh, parse_opacity=False):
|
|||
frag.write('visibility *= PCFCube(shadowMap0, ld, -l, shadowsBias, lightProj, n);')
|
||||
frag.write('}')
|
||||
|
||||
frag.write('direct += lambertDiffuseBRDF(albedo, dotNL);')
|
||||
frag.write('direct += specularBRDF(f0, roughness, dotNL, dotNH, dotNV, dotVH) * specular;')
|
||||
|
||||
# frag.write('if (lightType == 2) {')
|
||||
# frag.write(' float spotEffect = dot(lightDir, l);')
|
||||
# frag.write(' if (spotEffect < spotlightData.x) {')
|
||||
|
@ -792,9 +791,6 @@ def make_forward_base(con_mesh, parse_opacity=False):
|
|||
# frag.write(' direct = albedo * ltcdiff + ltcspec * specular;')
|
||||
# frag.write('}')
|
||||
|
||||
frag.write('direct += lambertDiffuseBRDF(albedo, dotNL);')
|
||||
frag.write('direct += specularBRDF(f0, roughness, dotNL, dotNH, dotNV, dotVH) * specular;')
|
||||
|
||||
if '_Brdf' in wrd.world_defs:
|
||||
frag.add_uniform('sampler2D senvmapBrdf', link='_envmapBrdf')
|
||||
frag.write('vec2 envBRDF = texture(senvmapBrdf, vec2(roughness, 1.0 - dotNV)).xy;')
|
||||
|
|
Loading…
Reference in a new issue