Fix refract

This commit is contained in:
Lubos Lenco 2017-10-16 09:25:18 +02:00
parent 5b91790265
commit d6d4112c5b
6 changed files with 51 additions and 31 deletions

View file

@ -251,6 +251,11 @@ void main() {
fragColor.rgb *= visibility;
#ifdef _VoxelGIRefract
fragColor.rgb = mix(traceRefraction(p / voxelgiDimensions, n, -v, metrough.y), fragColor.rgb, g1.a);
#ifdef _VoxelGICam
vec3 voxposr = (p - eyeSnap) / voxelgiHalfExtents;
#else
vec3 voxposr = p / voxelgiHalfExtents;
#endif
fragColor.rgb = mix(traceRefraction(voxposr, n, -v, metrough.y), fragColor.rgb, g1.a);
#endif
}

View file

@ -904,17 +904,17 @@ def parse_normal_map_color_input(inp):
parse_teximage_vector = False # Force texCoord for normal map image vector
defplus = c_state.get_rp_renderer() == 'Deferred Plus'
if not c_state.get_arm_export_tangents() or defplus or c_state.mat_get_material().arm_decal: # Compute TBN matrix
frag.write('vec3 texn = ({0}) * 2.0 - 1.0;'.format(parse_vector_input(inp)))
frag.write(' vec3 texn = ({0}) * 2.0 - 1.0;'.format(parse_vector_input(inp)))
frag.add_include('../../Shaders/std/normals.glsl')
if defplus:
frag.write('mat3 TBN = cotangentFrame(n, -vVec, g2.xy, g2.zw);')
frag.write(' mat3 TBN = cotangentFrame(n, -vVec, g2.xy, g2.zw);')
else:
frag.write('mat3 TBN = cotangentFrame(n, -vVec, texCoord);')
frag.write('n = TBN * normalize(texn);')
frag.write(' mat3 TBN = cotangentFrame(n, -vVec, texCoord);')
frag.write(' n = TBN * normalize(texn);')
else:
frag.write('vec3 n = ({0}) * 2.0 - 1.0;'.format(parse_vector_input(inp)))
# frag.write('n = normalize(TBN * normalize(n));')
frag.write('n = TBN * normalize(n);')
frag.write(' vec3 n = ({0}) * 2.0 - 1.0;'.format(parse_vector_input(inp)))
# frag.write(' n = normalize(TBN * normalize(n));')
frag.write(' n = TBN * normalize(n);')
con.add_elem('tang', 3)
parse_teximage_vector = True

View file

