Correct displace amount

This commit is contained in:
luboslenco 2019-02-04 21:47:46 +01:00
parent f2f4f908be
commit cd7a25db37
4 changed files with 14 additions and 7 deletions

View file

@ -60,7 +60,7 @@ def make(context_id, rpasses, shadowmap=False):
if con_depth.is_elem('col'):
vert.add_out('vec3 vcolor')
vert.write_attrib('vcolor = col.rgb;')
vert.write('wposition += wnormal * disp * 0.1;')
vert.write('wposition += wnormal * disp;')
if shadowmap:
vert.add_uniform('mat4 LVP', '_lightViewProjectionMatrix')
vert.write('gl_Position = LVP * vec4(wposition, 1.0);')
@ -109,11 +109,11 @@ def make(context_id, rpasses, shadowmap=False):
if shadowmap:
tese.add_uniform('mat4 LVP', '_lightViewProjectionMatrix')
tese.write('wposition += wnormal * disp * 0.1;')
tese.write('wposition += wnormal * disp;')
tese.write('gl_Position = LVP * vec4(wposition, 1.0);')
else:
tese.add_uniform('mat4 VP', '_viewProjectionMatrix')
tese.write('wposition += wnormal * disp * 0.1;')
tese.write('wposition += wnormal * disp;')
tese.write('gl_Position = VP * vec4(wposition, 1.0);')
# No displacement
else:

View file

@ -180,7 +180,7 @@ def make_base(con_mesh, parse_opacity):
else:
sh = tese
sh.add_uniform('mat4 VP', '_viewProjectionMatrix')
sh.write('wposition += wnormal * disp * 0.1;')
sh.write('wposition += wnormal * disp;')
sh.write('gl_Position = VP * vec4(wposition, 1.0);')
def make_deferred(con_mesh, rpasses):

View file

@ -257,7 +257,7 @@ def init_properties():
bpy.types.Scene.arm_terrain_textures = StringProperty(name="Textures", description="Set root folder for terrain assets", default="", subtype="DIR_PATH")
bpy.types.Scene.arm_terrain_sectors = IntVectorProperty(name="Sectors", description="Number of sectors to generate", default=[1,1], size=2)
bpy.types.Scene.arm_terrain_sector_size = FloatProperty(name="Sector Size", description="Dimensions for single sector", default=16)
bpy.types.Scene.arm_terrain_height_scale = FloatProperty(name="Height Scale", description="Scale height from the 0-1 range", default=10)
bpy.types.Scene.arm_terrain_height_scale = FloatProperty(name="Height Scale", description="Scale height from the 0-1 range", default=5)
bpy.types.Scene.arm_terrain_object = PointerProperty(name="Object", type=bpy.types.Object, description="Terrain root object")
# For light
bpy.types.Light.arm_clip_start = FloatProperty(name="Clip Start", default=0.1)

View file

@ -1186,16 +1186,23 @@ class ArmGenTerrainButton(bpy.types.Operator):
links = mat.node_tree.links
node = nodes.new('ShaderNodeDisplacement')
node.location = (-200, 100)
node.inputs[2].default_value = height_scale * 10
node.inputs[2].default_value = height_scale
node.space = 'WORLD'
links.new(nodes['Material Output'].inputs[2], node.outputs[0])
node = nodes.new('ShaderNodeTexImage')
node.location = (-600, 100)
node.color_space = 'NONE'
node.interpolation = 'Closest'
node.extension = 'EXTEND'
node.arm_material_param = True
node.name = '_TerrainHeight'
node.label = '_TerrainHeight' # Height-map texture link for this sector
links.new(nodes['Displacement'].inputs[0], nodes['_TerrainHeight'].outputs[0])
node = nodes.new('ShaderNodeBump')
node.location = (-200, -200)
node.inputs[0].default_value = 5.0
links.new(nodes['Bump'].inputs[2], nodes['_TerrainHeight'].outputs[0])
links.new(nodes['Principled BSDF'].inputs[17], nodes['Bump'].outputs[0])
# Create sectors
root_obj = bpy.data.objects.new("Terrain", None)
@ -1213,7 +1220,7 @@ class ArmGenTerrainButton(bpy.types.Operator):
bpy.ops.mesh.primitive_plane_add(location=(x * size, -y * size, 0))
slice_obj = bpy.context.active_object
slice_obj.scale[0] = size / 2
slice_obj.scale[1] = size / 2
slice_obj.scale[1] = -(size / 2)
slice_obj.scale[2] = height_scale
slice_obj.data.materials.append(mat)
for p in slice_obj.data.polygons: