Z multiplier for voxel res

This commit is contained in:
Lubos Lenco 2017-10-23 01:55:47 +02:00
parent 02ef97f0ce
commit d8d33f32e1
7 changed files with 18 additions and 14 deletions

View file

@ -8,7 +8,7 @@
// https://research.nvidia.com/sites/default/files/publications/GIVoxels-pg2011-authors.pdf
const float MAX_DISTANCE = 1.73205080757;
const float VOXEL_SIZE = 2.0 / voxelgiResolution;
const float VOXEL_SIZE = (2.0 / voxelgiResolution.x);
uniform sampler3D voxels;
@ -50,7 +50,7 @@ vec4 traceCone(const vec3 origin, vec3 dir, float aperture, const float maxDist,
// Step until alpha > 1 or out of bounds
while (sampleCol.a < 1.0 && dist < maxDist) {
// Choose mip level based on the diameter of the cone
float mip = max(log2(diam * voxelgiResolution), 0);
float mip = max(log2(diam * voxelgiResolution.x), 0);
// vec4 mipSample = sampleVoxel(samplePos, dir, indices, mip);
vec4 mipSample = textureLod(voxels, samplePos * 0.5 + vec3(0.5), mip);
#ifdef _VoxelGIEmission
@ -128,7 +128,7 @@ float traceConeAO(const vec3 origin, vec3 dir, float aperture, const float maxDi
float diam = dist * aperture;
vec3 samplePos = dir * dist + origin;
while (sampleCol < 1.0 && dist < maxDist) {
float mip = max(log2(diam * voxelgiResolution), 0);
float mip = max(log2(diam * voxelgiResolution.x), 0);
float mipSample = textureLod(voxels, samplePos * 0.5 + vec3(0.5), mip).r;
sampleCol += (1 - sampleCol) * mipSample;
dist += max(diam / 2, VOXEL_SIZE);

View file

@ -39,8 +39,4 @@ float attenuate(const float dist) {
// 1.0 / (quadratic * dist * dist);
}
bool isInsideCube(const vec3 p) {
return abs(p.x) < 1 && abs(p.y) < 1 && abs(p.z) < 1;
}
#endif

View file

@ -445,7 +445,7 @@ def make_deferred(rpdat):
res = int(rpdat.rp_voxelgi_resolution)
n.inputs[1].default_value = res
n.inputs[2].default_value = res
n.inputs[3].default_value = res
n.inputs[3].default_value = int(res * float(rpdat.rp_voxelgi_resolution_z))
n = nodes['Set Viewport Voxels']
n.inputs[1].default_value = res
n.inputs[2].default_value = res
@ -461,7 +461,7 @@ def make_deferred(rpdat):
res = int(rpdat.rp_voxelgi_resolution)
n.inputs[1].default_value = res
n.inputs[2].default_value = res
n.inputs[3].default_value = res
n.inputs[3].default_value = int(res * float(rpdat.rp_voxelgi_resolution_z))
n = nodes['Set Viewport Voxels']
n.inputs[1].default_value = res
n.inputs[2].default_value = res

View file

@ -44,7 +44,7 @@ def make_gi(context_id):
frag.add_uniform('int lightType', '_lampType')
frag.add_uniform('vec3 lightDir', '_lampDirection')
frag.write('if (!isInsideCube(voxposition)) return;')
frag.write('if (abs(voxposition.z) > ' + rpdat.rp_voxelgi_resolution_z + ' || abs(voxposition.x) > 1 || abs(voxposition.y) > 1) return;')
frag.write('vec3 wposition = voxposition * voxelgiHalfExtents;')
if rpdat.arm_voxelgi_revoxelize and rpdat.arm_voxelgi_camera:
frag.add_uniform('vec3 eyeSnap', '_cameraPositionSnap')
@ -275,8 +275,7 @@ def make_ao(context_id):
rpdat = arm.utils.get_rp()
frag.add_uniform('layout(r32ui) uimage3D voxels')
frag.write('if (!isInsideCube(voxposition)) return;')
frag.write('if (abs(voxposition.z) > ' + rpdat.rp_voxelgi_resolution_z + ' || abs(voxposition.x) > 1 || abs(voxposition.y) > 1) return;')
vert.add_include('../../Shaders/compiled.glsl')
vert.add_uniform('mat4 W', '_worldMatrix')

View file

@ -159,6 +159,11 @@ class ArmRPListItem(bpy.types.PropertyGroup):
('256', '256', '256'),
('512', '512', '512')],
name="Resolution", description="3D texture resolution", default='128', update=update_renderpath)
rp_voxelgi_resolution_z = bpy.props.EnumProperty(
items=[('1.0', '1.0', '1.0'),
('0.5', '0.5', '0.5'),
('0.25', '0.25', '0.25')],
name="Resolution Z", description="3D texture z resolution multiplier", default='1.0', update=update_renderpath)
arm_clouds = bpy.props.BoolProperty(name="Clouds", default=False, update=assets.invalidate_shader_cache)
arm_pcss_state = EnumProperty(
items=[('On', 'On', 'On'),

View file

@ -977,6 +977,7 @@ class ArmRenderPathPanel(bpy.types.Panel):
layout.prop(rpdat, 'rp_gi')
if rpdat.rp_gi != 'Off':
layout.prop(rpdat, 'rp_voxelgi_resolution')
layout.prop(rpdat, 'rp_voxelgi_resolution_z')
layout.prop(rpdat, 'arm_voxelgi_dimensions')
layout.prop(rpdat, 'arm_voxelgi_revoxelize')
if rpdat.arm_voxelgi_revoxelize:

View file

@ -440,9 +440,12 @@ const float compoDOFLength = 160.0;
""") # str(round(bpy.data.cameras[0].lens * 100) / 100)
if rpdat.rp_gi == 'Voxel GI' or rpdat.rp_gi == 'Voxel AO':
halfext = round(rpdat.arm_voxelgi_dimensions / 2.0)
f.write(
"""const int voxelgiResolution = """ + str(rpdat.rp_voxelgi_resolution) + """;
const float voxelgiHalfExtents = """ + str(round(rpdat.arm_voxelgi_dimensions / 2.0)) + """;
# """const int voxelgiResolution = """ + str(rpdat.rp_voxelgi_resolution) + """;
"""const ivec3 voxelgiResolution = ivec3(""" + str(rpdat.rp_voxelgi_resolution) + """, """ + str(rpdat.rp_voxelgi_resolution) + """, """ + str(int(int(rpdat.rp_voxelgi_resolution) * float(rpdat.rp_voxelgi_resolution_z))) + """);
//const float voxelgiHalfExtents = """ + str(round(rpdat.arm_voxelgi_dimensions / 2.0)) + """;
const vec3 voxelgiHalfExtents = vec3(""" + str(halfext) + """, """ + str(halfext) + """, """ + str(round(halfext * float(rpdat.rp_voxelgi_resolution_z))) + """);
const float voxelgiDiff = """ + str(round(wrd.arm_voxelgi_diff * 100) / 100) + """;
const float voxelgiSpec = """ + str(round(wrd.arm_voxelgi_spec * 100) / 100) + """;
const float voxelgiOcc = """ + str(round(wrd.arm_voxelgi_occ * 100) / 100) + """;