Adjust normal map calculations for terrain shading
This commit is contained in:
parent
9a144705f5
commit
72d295e266
BIN
editor.scn (Stored with Git LFS)
BIN
editor.scn (Stored with Git LFS)
Binary file not shown.
|
@ -58,7 +58,7 @@ var size: Vector2i = Vector2i.ZERO:
|
|||
RenderingServer.instance_set_base(self.get_instance(),
|
||||
surface_tool.commit(self._mesh).get_rid())
|
||||
|
||||
self._material.set_shader_parameter("AREA", Vector2(value))
|
||||
self._material.set_shader_parameter("SIZE", Vector2(value))
|
||||
self._mesh.surface_set_material(0, self._material)
|
||||
|
||||
size = value
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
shader_type spatial;
|
||||
|
||||
uniform vec2 AREA;
|
||||
|
||||
uniform sampler2D LAYER_1_ALBEDO : hint_default_black;
|
||||
|
||||
uniform sampler2D LAYER_1_NORMAL_MAP : hint_default_black;
|
||||
|
@ -20,10 +18,12 @@ uniform sampler2D LAYER_4_NORMAL_MAP : hint_default_black;
|
|||
|
||||
uniform float MAX_HEIGHT = 100.0;
|
||||
|
||||
uniform vec2 SIZE;
|
||||
|
||||
uniform sampler2D TERRAIN_MAP : hint_default_transparent, repeat_disable;
|
||||
|
||||
void fragment() {
|
||||
vec2 uv = UV * AREA;
|
||||
vec2 uv = UV * SIZE;
|
||||
vec2 uv_alt = uv * -0.25;
|
||||
vec3 splat_map = texture(TERRAIN_MAP, UV).rgb;
|
||||
float blank = clamp(1.0 - splat_map.r - splat_map.g - splat_map.b, 0.0, 1.0);
|
||||
|
@ -46,10 +46,11 @@ float height(vec2 uv) {
|
|||
void vertex() {
|
||||
VERTEX.y = height(UV);
|
||||
|
||||
float left = height(vec2(UV.x - 1.0, UV.y));
|
||||
float right = height(vec2(UV.x + 1.0, UV.y));
|
||||
float forward = height(vec2(UV.x, UV.y + 1.0));
|
||||
float backward = height(vec2(UV.x, UV.y - 1.0));
|
||||
vec2 texel = vec2(1.0, 1.0) / SIZE;
|
||||
float left = height(vec2(UV.x - texel.x, UV.y));
|
||||
float right = height(vec2(UV.x + texel.x, UV.y));
|
||||
float forward = height(vec2(UV.x, UV.y + texel.y));
|
||||
float backward = height(vec2(UV.x, UV.y - texel.y));
|
||||
|
||||
NORMAL = normalize(vec3(left - right, 2.0, forward - forward));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue