Update voxelgi
This commit is contained in:
parent
bee4f02103
commit
d64441b7d3
|
@ -315,14 +315,14 @@ void main() {
|
|||
// }
|
||||
#endif
|
||||
|
||||
#ifdef _VoxelGIShadow // #else
|
||||
#ifdef _VoxelGICam
|
||||
vec3 voxpos = (p - eyeSnap) / voxelgiHalfExtents;
|
||||
#else
|
||||
vec3 voxpos = p / voxelgiHalfExtents;
|
||||
#endif
|
||||
if (dotNL > 0.0) svisibility = max(0, 1.0 - traceShadow(voxels, voxpos, l, 0.1, 10.0, n));
|
||||
#endif
|
||||
// #ifdef _VoxelGIShadow // #else
|
||||
// #ifdef _VoxelGICam
|
||||
// vec3 voxpos = (p - eyeSnap) / voxelgiHalfExtents;
|
||||
// #else
|
||||
// vec3 voxpos = p / voxelgiHalfExtents;
|
||||
// #endif
|
||||
// if (dotNL > 0.0) svisibility = max(0, 1.0 - traceShadow(voxels, voxpos, l, 0.1, 10.0, n));
|
||||
// #endif
|
||||
|
||||
#ifdef _SSRS
|
||||
float tvis = traceShadowSS(-sunDir, p, gbufferD, invVP, eye);
|
||||
|
|
|
@ -23,11 +23,11 @@ uniform mat4 LVP;
|
|||
|
||||
uniform layout(binding = 0, rgba8) readonly image3D voxelsOpac;
|
||||
uniform layout(binding = 1, r32ui) readonly uimage3D voxelsNor;
|
||||
// uniform layout(binding = 2, rgba8) writeonly image3D voxels;
|
||||
uniform layout(binding = 2, r32ui) uimage3D voxels;
|
||||
#ifdef _ShadowMap
|
||||
uniform layout(binding = 3) sampler2D shadowMap;
|
||||
uniform layout(binding = 4) samplerCube shadowMapCube;
|
||||
uniform layout(binding = 3) sampler2DShadow shadowMap;
|
||||
uniform layout(binding = 4) sampler2DShadow shadowMapSpot;
|
||||
uniform layout(binding = 5) samplerCubeShadow shadowMapPoint;
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
|
@ -56,11 +56,16 @@ void main() {
|
|||
if (lightShadow == 1) {
|
||||
vec4 lightPosition = LVP * vec4(wposition, 1.0);
|
||||
vec3 lPos = lightPosition.xyz / lightPosition.w;
|
||||
// if (lightPosition.w > 0.0)
|
||||
if (texture(shadowMap, lPos.xy).r < lPos.z - shadowsBias) visibility = 0.0;
|
||||
// visibility = shadowTest(shadowMap, lPos, shadowsBias, shadowmapSize);
|
||||
visibility = texture(shadowMap, vec3(lPos.xy, lPos.z - shadowsBias)).r;
|
||||
}
|
||||
else if (lightShadow == 2) {
|
||||
vec4 lightPosition = LVP * vec4(wposition, 1.0);
|
||||
vec3 lPos = lightPosition.xyz / lightPosition.w;
|
||||
visibility *= texture(shadowMapSpot, vec3(lPos.xy, lPos.z - shadowsBias)).r;
|
||||
}
|
||||
else if (lightShadow == 3) {
|
||||
visibility *= texture(shadowMapPoint, vec4(-l, lpToDepth(lp, lightProj) - shadowsBias)).r;
|
||||
}
|
||||
else if (lightShadow == 2) visibility *= float(texture(shadowMapCube, -l).r + shadowsBias > lpToDepth(lp, lightProj));
|
||||
#endif
|
||||
|
||||
if (lightType == 2) {
|
||||
|
|
|
@ -13,6 +13,7 @@ class Inc {
|
|||
static var voxel_tc:kha.compute.TextureUnit;
|
||||
static var voxel_td:kha.compute.TextureUnit;
|
||||
static var voxel_te:kha.compute.TextureUnit;
|
||||
static var voxel_tf:kha.compute.TextureUnit;
|
||||
static var voxel_ca:kha.compute.ConstantLocation;
|
||||
static var voxel_cb:kha.compute.ConstantLocation;
|
||||
static var voxel_cc:kha.compute.ConstantLocation;
|
||||
|
@ -396,7 +397,8 @@ class Inc {
|
|||
voxel_tb = voxel_sh.getTextureUnit("voxelsNor");
|
||||
voxel_tc = voxel_sh.getTextureUnit("voxels");
|
||||
voxel_td = voxel_sh.getTextureUnit("shadowMap");
|
||||
voxel_te = voxel_sh.getTextureUnit("shadowMapCube");
|
||||
voxel_te = voxel_sh.getTextureUnit("shadowMapSpot");
|
||||
voxel_tf = voxel_sh.getTextureUnit("shadowMapPoint");
|
||||
|
||||
voxel_ca = voxel_sh.getConstantLocation("lightPos");
|
||||
voxel_cb = voxel_sh.getConstantLocation("lightColor");
|
||||
|
@ -427,17 +429,19 @@ class Inc {
|
|||
kha.compute.Compute.setTexture(voxel_tc, rts.get("voxels").image, kha.compute.Access.Write);
|
||||
|
||||
#if (rp_shadowmap)
|
||||
if (Inc.shadowMapName(l) == "shadowMapCube") {
|
||||
// shadowMapCube
|
||||
kha.compute.Compute.setSampledCubeMap(voxel_te, rts.get("shadowMapCube").cubeMap);
|
||||
if (l.data.raw.type == "sun") {
|
||||
kha.compute.Compute.setSampledTexture(voxel_td, rts.get("shadowMap").image);
|
||||
kha.compute.Compute.setInt(voxel_ce, 1); // lightShadow
|
||||
}
|
||||
else if (l.data.raw.type == "spot") {
|
||||
kha.compute.Compute.setSampledTexture(voxel_te, rts.get("shadowMapSpot[0]").image);
|
||||
kha.compute.Compute.setInt(voxel_ce, 2);
|
||||
}
|
||||
else {
|
||||
// shadowMap
|
||||
kha.compute.Compute.setSampledTexture(voxel_td, rts.get("shadowMap").image);
|
||||
kha.compute.Compute.setSampledCubeMap(voxel_tf, rts.get("shadowMapPoint[0]").cubeMap);
|
||||
kha.compute.Compute.setInt(voxel_ce, 3);
|
||||
}
|
||||
// lightShadow
|
||||
var i = l.data.raw.shadowmap_cube ? 2 : 1;
|
||||
kha.compute.Compute.setInt(voxel_ce, i);
|
||||
|
||||
// lightProj
|
||||
var near = l.data.raw.near_plane;
|
||||
var far = l.data.raw.far_plane;
|
||||
|
@ -481,22 +485,22 @@ class Inc {
|
|||
var res = Inc.getVoxelRes();
|
||||
path.generateMipmaps("voxels");
|
||||
|
||||
#if (rp_gi_bounces)
|
||||
if (bounce_sh == null) {
|
||||
bounce_sh = path.getComputeShader("voxel_bounce");
|
||||
bounce_ta = bounce_sh.getTextureUnit("voxelsNor");
|
||||
bounce_tb = bounce_sh.getTextureUnit("voxelsFrom");
|
||||
bounce_tc = bounce_sh.getTextureUnit("voxelsTo");
|
||||
}
|
||||
// path.clearImage("voxelsBounce", 0x00000000);
|
||||
kha.compute.Compute.setShader(bounce_sh);
|
||||
kha.compute.Compute.setTexture(bounce_ta, rts.get("voxelsNor").image, kha.compute.Access.Read);
|
||||
kha.compute.Compute.setTexture3DParameters(bounce_tb, kha.graphics4.TextureAddressing.Clamp, kha.graphics4.TextureAddressing.Clamp, kha.graphics4.TextureAddressing.Clamp, kha.graphics4.TextureFilter.LinearFilter, kha.graphics4.TextureFilter.PointFilter, kha.graphics4.MipMapFilter.LinearMipFilter);
|
||||
kha.compute.Compute.setSampledTexture(bounce_tb, rts.get("voxels").image);
|
||||
kha.compute.Compute.setTexture(bounce_tc, rts.get("voxelsBounce").image, kha.compute.Access.Write);
|
||||
kha.compute.Compute.compute(res, res, res);
|
||||
path.generateMipmaps("voxelsBounce");
|
||||
#end
|
||||
// #if (rp_gi_bounces)
|
||||
// if (bounce_sh == null) {
|
||||
// bounce_sh = path.getComputeShader("voxel_bounce");
|
||||
// bounce_ta = bounce_sh.getTextureUnit("voxelsNor");
|
||||
// bounce_tb = bounce_sh.getTextureUnit("voxelsFrom");
|
||||
// bounce_tc = bounce_sh.getTextureUnit("voxelsTo");
|
||||
// }
|
||||
// // path.clearImage("voxelsBounce", 0x00000000);
|
||||
// kha.compute.Compute.setShader(bounce_sh);
|
||||
// kha.compute.Compute.setTexture(bounce_ta, rts.get("voxelsNor").image, kha.compute.Access.Read);
|
||||
// kha.compute.Compute.setTexture3DParameters(bounce_tb, kha.graphics4.TextureAddressing.Clamp, kha.graphics4.TextureAddressing.Clamp, kha.graphics4.TextureAddressing.Clamp, kha.graphics4.TextureFilter.LinearFilter, kha.graphics4.TextureFilter.PointFilter, kha.graphics4.MipMapFilter.LinearMipFilter);
|
||||
// kha.compute.Compute.setSampledTexture(bounce_tb, rts.get("voxels").image);
|
||||
// kha.compute.Compute.setTexture(bounce_tc, rts.get("voxelsBounce").image, kha.compute.Access.Write);
|
||||
// kha.compute.Compute.compute(res, res, res);
|
||||
// path.generateMipmaps("voxelsBounce");
|
||||
// #end
|
||||
}
|
||||
#end
|
||||
}
|
||||
|
|
|
@ -53,9 +53,9 @@ class RenderPathDeferred {
|
|||
{
|
||||
Inc.initGI("voxelsOpac");
|
||||
Inc.initGI("voxelsNor");
|
||||
#if (rp_gi_bounces)
|
||||
Inc.initGI("voxelsBounce");
|
||||
#end
|
||||
// #if (rp_gi_bounces)
|
||||
// Inc.initGI("voxelsBounce");
|
||||
// #end
|
||||
}
|
||||
#end
|
||||
#if (rp_gi == "Voxel AO")
|
||||
|
@ -591,9 +591,10 @@ class RenderPathDeferred {
|
|||
// Inc.computeVoxelsBegin();
|
||||
// for (i in 0...lights.length) Inc.computeVoxels(i); // Redraws SM
|
||||
// Inc.computeVoxelsEnd();
|
||||
#if (rp_gi_bounces)
|
||||
voxels = "voxelsBounce";
|
||||
#end
|
||||
|
||||
// #if (rp_gi_bounces)
|
||||
// voxels = "voxelsBounce";
|
||||
// #end
|
||||
#else
|
||||
path.generateMipmaps(voxels); // AO
|
||||
#end
|
||||
|
|
|
@ -118,9 +118,9 @@ class RenderPathForward {
|
|||
{
|
||||
Inc.initGI("voxelsOpac");
|
||||
Inc.initGI("voxelsNor");
|
||||
#if (rp_gi_bounces)
|
||||
Inc.initGI("voxelsBounce");
|
||||
#end
|
||||
// #if (rp_gi_bounces)
|
||||
// Inc.initGI("voxelsBounce");
|
||||
// #end
|
||||
}
|
||||
#end
|
||||
}
|
||||
|
@ -269,9 +269,9 @@ class RenderPathForward {
|
|||
Inc.computeVoxelsBegin();
|
||||
Inc.computeVoxels(0);
|
||||
Inc.computeVoxelsEnd();
|
||||
#if (rp_gi_bounces)
|
||||
voxels = "voxelsBounce";
|
||||
#end
|
||||
// #if (rp_gi_bounces)
|
||||
// voxels = "voxelsBounce";
|
||||
// #end
|
||||
#else
|
||||
path.generateMipmaps(voxels); // AO
|
||||
#end
|
||||
|
|
|
@ -75,11 +75,11 @@ def add_world_defs():
|
|||
if voxelgi:
|
||||
wrd.world_defs += '_VoxelGI'
|
||||
assets.add_shader_external(arm.utils.get_sdk_path() + '/armory/Shaders/voxel_light/voxel_light.comp.glsl')
|
||||
if rpdat.arm_voxelgi_bounces != "1":
|
||||
assets.add_khafile_def('rp_gi_bounces={0}'.format(rpdat.arm_voxelgi_bounces))
|
||||
assets.add_shader_external(arm.utils.get_sdk_path() + '/armory/Shaders/voxel_bounce/voxel_bounce.comp.glsl')
|
||||
if rpdat.arm_voxelgi_shadows:
|
||||
wrd.world_defs += '_VoxelGIShadow'
|
||||
# if rpdat.arm_voxelgi_bounces != "1":
|
||||
# assets.add_khafile_def('rp_gi_bounces={0}'.format(rpdat.arm_voxelgi_bounces))
|
||||
# assets.add_shader_external(arm.utils.get_sdk_path() + '/armory/Shaders/voxel_bounce/voxel_bounce.comp.glsl')
|
||||
# if rpdat.arm_voxelgi_shadows:
|
||||
# wrd.world_defs += '_VoxelGIShadow'
|
||||
if rpdat.rp_voxelgi_relight:
|
||||
assets.add_khafile_def('rp_voxelgi_relight')
|
||||
elif voxelao:
|
||||
|
@ -273,8 +273,8 @@ def build():
|
|||
assets.add_khafile_def('rp_gi={0}'.format(rp_gi))
|
||||
assets.add_khafile_def('rp_voxelgi_resolution={0}'.format(rpdat.rp_voxelgi_resolution))
|
||||
assets.add_khafile_def('rp_voxelgi_resolution_z={0}'.format(rpdat.rp_voxelgi_resolution_z))
|
||||
if rpdat.arm_voxelgi_shadows:
|
||||
assets.add_khafile_def('rp_voxelgi_shadows')
|
||||
# if rpdat.arm_voxelgi_shadows:
|
||||
# assets.add_khafile_def('rp_voxelgi_shadows')
|
||||
else:
|
||||
log.warn('Disabling Voxel GI - unsupported target - use Krom instead')
|
||||
|
||||
|
|
|
@ -159,44 +159,6 @@ def make_gi(context_id):
|
|||
|
||||
frag.write('val = encNor(wnormal);');
|
||||
frag.write('imageAtomicMax(voxelsNor, ivec3(voxelgiResolution * voxel), val);')
|
||||
|
||||
# frag.write('imageStore(voxels, ivec3(voxelgiResolution * voxel), vec4(color, 1.0));')
|
||||
# frag.write('imageAtomicRGBA8Avg(voxels, ivec3(voxelgiResolution * voxel), vec4(color, 1.0));')
|
||||
|
||||
# frag.write('ivec3 coords = ivec3(voxelgiResolution * voxel);')
|
||||
# if parse_opacity:
|
||||
# frag.write('vec4 val = vec4(color, opacity);')
|
||||
# else:
|
||||
# frag.write('vec4 val = vec4(color, 1.0);')
|
||||
# frag.write('val *= 255.0;')
|
||||
# frag.write('uint newVal = encUnsignedNibble(convVec4ToRGBA8(val), 1);')
|
||||
# frag.write('uint prevStoredVal = 0;')
|
||||
# frag.write('uint currStoredVal;')
|
||||
# # frag.write('int counter = 0;')
|
||||
# # frag.write('while ((currStoredVal = imageAtomicCompSwap(voxels, coords, prevStoredVal, newVal)) != prevStoredVal && counter < 16) {')
|
||||
# frag.write('while ((currStoredVal = imageAtomicCompSwap(voxels, coords, prevStoredVal, newVal)) != prevStoredVal) {')
|
||||
# frag.write(' vec4 rval = convRGBA8ToVec4(currStoredVal & 0xFEFEFEFE);')
|
||||
# frag.write(' uint n = decUnsignedNibble(currStoredVal);')
|
||||
# frag.write(' rval = rval * n + val;')
|
||||
# frag.write(' rval /= ++n;')
|
||||
# frag.write(' rval = round(rval / 2) * 2;')
|
||||
# frag.write(' newVal = encUnsignedNibble(convVec4ToRGBA8(rval), n);')
|
||||
# frag.write(' prevStoredVal = currStoredVal;')
|
||||
# # frag.write(' counter++;')
|
||||
# frag.write('}')
|
||||
|
||||
# frag.write('val.rgb *= 255.0f;')
|
||||
# frag.write('uint newVal = convVec4ToRGBA8(val);')
|
||||
# frag.write('uint prevStoredVal = 0;')
|
||||
# frag.write('uint curStoredVal;')
|
||||
# frag.write('while ((curStoredVal = imageAtomicCompSwap(voxels, coords, prevStoredVal, newVal)) != prevStoredVal) {')
|
||||
# frag.write(' prevStoredVal = curStoredVal;')
|
||||
# frag.write(' vec4 rval = convRGBA8ToVec4(curStoredVal);')
|
||||
# frag.write(' rval.xyz = (rval.xyz * rval.w);')
|
||||
# frag.write(' vec4 curValF = rval + val;')
|
||||
# frag.write(' curValF.xyz /= (curValF.w);')
|
||||
# frag.write(' newVal = convVec4ToRGBA8(curValF);')
|
||||
# frag.write('}')
|
||||
|
||||
return con_voxel
|
||||
|
||||
|
@ -284,8 +246,6 @@ def make_ao(context_id):
|
|||
frag.add_include('std/math.glsl')
|
||||
frag.add_include('std/imageatomic.glsl')
|
||||
frag.write_header('#extension GL_ARB_shader_image_load_store : enable')
|
||||
|
||||
# frag.add_uniform('layout(r32ui) uimage3D voxels')
|
||||
frag.add_uniform('layout(r8) writeonly image3D voxels')
|
||||
|
||||
vert.add_include('compiled.inc')
|
||||
|
|
|
@ -420,13 +420,13 @@ class ArmRPListItem(bpy.types.PropertyGroup):
|
|||
arm_voxelgi_dimensions: FloatProperty(name="Dimensions", description="Voxelization bounds",default=16, update=assets.invalidate_compiled_data)
|
||||
arm_voxelgi_revoxelize: BoolProperty(name="Revoxelize", description="Revoxelize scene each frame", default=False, update=assets.invalidate_shader_cache)
|
||||
arm_voxelgi_temporal: BoolProperty(name="Temporal Filter", description="Use temporal filtering to stabilize voxels", default=False, update=assets.invalidate_shader_cache)
|
||||
arm_voxelgi_bounces: EnumProperty(
|
||||
items=[('1', '1', '1'),
|
||||
('2', '2', '2')],
|
||||
name="Bounces", description="Trace multiple light bounces", default='1', update=update_renderpath)
|
||||
# arm_voxelgi_bounces: EnumProperty(
|
||||
# items=[('1', '1', '1'),
|
||||
# ('2', '2', '2')],
|
||||
# name="Bounces", description="Trace multiple light bounces", default='1', update=update_renderpath)
|
||||
arm_voxelgi_camera: BoolProperty(name="Dynamic Camera", description="Use camera as voxelization origin", default=False, update=assets.invalidate_shader_cache)
|
||||
# arm_voxelgi_anisotropic: BoolProperty(name="Anisotropic", description="Use anisotropic voxels", default=False, update=update_renderpath)
|
||||
arm_voxelgi_shadows: BoolProperty(name="Trace Shadows", description="Use voxels to render shadows", default=False, update=update_renderpath)
|
||||
# arm_voxelgi_shadows: BoolProperty(name="Trace Shadows", description="Use voxels to render shadows", default=False, update=update_renderpath)
|
||||
arm_samples_per_pixel: EnumProperty(
|
||||
items=[('1', '1', '1'),
|
||||
('2', '2', '2'),
|
||||
|
|
|
@ -787,9 +787,9 @@ class ArmRenderPathVoxelsPanel(bpy.types.Panel):
|
|||
col.enabled = rpdat.rp_gi != 'Off'
|
||||
col2 = col.column()
|
||||
col2.enabled = rpdat.rp_gi == 'Voxel GI'
|
||||
col2.prop(rpdat, 'arm_voxelgi_bounces')
|
||||
# col2.prop(rpdat, 'arm_voxelgi_bounces')
|
||||
col2.prop(rpdat, 'rp_voxelgi_relight')
|
||||
col2.prop(rpdat, 'arm_voxelgi_shadows', text='Shadows')
|
||||
# col2.prop(rpdat, 'arm_voxelgi_shadows', text='Shadows')
|
||||
col.prop(rpdat, 'arm_voxelgi_cones')
|
||||
col.prop(rpdat, 'rp_voxelgi_resolution')
|
||||
col.prop(rpdat, 'rp_voxelgi_resolution_z')
|
||||
|
|
Loading…
Reference in a new issue