Static background node.

This commit is contained in:
Lubos Lenco 2016-11-03 19:07:16 +01:00
parent c8a65da54b
commit 52c516c957
5 changed files with 56 additions and 3 deletions

View file

@ -36,6 +36,10 @@ precision mediump float;
#ifdef _EnvTex
uniform sampler2D envmap;
#endif
#ifdef _EnvImg // Static background
uniform vec2 screenSize;
uniform sampler2D envmap;
#endif
// uniform sampler2D gbufferD;
uniform float envmapStrength; // From world material
@ -193,6 +197,12 @@ void main() {
#endif
#endif
#ifdef _EnvImg // Static background
// Will have to get rid of gl_FragCoord, pass tc from VS
vec2 texco = gl_FragCoord.xy / screenSize;
vec3 R = texture(envmap, vec2(texco.x, 1.0 - texco.y)).rgb * envmapStrength;
#endif
#ifdef _EnvSky
vec3 n = normalize(normal);
vec3 sunDir = vec3(sunDirection.x, -sunDirection.y, sunDirection.z);

View file

@ -79,6 +79,11 @@
"name": "eye",
"link": "_cameraPosition",
"ifdef": ["_XEnvClouds"]
},
{
"name": "screenSize",
"link": "_screenSize",
"ifdef": ["_EnvImg"]
}
],
"texture_params": [],

View file

@ -1924,7 +1924,7 @@ class ArmoryExporter:
elif objtype == 'SPOT':
o['type'] = 'spot'
o['spot_size'] = math.cos(objref.spot_size / 2)
o['spot_blend'] = objref.spot_blend
o['spot_blend'] = objref.spot_blend / 10 # Cycles defaults to 0.15
else: # Hemi, area
o['type'] = 'sun'

View file

@ -100,6 +100,7 @@ def make_texture(self, id, image_node, material, image_format='RGBA32'):
# Link image path to assets
assets.add(armutils.safe_assetpath(image.filepath))
# Reference image name
powimage = is_pow(image.size[0]) and is_pow(image.size[1])
tex['file'] = armutils.extract_filename(image.filepath)
tex['file'] = armutils.safe_filename(tex['file'])
if image_format != 'RGBA32':
@ -118,7 +119,7 @@ def make_texture(self, id, image_node, material, image_format='RGBA32'):
tex['u_addressing'] = 'clamp'
tex['v_addressing'] = 'clamp'
else:
if bpy.data.worlds['Arm'].npot_texture_repeat == False and (is_pow(image.size[0]) == False or is_pow(image.size[1]) == False):
if bpy.data.worlds['Arm'].npot_texture_repeat == False and powimage == False:
print('Armory Warning: ' + material.name + '/' + image.name + ' - non power of 2 texture can not use repeat mode')
tex['u_addressing'] = 'clamp'
tex['v_addressing'] = 'clamp'

View file

@ -46,7 +46,10 @@ def build_node_tree(world):
# Clear to color if no texture or sky is provided
wrd = bpy.data.worlds['Arm']
if '_EnvSky' not in wrd.world_defs and '_EnvTex' not in wrd.world_defs:
wrd.world_defs += '_EnvCol'
if '_EnvImg' not in wrd.world_defs:
wrd.world_defs += '_EnvCol'
# Irradiance json file name
world.world_envtex_name = world.name
world.world_envtex_irr_name = world.name
@ -175,6 +178,40 @@ def parse_color(world, node, context, envmap_strength_const):
if generate_radiance:
bpy.data.worlds['Arm'].world_defs += '_Rad'
# Static image background
elif node.type == 'TEX_IMAGE':
bpy.data.worlds['Arm'].world_defs += '_EnvImg'
texture = {}
context['bind_textures'].append(texture)
texture['name'] = 'envmap'
# No repeat for now
texture['u_addressing'] = 'clamp'
texture['v_addressing'] = 'clamp'
image = node.image
filepath = image.filepath
if image.packed_file != None:
# Extract packed data
filepath = '/build/compiled/Assets/unpacked'
unpack_path = armutils.get_fp() + filepath
if not os.path.exists(unpack_path):
os.makedirs(unpack_path)
unpack_filepath = unpack_path + '/' + image.name
if os.path.isfile(unpack_filepath) == False or os.path.getsize(unpack_filepath) != image.packed_file.size:
with open(unpack_filepath, 'wb') as f:
f.write(image.packed_file.data)
assets.add(unpack_filepath)
else:
# Link image path to assets
assets.add(armutils.safe_assetpath(image.filepath))
# Reference image name
texture['file'] = armutils.extract_filename(image.filepath)
texture['file'] = armutils.safe_filename(texture['file'])
# Append sky define
elif node.type == 'TEX_SKY':
envmap_strength_const['float'] *= 0.25 # Match to Cycles