Begin cubemap capture

This commit is contained in:
Lubos Lenco 2017-03-17 18:34:03 +01:00
parent 7b6cc88dab
commit d8044cf1df
7 changed files with 55 additions and 43 deletions

View file

@ -30,8 +30,10 @@ uniform sampler2D gbufferD;
uniform sampler2D gbuffer0;
uniform sampler2D gbuffer1;
// TODO: separate shaders
#ifndef _NoShadows
//!uniform sampler2D shadowMap;
//!uniform samplerCube shadowMapCube;
#ifdef _PCSS
//!uniform sampler2D snoise;
//!uniform float lampSizeUV;
@ -109,6 +111,9 @@ float shadowTest(const vec3 lPos) {
return PCF(lPos.xy, lPos.z - shadowsBias);
#endif
}
float shadowTestCube(const vec3 lPos, const vec3 l) {
return PCFCube(l, lPos.z - shadowsBias);
}
#endif
#ifdef _SSRS
@ -169,19 +174,23 @@ void main() {
vec3 albedo = surfaceAlbedo(g1.rgb, metrough.x); // g1.rgb - basecolor
vec3 f0 = surfaceF0(g1.rgb, metrough.x);
vec3 l;
l = normalize(lightPos - p);
float visibility = 1.0;
#ifndef _NoShadows
// TODO: merge..
if (lightShadow == 1) {
vec4 lampPos = LWVP * vec4(p, 1.0);
if (lampPos.w > 0.0) {
visibility = shadowTest(lampPos.xyz / lampPos.w);
}
if (lampPos.w > 0.0) visibility = shadowTest(lampPos.xyz / lampPos.w);
}
else if (lightShadow == 2) { // Cube
vec4 lampPos = LWVP * vec4(p, 1.0);
if (lampPos.w > 0.0) visibility = shadowTestCube(lampPos.xyz / lampPos.w, l);
}
#endif
// Per-light
vec3 l;
l = normalize(lightPos - p);
#ifndef _NoLampFalloff
visibility *= attenuate(distance(p, lightPos));
#endif

View file

@ -1,6 +1,7 @@
#include "../compiled.glsl"
uniform sampler2D shadowMap;
uniform samplerCube shadowMapCube;
float texture2DCompare(const vec2 uv, const float compare){
float depth = texture(shadowMap, uv).r;
@ -21,7 +22,7 @@ float texture2DShadowLerp(const vec2 uv, const float compare){
return c;
}
float PCF(const vec2 uv, float compare) {
float PCF(const vec2 uv, const float compare) {
// float result = 0.0;
// for (int x = -1; x <= 1; x++){
// for(int y = -1; y <= 1; y++){
@ -40,3 +41,8 @@ float PCF(const vec2 uv, float compare) {
// }
return result / 9.0;
}
float PCFCube(const vec3 l, const float compare) {
// No PCF yet..
return float(texture(shadowMapCube, -l).r > compare);
}

View file

@ -1193,30 +1193,30 @@ class ArmoryExporter:
return space.region_3d.perspective_matrix
return None
def make_fake_omni_lamps(self, o, bobject):
# Look down
o['transform']['values'] = [1.0, 0.0, 0.0, bobject.location.x, 0.0, 1.0, 0.0, bobject.location.y, 0.0, 0.0, 1.0, bobject.location.z, 0.0, 0.0, 0.0, 1.0]
if not hasattr(o, 'children'):
o['children'] = []
# Make child lamps
for i in range(0, 5):
child_lamp = {}
child_lamp['name'] = o['name'] + '__' + str(i)
child_lamp['data_ref'] = o['data_ref']
child_lamp['type'] = 'lamp_object'
if i == 0:
mat = [0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0]
elif i == 1:
mat = [0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0]
elif i == 2:
mat = [0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0]
elif i == 3:
mat = [0.0, -1.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0]
elif i == 4:
mat = [-1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 1.0]
child_lamp['transform'] = {}
child_lamp['transform']['values'] = mat
o['children'].append(child_lamp)
# def make_fake_omni_lamps(self, o, bobject):
# # Look down
# o['transform']['values'] = [1.0, 0.0, 0.0, bobject.location.x, 0.0, 1.0, 0.0, bobject.location.y, 0.0, 0.0, 1.0, bobject.location.z, 0.0, 0.0, 0.0, 1.0]
# if not hasattr(o, 'children'):
# o['children'] = []
# # Make child lamps
# for i in range(0, 5):
# child_lamp = {}
# child_lamp['name'] = o['name'] + '__' + str(i)
# child_lamp['data_ref'] = o['data_ref']
# child_lamp['type'] = 'lamp_object'
# if i == 0:
# mat = [0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0]
# elif i == 1:
# mat = [0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0]
# elif i == 2:
# mat = [0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0]
# elif i == 3:
# mat = [0.0, -1.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0]
# elif i == 4:
# mat = [-1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 1.0]
# child_lamp['transform'] = {}
# child_lamp['transform']['values'] = mat
# o['children'].append(child_lamp)
def export_object(self, bobject, scene, poseBone = None, parento = None):
# This function exports a single object in the scene and includes its name,
@ -1367,8 +1367,8 @@ class ArmoryExporter:
self.export_object_transform(bobject, scene, o)
# 6 directional lamps
if type == NodeTypeLamp and objref.type == 'POINT' and objref.lamp_omni_shadows:
self.make_fake_omni_lamps(o, bobject)
# if type == NodeTypeLamp and objref.type == 'POINT' and objref.lamp_omni_shadows:
# self.make_fake_omni_lamps(o, bobject)
# Viewport Camera - overwrite active camera matrix with viewport matrix
if type == NodeTypeCamera and bpy.data.worlds['Arm'].arm_play_viewport_camera and self.scene.camera != None and bobject.name == self.scene.camera.name:
@ -2101,7 +2101,8 @@ class ArmoryExporter:
# Fake omni shadows
if objref.lamp_omni_shadows:
o['fov'] = 1.5708 # 90 deg
o['strength'] /= 6
o['shadowmap_cube'] = True
# o['strength'] /= 6
self.output['lamp_datas'].append(o)

View file

@ -174,7 +174,7 @@ def parse_shader(sres, c, con, defs, lines, parse_attributes):
cid = s[2][:-1]
found = False # Unique check
if ctype == 'sampler2D' or ctype == 'sampler2DShadow' or ctype == 'sampler3D' or ctype == 'image2D' or ctype == 'image3D': # Texture unit
if ctype == 'sampler2D' or ctype == 'sampler2DShadow' or ctype == 'sampler3D' or ctype == 'samplerCube' or ctype == 'image2D' or ctype == 'image3D': # Texture unit
for tu in con['texture_units']: # Texture already present
if tu['name'] == cid:
found = True

View file

@ -844,14 +844,14 @@ def parse_render_target(node, node_group, render_targets, depth_buffers):
# Second shadowmap for point lamps
# TODO: check if lamp users are visible
for lamp in bpy.data.lamps:
if lamp.type == 'POINT':
# for lamp in bpy.data.lamps:
# if lamp.type == 'POINT':
# target = make_shadowmap_target(node, scale, '2')
# render_targets.append(target)
# break
# Clamp omni-shadows, remove
if lamp.lamp_omni_shadows:
bpy.data.worlds['Arm'].rp_defs += '_Clampstc'
# if lamp.lamp_omni_shadows:
# bpy.data.worlds['Arm'].rp_defs += '_Clampstc'
elif node.bl_idname == 'ImageNodeType' or node.bl_idname == 'Image3DNodeType':
# Target already exists
@ -896,7 +896,6 @@ def make_render_target(n, scale, depth_buffer_id=None):
def make_shadowmap_target(n, scale, postfix=''):
target = {}
# target['name'] = '_shadow_' + n.inputs[0].default_value + postfix
target['name'] = n.inputs[0].default_value + postfix
target['width'] = n.inputs[1].default_value
target['height'] = n.inputs[2].default_value

View file

@ -504,7 +504,7 @@ def init_properties():
bpy.types.Lamp.lamp_clip_end = bpy.props.FloatProperty(name="Clip End", default=50.0)
bpy.types.Lamp.lamp_fov = bpy.props.FloatProperty(name="Field of View", default=0.84)
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="Fakes omnidirectional shadows by creating 6 directional lights - will result in preformance loss - usable for deferred renderers only", default=False)
bpy.types.Lamp.lamp_omni_shadows = bpy.props.BoolProperty(name="Omnidirectional Shadows", description="Draw shadows to all faces of the cube map", default=True)
if not 'Arm' in bpy.data.worlds:
wrd = bpy.data.worlds.new('Arm')

View file

@ -187,9 +187,6 @@ class DataPropsPanel(bpy.types.Panel):
row.prop(obj.data, 'lamp_shadows_bias')
if obj.data.type == 'POINT':
layout.prop(obj.data, 'lamp_omni_shadows')
if obj.data.lamp_omni_shadows:
layout.label('Warning: Will result in performance loss.')
layout.label('Temporary implementation.')
elif obj.type == 'SPEAKER':
layout.prop(obj.data, 'loop')
layout.prop(obj.data, 'stream')