Fix volumetric light

This commit is contained in:
Lubos Lenco 2017-05-22 15:55:34 +02:00
parent 0df4db841b
commit 81b8b0bc3a
14 changed files with 34 additions and 18 deletions

View file

@ -56,5 +56,5 @@ void main() {
// weight += doBlur(blurWeights[9], 9, nor, tc);
// }
fragColor.r /= weight; // SSAO only
fragColor = vec4(fragColor.r / weight); // SSAO only
}

View file

@ -3,8 +3,6 @@
{
"name": "blur_edge_pass_x",
"color_write_alpha": false,
"color_write_green": false,
"color_write_blue": false,
"depth_write": false,
"compare_mode": "always",
"cull_mode": "none",
@ -22,8 +20,6 @@
{
"name": "blur_edge_pass_y",
"color_write_alpha": false,
"color_write_green": false,
"color_write_blue": false,
"depth_write": false,
"compare_mode": "always",
"cull_mode": "none",
@ -41,8 +37,6 @@
{
"name": "blur_edge_pass_y_blend",
"color_write_alpha": false,
"color_write_green": false,
"color_write_blue": false,
"depth_write": false,
"compare_mode": "always",
"cull_mode": "none",
@ -64,8 +58,6 @@
{
"name": "blur_edge_pass_y_blend_add",
"color_write_alpha": false,
"color_write_green": false,
"color_write_blue": false,
"depth_write": false,
"compare_mode": "always",
"cull_mode": "none",

View file

@ -43,6 +43,7 @@ float PCF(const vec2 uv, const float compare) {
}
float lpToDepth(vec3 lp, const vec2 lightPlane) {
// TODO: precompute..
float d = lightPlane.y - lightPlane.x;
lp = abs(lp);
float zcomp = max(lp.x, max(lp.y, lp.z));
@ -53,7 +54,7 @@ float lpToDepth(vec3 lp, const vec2 lightPlane) {
float PCFCube(const vec3 lp, const vec3 ml, const float bias, const vec2 lightPlane) {
// return float(texture(shadowMapCube, ml).r + bias > lpToDepth(lp, lightPlane));
const float s = 0.001; // TODO: incorrect...
const float s = shadowmapCubePcfSize; // 0.001 TODO: incorrect...
float compare = lpToDepth(lp, lightPlane) - bias;
float result = step(compare, texture(shadowMapCube, ml).r);
result += step(compare, texture(shadowMapCube, ml + vec3(s, s, s)).r);

View file

@ -7,10 +7,12 @@ precision mediump float;
#include "../compiled.glsl"
#include "../std/gbuffer.glsl"
#include "../std/shadows.glsl"
uniform sampler2D gbufferD;
#ifndef _NoShadows
uniform sampler2D shadowMap;
//!uniform sampler2D shadowMap;
//!uniform samplerCube shadowMapCube;
#endif
uniform sampler2D snoise;
@ -22,6 +24,8 @@ uniform vec3 lightPos;
uniform vec3 lightColor;
uniform float lightRadius;
uniform float shadowsBias;
uniform int lightShadow;
uniform vec2 lightPlane;
in vec4 wvpposition;
out vec4 fragColor;
@ -55,10 +59,10 @@ void rayStep(inout vec3 curPos, inout float curOpticalDepth, inout float scatter
vec4 lampPos = LWVP * vec4(curPos, 1.0);
if (lampPos.w > 0.0) {
lampPos.xyz /= lampPos.w;
lampPos.xy = lampPos.xy * 0.5 + 0.5;
float distanceFromLight = texture(shadowMap, lampPos.xy).r * 2.0 - 1.0;
visibility = float(distanceFromLight > lampPos.z - shadowsBias);
visibility = float(texture(shadowMap, lampPos.xy).r > lampPos.z - shadowsBias);
}
// Cubemap
// visibility = float(texture(shadowMapCube, -l).r + shadowsBias > lpToDepth(lp, lightPlane));
scatteredLightAmount += curOpticalDepth * l1 * visibility;
}
@ -184,6 +188,5 @@ void main() {
// }
// curOpticalDepth
fragColor = vec4(scatteredLightAmount * lightColor.rgb * volumAirColor * volumAirTurbidity, 0.0);
// fragColor = vec4(scatteredLightAmount * lightColor.rgb * ((1.0 - depth) * 10.0), 0.0);
fragColor = vec4(vec3(scatteredLightAmount * volumAirColor * normalize(lightColor.rgb) * volumAirTurbidity), 0.0); // * ((1.0 - depth) * 10.0)
}

View file

@ -45,6 +45,14 @@
{
"name": "snoise",
"link": "_noise8"
},
{
"name": "lightPlane",
"link": "_lampPlane"
},
{
"name": "lightShadow",
"link": "_lampCastShadow"
}
],
"texture_params": [],

View file

@ -2034,7 +2034,7 @@ class ArmoryExporter:
# Export tangents
if self.has_tangents(exportMesh):
tanga_vals = self.calc_tangents(pa['values'], na['values'], ta['values'], o['index_arrays'][0]['values'])
tanga = make_va('tang', 3, tanga_vals)
tanga = self.make_va('tang', 3, tanga_vals)
o['vertex_arrays'].append(tanga)
# Delete the new mesh that we made earlier

View file

@ -136,6 +136,9 @@ def make_deferred(cam):
links.remove(l)
relink('Bind Target Transluc SM', 'Draw Meshes Transluc')
if cam.rp_volumetriclight:
links.new(nodes['Deferred Light'].outputs[0], nodes['Volumetric Light'].inputs[0])
# if not cam.rp_decals:
# relink('Set Target.005', 'SSAO')

View file

@ -88,6 +88,8 @@ def make(context_id):
frag.write(' if (texture(shadowMap, lpos.xy).r < lpos.z - shadowsBias) visibility = 0.0;')
frag.write('}')
frag.write('else if (lightShadow == 2) visibility = float(texture(shadowMapCube, -l).r + shadowsBias > lpToDepth(lp, lightPlane));')
else:
frag.write('int lightShadow = 0;')
frag.add_include('../../Shaders/std/math.glsl')
frag.write_header('#extension GL_ARB_shader_image_load_store : enable')

View file

@ -160,7 +160,7 @@ def init_properties():
bpy.types.World.arm_lod_gen_ratio = FloatProperty(name="Decimate Ratio", description="Decimate ratio", default=0.8)
bpy.types.World.arm_cache_shaders = BoolProperty(name="Cache Shaders", description="Do not rebuild existing shaders", default=True, update=assets.invalidate_shader_cache)
bpy.types.World.arm_cache_compiler = BoolProperty(name="Cache Compiler", description="Only recompile sources when required", default=False)
bpy.types.World.arm_gpu_processing = BoolProperty(name="GPU Processing", description="Utilize GPU for asset pre-processing at build time", default=True)
bpy.types.World.arm_gpu_processing = BoolProperty(name="GPU Processing", description="Utilize GPU for asset pre-processing at build time", default=True, update=assets.invalidate_compiled_data)
bpy.types.World.arm_play_live_patch = BoolProperty(name="Live Patching", description="Sync running player data to Blender", default=True)
bpy.types.World.arm_play_auto_build = BoolProperty(name="Auto Build", description="Rebuild scene on operator changes", default=True)
bpy.types.World.arm_play_viewport_camera = BoolProperty(name="Viewport Camera", description="Start player at viewport camera position", default=False)
@ -540,6 +540,7 @@ def init_properties():
bpy.types.Lamp.lamp_shadows_bias = bpy.props.FloatProperty(name="Bias", description="Depth offset for shadow acne", default=0.0001)
bpy.types.Lamp.lamp_omni_shadows = bpy.props.BoolProperty(name="Omnidirectional Shadows", description="Draw shadows to all faces of the cube map", default=True)
bpy.types.Lamp.lamp_omni_shadows_cubemap = bpy.props.BoolProperty(name="Cubemap Capture", description="Store shadowmap in a single cubemap", default=True)
bpy.types.World.lamp_omni_shadows_cubemap_pcfsize = bpy.props.FloatProperty(name="PCF Size", description="Filter size", default=0.001)
if not 'Arm' in bpy.data.worlds:
wrd = bpy.data.worlds.new('Arm')

View file

@ -121,6 +121,9 @@ def set_preset(self, context, preset):
cam.rp_stereo = False
cam.rp_greasepencil = False
cam.rp_voxelgi = True
cam.rp_voxelgi_resolution[0] = 256
cam.rp_voxelgi_resolution[1] = 256
cam.rp_voxelgi_resolution[2] = 256
cam.rp_render_to_texture = True
cam.rp_supersampling = '2'
cam.rp_antialiasing = 'TAA'

View file

@ -191,6 +191,8 @@ class DataPropsPanel(bpy.types.Panel):
layout.prop(obj.data, 'lamp_omni_shadows_cubemap')
if not obj.data.lamp_omni_shadows_cubemap:
layout.label('Warning: Will result in performance loss')
else:
layout.prop(bpy.data.worlds['Arm'], 'lamp_omni_shadows_cubemap_pcfsize')
elif obj.type == 'SPEAKER':
layout.prop(obj.data, 'loop')
layout.prop(obj.data, 'stream')

View file

@ -279,6 +279,7 @@ const float PI = 3.1415926535;
const float PI2 = PI * 2.0;
const vec2 cameraPlane = vec2(""" + str(round(clip_start * 100) / 100) + """, """ + str(round(clip_end * 100) / 100) + """);
const vec2 shadowmapSize = vec2(""" + str(shadowmap_size) + """, """ + str(shadowmap_size) + """);
const float shadowmapCubePcfSize = """ + str(round(wrd.lamp_omni_shadows_cubemap_pcfsize * 10000) / 10000) + """;
""")
if wrd.generate_clouds:
f.write(

Binary file not shown.

Binary file not shown.