Textured lamp test, fixes.

This commit is contained in:
Lubos Lenco 2016-11-05 20:57:04 +01:00
parent 16771d48a1
commit bcc6dbdf91
36 changed files with 80 additions and 26 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -6,6 +6,7 @@ precision mediump float;
#include "../compiled.glsl"
#include "../std/brdf.glsl"
#include "../std/math.glsl"
// ...
#ifndef _NoShadows
#ifdef _PCSS
@ -45,7 +46,6 @@ uniform vec3 lightPos;
uniform vec3 lightDir;
uniform int lightType;
// uniform int lightIndex;
uniform vec3 lightColor;
uniform float lightStrength;
uniform float shadowsBias;
uniform float spotlightCutoff;
@ -54,6 +54,12 @@ uniform vec3 eye;
// uniform vec3 eyeLook;
// uniform vec2 screenSize;
#ifdef _LampTex
uniform sampler2D texlampcolor;
#else
uniform vec3 lightColor;
#endif
// in vec2 texCoord;
in vec4 wvpposition;
// in vec3 viewRay;
@ -166,8 +172,14 @@ void main() {
// vec3 fiberDirection = vec3(0.0, 1.0, 8.0);
// vec3 direct = diffuseBRDF(albedo, metrough.y, dotNV, dotNL, dotVH, dotLV) + wardSpecular(n, h, dotNL, dotNV, dotNH, fiberDirection, shinyParallel, shinyPerpendicular);
// #endif
direct = direct * lightColor * lightStrength;
direct = direct * lightStrength;
#ifdef _LampTex
direct *= texture(texlampcolor, envMapEquirect(l)).rgb;
// direct *= texture(texlampcolor, l.xy).rgb;
#else
direct *= lightColor;
#endif
#ifdef _SSS
float mask = g0.a;

View file

@ -35,7 +35,13 @@
},
{
"name": "lightColor",
"link": "_lampColor"
"link": "_lampColor",
"ifndef": ["_LampColTex"]
},
{
"name": "texlampcolor",
"link": "_lampColorTexture",
"ifdef": ["_LampColTex"]
},
{
"name": "lightStrength",

View file

@ -1938,18 +1938,8 @@ class ArmoryExporter:
if objref.shadow_soft_size != 0.1:
o['lamp_size'] = objref.shadow_soft_size
# Parse nodes, only emission for now
# Merge with make_material
for n in objref.node_tree.nodes:
if n.type == 'EMISSION':
col = n.inputs[0].default_value
o['color'] = [col[0], col[1], col[2]]
o['strength'] = n.inputs[1].default_value
# Normalize point/spot strength
if o['type'] != 'sun':
o['strength'] /= 1000.0
break
# Parse nodes
make_material.parse_lamp(objref.node_tree, o)
self.output['lamp_datas'].append(o)
def export_camera(self, objectRef):

View file

@ -247,7 +247,7 @@ def parse_shader(sres, c, con, defs, lines, parse_attributes):
if 'ifndef' in l:
def_found = False
for d in defs:
for link_def in l['ifdef']:
for link_def in l['ifndef']:
if d == link_def:
def_found = True
break

View file

@ -32,3 +32,6 @@ def print_progress(value):
def get_progress(self):
global progress
return progress
def warn(text):
print('Armory Warning: ' + text)

View file

@ -4,6 +4,7 @@ import assets
import armutils
import os
import nodes
import log
def is_pow(num):
return ((num & (num - 1)) == 0) and num != 0
@ -41,6 +42,27 @@ def parse(self, material, c, defs):
defs.append('_Tex')
break
def parse_lamp(tree, o):
# Emission only for now
for n in tree.nodes:
if n.type == 'EMISSION':
col = n.inputs[0].default_value
o['color'] = [col[0], col[1], col[2]]
o['strength'] = n.inputs[1].default_value
# Normalize point/spot strength
if o['type'] != 'sun':
o['strength'] /= 1000.0
# Texture test..
if n.inputs[0].is_linked:
color_node = nodes.find_node_by_link(tree, n, n.inputs[0])
if color_node.type == 'TEX_IMAGE':
o['color_texture'] = color_node.image.name
make_texture(None, '', color_node, None)
# bpy.data.worlds['Arm'].world_defs += '_LampTex'
break
def make_albedo_const(col, c):
const = {}
parse.const_color = const
@ -102,6 +124,9 @@ def make_texture(self, id, image_node, material, image_format='RGBA32'):
# Reference image name
powimage = is_pow(image.size[0]) and is_pow(image.size[1])
tex['file'] = armutils.extract_filename(image.filepath)
ext = tex['file'][-3:].lower()
if ext != 'jpg' and ext != 'png' and ext != 'hdr':
log.warn(material.name + '/' + image.name + ' - image format is not supported yet. Use jpg, png, hdr.')
tex['file'] = armutils.safe_filename(tex['file'])
if image_format != 'RGBA32':
tex['format'] = image_format
@ -460,7 +485,12 @@ def parse_pbr_group(self, material, c, defs, tree, node, factor):
roughness_strength_input = node.inputs[4]
roughness_strength = roughness_strength_input.default_value
if roughness_strength != 1.0:
add_roughness_strength(self, c, defs, roughness_strength)
if roughness_input.is_linked:
add_roughness_strength(self, c, defs, roughness_strength)
else:
# No texture, multiply roughness float instead
const = parse.const_roughness
const['float'] *= roughness_strength
# Metalness Map
metalness_input = node.inputs[5]
parse_metalness_socket(self, metalness_input, material, c, defs, tree, node, factor)

View file

@ -129,6 +129,8 @@ def parse_surface(world, node, context):
world.world_envtex_strength = envmap_strength_const['float']
def parse_color(world, node, context, envmap_strength_const):
wrd = bpy.data.worlds['Arm']
# Env map included
if node.type == 'TEX_ENVIRONMENT':
envmap_strength_const['float'] *= 2.0 # Match to cycles
@ -160,7 +162,7 @@ def parse_color(world, node, context, envmap_strength_const):
texture['file'] = armutils.safe_filename(texture['file'])
# Generate prefiltered envmaps
generate_radiance = bpy.data.worlds['Arm'].generate_radiance
generate_radiance = wrd.generate_radiance
world.world_envtex_name = texture['file']
world.world_envtex_irr_name = texture['file'].rsplit('.', 1)[0]
disable_hdr = image.filepath.endswith('.jpg')
@ -234,14 +236,19 @@ def parse_color(world, node, context, envmap_strength_const):
write_probes.write_sky_irradiance(world.name)
# Radiance
if bpy.data.worlds['Arm'].generate_radiance_sky and bpy.data.worlds['Arm'].generate_radiance:
if wrd.generate_radiance_sky and wrd.generate_radiance:
bpy.data.worlds['Arm'].world_defs += '_Rad'
if wrd.generate_radiance_sky_type == 'Hosek':
hosek_path = 'armory/Assets/hosek/'
else:
hosek_path = 'armory/Assets/hosek_fake/'
sdk_path = armutils.get_sdk_path()
# Use fake maps for now
assets.add(sdk_path + 'armory/Assets/hosek/hosek_radiance.hdr')
assets.add(sdk_path + hosek_path + 'hosek_radiance.hdr')
for i in range(0, 8):
assets.add(sdk_path + 'armory/Assets/hosek/hosek_radiance_' + str(i) + '.hdr')
assets.add(sdk_path + hosek_path + 'hosek_radiance_' + str(i) + '.hdr')
world.world_envtex_name = 'hosek'
world.world_envtex_num_mips = 8

View file

@ -150,6 +150,10 @@ def init_properties():
bpy.types.World.world_defs = bpy.props.StringProperty(name="World Shader Defs", default='')
bpy.types.World.generate_radiance = bpy.props.BoolProperty(name="Probe Radiance", default=True, update=assets.invalidate_shader_cache)
bpy.types.World.generate_radiance_sky = bpy.props.BoolProperty(name="Sky Radiance", default=False, update=assets.invalidate_shader_cache)
bpy.types.World.generate_radiance_sky_type = EnumProperty(
items=[('Fake', 'Fake', 'Fake'),
('Hosek', 'Hosek', 'Hosek')],
name="Type", description="Prefiltered maps to be used for radiance.", default='Fake')
bpy.types.World.generate_clouds = bpy.props.BoolProperty(name="Clouds", default=False, update=assets.invalidate_shader_cache)
bpy.types.World.generate_clouds_density = bpy.props.FloatProperty(name="Density", default=0.5, min=0.0, max=10.0, update=assets.invalidate_shader_cache)
bpy.types.World.generate_clouds_size = bpy.props.FloatProperty(name="Size", default=1.0, min=0.0, max=10.0, update=assets.invalidate_shader_cache)
@ -178,9 +182,9 @@ def init_properties():
bpy.types.World.generate_ssao_texture_scale = bpy.props.FloatProperty(name="Texture Scale", default=1.0, min=0.0, max=1.0, update=assets.invalidate_shader_cache)
bpy.types.World.generate_shadows = bpy.props.BoolProperty(name="Shadows", default=True, update=assets.invalidate_shader_cache)
bpy.types.World.generate_bloom = bpy.props.BoolProperty(name="Bloom", default=True, update=assets.invalidate_shader_cache)
bpy.types.World.generate_bloom_treshold = bpy.props.FloatProperty(name="Treshold", default=6.0, update=assets.invalidate_shader_cache)
bpy.types.World.generate_bloom_strength = bpy.props.FloatProperty(name="Strength", default=1.0, update=assets.invalidate_shader_cache)
bpy.types.World.generate_bloom_radius = bpy.props.FloatProperty(name="Radius", default=1.0, update=assets.invalidate_shader_cache)
bpy.types.World.generate_bloom_treshold = bpy.props.FloatProperty(name="Treshold", default=20.0, update=assets.invalidate_shader_cache)
bpy.types.World.generate_bloom_strength = bpy.props.FloatProperty(name="Strength", default=0.5, update=assets.invalidate_shader_cache)
bpy.types.World.generate_bloom_radius = bpy.props.FloatProperty(name="Radius", default=0.5, update=assets.invalidate_shader_cache)
bpy.types.World.generate_motion_blur = bpy.props.BoolProperty(name="Motion Blur", default=True, update=assets.invalidate_shader_cache)
bpy.types.World.generate_motion_blur_intensity = bpy.props.FloatProperty(name="Intensity", default=1.0, update=assets.invalidate_shader_cache)
bpy.types.World.generate_ssr = bpy.props.BoolProperty(name="SSR", description="Screen-Space Reflections", default=True, update=assets.invalidate_shader_cache)
@ -255,7 +259,7 @@ def init_properties():
bpy.types.Lamp.lamp_clip_start = bpy.props.FloatProperty(name="Clip Start", default=0.1)
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="Shadows Bias", description="Depth offset for shadow acne", default=0.00037)
bpy.types.Lamp.lamp_shadows_bias = bpy.props.FloatProperty(name="Shadows Bias", description="Depth offset for shadow acne", default=0.0002)
if not 'Arm' in bpy.data.worlds:
wrd = bpy.data.worlds.new('Arm')

View file

@ -318,6 +318,8 @@ class WorldPropsPanel(bpy.types.Panel):
layout.prop(wrd, 'generate_radiance')
if wrd.generate_radiance:
layout.prop(wrd, 'generate_radiance_sky')
if wrd.generate_radiance_sky:
layout.prop(wrd, 'generate_radiance_sky_type')
layout.prop(wrd, 'generate_clouds')
if wrd.generate_clouds:
layout.prop(wrd, 'generate_clouds_density')