@ -110,7 +110,7 @@ def make_base(con_mesh, parse_opacity):
tese = None
vert.add_uniform('mat3 N', '_normalMatrix')
vert.write_main_header('vec4 spos = vec4(pos, 1.0);')
vert.write_main_header(' vec4 spos = vec4(pos, 1.0);')
vattr_written = False
is_displacement = mat_utils.disp_linked(mat_state.output_node)
@ -178,7 +178,7 @@ def make_base(con_mesh, parse_opacity):
if con_mesh.is_elem('tex'):
vert.add_out('vec2 texCoord')
if mat_state.material.arm_tilesheet_mat:
if mat_state.material.arm_particle != 'off':
if mat_state.material.arm_particle == 'gpu':
make_particle.write_tilesheet(vert)
else:
vert.add_uniform('vec2 tilesheetOffset', '_tilesheetOffset')
@ -228,7 +228,7 @@ def make_base(con_mesh, parse_opacity):
vert.add_out('vec3 wnormal')
write_norpos(con_mesh, vert)
frag.write_pre = True
frag.write_main_header('vec3 n = normalize(wnormal);')
frag.write_main_header(' vec3 n = normalize(wnormal);')
frag.write_pre = False
if tese != None:
@ -438,16 +438,18 @@ def make_forward_mobile(con_mesh):
# frag.write(' visibility = max(float(texture(shadowMap, lpos.xy).r + shadowsBias > lpos.z), 0.5);')
frag.write(' }')
frag.add_out('vec4 fragColor')
blend = mat_state.material.arm_blending
if blend:
# frag.write('fragColor = vec4(basecol * visibility, 1.0);')
frag.write('fragColor = vec4(basecol, 1.0);')
return
frag.write('vec3 direct = basecol * dotNL * lightColor;')
frag.write('direct += vec3(D_Approx(max(roughness, 0.3), dot(reflect(-vVec, n), lightDir)));')
frag.write('direct *= attenuate(distance(wposition, lightPos));')
frag.add_out('vec4 fragColor')
blend = mat_state.material.arm_blending
if blend:
frag.write('fragColor = vec4(basecol * visibility, 1.0);')
else:
frag.write('fragColor = vec4(direct * visibility + basecol * 0.5 * envmapStrength, 1.0);')
frag.write('fragColor = vec4(direct * visibility + basecol * 0.5 * envmapStrength, 1.0);')
if '_LDR' in wrd.world_defs:
frag.write('fragColor.rgb = pow(fragColor.rgb, vec3(1.0 / 2.2));')
@ -493,18 +495,15 @@ def make_forward(con_mesh):
make_forward_base(con_mesh)
frag = con_mesh.frag
frag.add_out('vec4 fragColor')
blend = mat_state.material.arm_blending
if blend:
frag.write('fragColor = vec4(basecol * lightColor * visibility, 1.0);')
else:
frag.write('fragColor = vec4(direct * lightColor * visibility + indirect * occlusion * envmapStrength, 1.0);')
if not blend:
frag.add_out('vec4 fragColor')
if '_LDR' in wrd.world_defs:
frag.add_include('../../Shaders/std/tonemap.glsl')
frag.write('fragColor.rgb = tonemapFilmic(fragColor.rgb);')
# frag.write('fragColor.rgb = pow(fragColor.rgb, vec3(1.0 / 2.2));')
if '_LDR' in wrd.world_defs:
frag.add_include('../../Shaders/std/tonemap.glsl')
frag.write('fragColor.rgb = tonemapFilmic(fragColor.rgb);')
# frag.write('fragColor.rgb = pow(fragColor.rgb, vec3(1.0 / 2.2));')
# Particle opacity
if mat_state.material.arm_particle == 'gpu' and mat_state.material.arm_particle_fade:
@ -527,7 +526,7 @@ def make_forward_base(con_mesh, parse_opacity=False):
frag.main_pre += """
vec3 vVec = normalize(eyeDir);
float dotNV = max(dot(n, vVec), 0.0);
"""
"""
if is_displacement:
tese.add_out('vec3 eyeDir')
@ -615,6 +614,14 @@ def make_forward_base(con_mesh, parse_opacity=False):
frag.write(' }')
frag.write('}')
blend = mat_state.material.arm_blending
if blend:
frag.add_out('vec4 fragColor')
# frag.write('fragColor = vec4(basecol * lightColor * visibility, 1.0);')
frag.write('fragColor = vec4(basecol, 1.0);')
# TODO: Fade out fragments near depth buffer here
return
frag.write('vec3 albedo = surfaceAlbedo(basecol, metallic);')
frag.write('vec3 f0 = surfaceF0(basecol, metallic);')
frag.write('vec3 direct;')

View file

@ -14,7 +14,7 @@ def write(vert, particle_info=None):
vert.add_uniform('mat4 pd', '_particleData')
str_tex_hash = "float fhash(float n) { return fract(sin(n) * 43758.5453); }"
str_tex_hash = " float fhash(float n) { return fract(sin(n) * 43758.5453); }"
vert.add_function(str_tex_hash)
prep = 'float '

View file

@ -3,6 +3,7 @@ import arm.utils
import arm.material.cycles as cycles
import arm.material.mat_state as mat_state
import arm.material.mat_utils as mat_utils
import arm.material.make_particle as make_particle
def make(context_id):
rpdat = arm.utils.get_rp()
@ -113,6 +114,11 @@ def make_gi(context_id):
frag.write('float dotNV = 0.0;')
cycles.parse(mat_state.nodes, con_voxel, vert, frag, geom, tesc, tese, parse_opacity=parse_opacity, parse_displacement=False, basecol_only=True)
# Voxelized particles
# particle = mat_state.material.arm_particle
# if particle == 'gpu':
# make_particle.write(vert, particle_info=cycles.particle_info)
if not frag.contains('vec3 n ='):
frag.write_pre = True
frag.write('vec3 n;')

View file

@ -969,9 +969,6 @@ class ArmRenderPathPanel(bpy.types.Panel):
layout.prop(rpdat, "rp_sss_state")
layout.prop(rpdat, "rp_blending_state")
layout.prop(rpdat, "rp_background")
layout.prop(rpdat, "rp_hdr")
layout.prop(rpdat, "rp_stereo")
layout.prop(rpdat, "rp_greasepencil")
layout.prop(rpdat, 'rp_gi')
if rpdat.rp_gi != 'Off':
layout.prop(rpdat, 'rp_voxelgi_resolution')
@ -986,6 +983,11 @@ class ArmRenderPathPanel(bpy.types.Panel):
# layout.prop(rpdat, 'rp_voxelgi_hdr')
if rpdat.rp_gi == 'Voxel GI':
layout.prop(rpdat, 'arm_voxelgi_emission')
layout.separator()
layout.prop(rpdat, "rp_hdr")
layout.prop(rpdat, "rp_stereo")
layout.prop(rpdat, "rp_greasepencil")
layout.separator()
layout.prop(rpdat, "rp_render_to_texture")