mirror of
https://port.numenaute.org/aleajactaest/khanat-client.git
synced 2024-11-25 16:46:22 +00:00
EDIT amelioration du shader de terrain.
This commit is contained in:
parent
71bbdf4c0c
commit
c71b983694
7 changed files with 87 additions and 32 deletions
Binary file not shown.
|
@ -1,20 +1,29 @@
|
||||||
shader_type spatial;
|
shader_type spatial;
|
||||||
render_mode blend_mix,depth_draw_opaque,cull_back,diffuse_burley,specular_schlick_ggx;
|
render_mode blend_mix,depth_draw_opaque,cull_back,diffuse_burley,specular_schlick_ggx;
|
||||||
uniform vec4 albedo : hint_color;
|
uniform vec4 albedo : hint_color;
|
||||||
uniform sampler2D texture_albedo : hint_albedo;
|
uniform sampler2D texture_grass : hint_albedo;
|
||||||
uniform sampler2D texture_grass_2 : hint_albedo;
|
uniform sampler2D texture_grass_height : hint_white;
|
||||||
uniform sampler2D texture_albedo_2 : hint_albedo;
|
uniform sampler2D texture_dirt : hint_albedo;
|
||||||
uniform sampler2D texture_albedo_hsv : hint_white;
|
uniform sampler2D texture_dirt_height : hint_black;
|
||||||
|
uniform sampler2D texture_hsv_mask : hint_white;
|
||||||
|
uniform sampler2D texture_hsv2_mask : hint_white;
|
||||||
uniform sampler2D texture_albedo_mix : hint_black;
|
uniform sampler2D texture_albedo_mix : hint_black;
|
||||||
|
uniform sampler2D texture_mix_gradiant : hint_black;
|
||||||
|
uniform sampler2D texture_mix_border : hint_black;
|
||||||
|
|
||||||
|
uniform sampler2D texture_albedo_mix2 : hint_black;
|
||||||
uniform float specular;
|
uniform float specular;
|
||||||
uniform float metallic;
|
uniform float metallic;
|
||||||
uniform float roughness : hint_range(0,1);
|
uniform float roughness : hint_range(0,1);
|
||||||
uniform float point_size : hint_range(0,128);
|
uniform float point_size : hint_range(0,128);
|
||||||
uniform sampler2D texture_roughness : hint_white;
|
uniform sampler2D texture_roughness : hint_white;
|
||||||
|
uniform sampler2D texture_roughness_dirt : hint_white;
|
||||||
uniform vec4 roughness_texture_channel;
|
uniform vec4 roughness_texture_channel;
|
||||||
uniform sampler2D texture_normal : hint_normal;
|
uniform sampler2D texture_normal : hint_normal;
|
||||||
|
uniform sampler2D texture_normal_dirt : hint_normal;
|
||||||
uniform float normal_scale : hint_range(-16,16);
|
uniform float normal_scale : hint_range(-16,16);
|
||||||
uniform sampler2D texture_ambient_occlusion : hint_white;
|
uniform sampler2D texture_ambient_occlusion : hint_white;
|
||||||
|
uniform sampler2D texture_ambient_occlusion_dirt : hint_white;
|
||||||
uniform vec4 ao_texture_channel;
|
uniform vec4 ao_texture_channel;
|
||||||
uniform float ao_light_affect;
|
uniform float ao_light_affect;
|
||||||
uniform vec3 uv1_scale;
|
uniform vec3 uv1_scale;
|
||||||
|
@ -24,13 +33,12 @@ uniform vec3 uv2_offset;
|
||||||
|
|
||||||
uniform vec3 hsv;
|
uniform vec3 hsv;
|
||||||
uniform float grass_level = 1.0;
|
uniform float grass_level = 1.0;
|
||||||
|
uniform float angle = 0.0;
|
||||||
|
|
||||||
varying vec2 base_uv;
|
varying vec2 base_uv;
|
||||||
varying vec2 rotated_uv;
|
varying vec2 rotated_uv;
|
||||||
varying vec2 rotated_uv_mask;
|
varying vec2 rotated_uv_mask;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
vec2 rotateUVmatrinx(vec2 uv, vec2 pivot, float rotation)
|
vec2 rotateUVmatrinx(vec2 uv, vec2 pivot, float rotation)
|
||||||
{
|
{
|
||||||
mat2 rotation_matrix=mat2( vec2(sin(rotation),-cos(rotation)),
|
mat2 rotation_matrix=mat2( vec2(sin(rotation),-cos(rotation)),
|
||||||
|
@ -71,44 +79,91 @@ vec3 hsv2rgb(vec3 c)
|
||||||
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
|
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void vertex() {
|
|
||||||
|
|
||||||
|
void vertex()
|
||||||
|
{
|
||||||
base_uv=UV*uv1_scale.xy+uv1_offset.xy;
|
base_uv=UV*uv1_scale.xy+uv1_offset.xy;
|
||||||
rotated_uv = rotateUVmatrinx(base_uv, vec2(0.5), (VERTEX.x));
|
rotated_uv = rotateUVmatrinx(base_uv, vec2(0.5), (angle));
|
||||||
rotated_uv = base_uv;
|
// rotated_uv = base_uv;
|
||||||
rotated_uv_mask = rotateUVmatrinx(UV, vec2(0.5), (VERTEX.x));
|
rotated_uv_mask = rotateUVmatrinx(UV, vec2(0.5), (angle));
|
||||||
rotated_uv_mask = UV;
|
// rotated_uv_mask = UV;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void fragment() {
|
void fragment()
|
||||||
|
{
|
||||||
// vec2 base_uv = UV;
|
// vec2 base_uv = UV;
|
||||||
vec4 albedo_tex = texture(texture_albedo,rotated_uv);
|
vec4 grass_tex = texture(texture_grass,base_uv);
|
||||||
vec4 grass_2_tex = texture(texture_grass_2,rotated_uv);
|
vec4 grass_height_tex = texture(texture_grass_height,base_uv);
|
||||||
vec4 albedo_2_tex = texture(texture_albedo_2,rotated_uv);
|
vec4 dirt_tex = texture(texture_dirt,base_uv);
|
||||||
vec4 albedo_hsv_tex = texture(texture_albedo_hsv,rotated_uv_mask);
|
vec4 dirt_height_tex = texture(texture_dirt_height,base_uv);
|
||||||
vec4 albedo_mix_tex = texture(texture_albedo_mix,rotated_uv_mask);
|
vec4 dirt_height_hsv_tex = texture(texture_dirt_height,rotated_uv_mask);
|
||||||
ALBEDO = albedo.rgb * albedo_tex.rgb;
|
vec4 hsv_mask_tex = texture(texture_hsv_mask,UV);
|
||||||
|
vec4 hsv2_mask_tex = texture(texture_hsv2_mask,UV*vec2(5.0,5.0));
|
||||||
// ALBEDO = mix( ALBEDO, grass_2_tex.rgb, 0.5 );
|
vec4 albedo_mix_tex = texture(texture_albedo_mix,UV);
|
||||||
|
vec4 mix_gradiant_tex = texture(texture_mix_gradiant,vec2( albedo_mix_tex.r, albedo_mix_tex.r ));
|
||||||
|
vec4 albedo_mix_tex_low = texture(texture_albedo_mix,UV*vec2(5.0,5.0));
|
||||||
|
vec4 mix_gradiant_low_tex = texture(texture_mix_gradiant,vec2( albedo_mix_tex_low.r, albedo_mix_tex_low.r ));
|
||||||
|
vec4 mix_gradiant_border = texture(texture_mix_border,vec2( albedo_mix_tex_low.r, albedo_mix_tex_low.r ));
|
||||||
|
vec4 albedo_mix_tex2 = texture(texture_albedo_mix2,base_uv);
|
||||||
|
vec4 mix_gradiant2_tex = texture(texture_mix_gradiant,vec2( albedo_mix_tex2.r, albedo_mix_tex2.r ));
|
||||||
|
ALBEDO = albedo.rgb * grass_tex.rgb;
|
||||||
|
|
||||||
vec3 hsv_albedo = rgb2hsv(ALBEDO);
|
vec3 hsv_albedo = rgb2hsv(ALBEDO);
|
||||||
vec3 hsv_mask = rgb2hsv( albedo_hsv_tex.rgb );
|
vec3 hsv_mask = rgb2hsv( hsv_mask_tex.rgb );
|
||||||
hsv_albedo.x = hsv_mask.x;
|
vec3 hsv2_mask = rgb2hsv( hsv2_mask_tex.rgb );
|
||||||
hsv_albedo.y = hsv_mask.y;
|
hsv_albedo.x *= hsv.x;
|
||||||
hsv_albedo.z *= hsv_mask.z;
|
hsv_albedo.y = hsv.y;
|
||||||
|
hsv_albedo.z *= hsv.z * (hsv_mask.z * hsv2_mask.z*2.0);
|
||||||
ALBEDO = hsv2rgb( hsv_albedo );
|
ALBEDO = hsv2rgb( hsv_albedo );
|
||||||
|
|
||||||
ALBEDO = mix( ALBEDO, albedo_2_tex.rgb, min( 1.0, max(-1.0, albedo_mix_tex.r-grass_level)) );
|
|
||||||
|
vec4 mix_mix = mix( mix_gradiant_tex, mix_gradiant2_tex, 0.5 );
|
||||||
|
|
||||||
|
float mix_level = clamp( mix_gradiant_tex.r*mix_gradiant_border.r-grass_level, 0.0, 1.0 );
|
||||||
|
|
||||||
|
// if ( grass_height_tex.r > 0.5 )
|
||||||
|
// {
|
||||||
|
//// mix_level = 0.0;
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// mix_level = 1.0;
|
||||||
|
// }
|
||||||
|
if ( mix_level > 0.0 && mix_level < 1.0 )
|
||||||
|
{
|
||||||
|
if ( grass_height_tex.r < dirt_height_tex.r )
|
||||||
|
{
|
||||||
|
mix_level = 1.0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mix_level = 0.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mix_level *= mix_level;
|
||||||
|
mix_level *= mix_level;
|
||||||
|
mix_level *= mix_level;
|
||||||
|
vec3 hsv_dirt = rgb2hsv(dirt_tex.rgb);
|
||||||
|
vec3 hsv_dirt_height = rgb2hsv(dirt_height_hsv_tex.rgb);
|
||||||
|
hsv_dirt.y = hsv.y*hsv_mask.z;
|
||||||
|
hsv_dirt.z *= hsv.z*hsv_mask.z;
|
||||||
|
dirt_tex.rgb = hsv2rgb( hsv_dirt );
|
||||||
|
ALBEDO = mix( ALBEDO, dirt_tex.rgb, mix_level );
|
||||||
|
|
||||||
METALLIC = metallic;
|
METALLIC = metallic;
|
||||||
float roughness_tex = dot(texture(texture_roughness,rotated_uv),roughness_texture_channel);
|
vec4 final_roughness = mix( texture(texture_roughness,base_uv),texture(texture_roughness_dirt,base_uv), mix_level );
|
||||||
ROUGHNESS = roughness_tex * roughness;
|
ROUGHNESS = dot(final_roughness, roughness_texture_channel) * roughness;
|
||||||
SPECULAR = specular;
|
SPECULAR = specular;
|
||||||
NORMALMAP = texture(texture_normal,rotated_uv).rgb;
|
vec4 final_normal = mix( texture(texture_normal,base_uv), texture(texture_normal_dirt,base_uv), mix_level );
|
||||||
|
NORMALMAP = final_normal.rgb;
|
||||||
NORMALMAP_DEPTH = normal_scale;
|
NORMALMAP_DEPTH = normal_scale;
|
||||||
AO = dot(texture(texture_ambient_occlusion,rotated_uv),ao_texture_channel);
|
vec4 final_ao = mix( texture(texture_ambient_occlusion,base_uv), texture(texture_ambient_occlusion_dirt,base_uv), mix_level );
|
||||||
|
AO = dot(final_ao,ao_texture_channel);
|
||||||
AO_LIGHT_AFFECT = ao_light_affect;
|
AO_LIGHT_AFFECT = ao_light_affect;
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
BIN
assets/decors/terrains/demo/textures/grass_hsv2.png
Normal file
BIN
assets/decors/terrains/demo/textures/grass_hsv2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.4 MiB |
BIN
assets/decors/terrains/demo/textures/mix_mask.jpg
Normal file
BIN
assets/decors/terrains/demo/textures/mix_mask.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 140 KiB |
BIN
assets/decors/terrains/demo/textures/mix_mask_2.jpg
Normal file
BIN
assets/decors/terrains/demo/textures/mix_mask_2.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 716 KiB |
|
@ -25,8 +25,8 @@ noise = SubResource( 1 )
|
||||||
[sub_resource type="ShaderMaterial" id=3]
|
[sub_resource type="ShaderMaterial" id=3]
|
||||||
resource_local_to_scene = true
|
resource_local_to_scene = true
|
||||||
shader = ExtResource( 5 )
|
shader = ExtResource( 5 )
|
||||||
shader_param/iTime = 92.0443
|
shader_param/iTime = 3.93876
|
||||||
shader_param/iFrame = 3942
|
shader_param/iFrame = 307
|
||||||
shader_param/COVERAGE = 0.5
|
shader_param/COVERAGE = 0.5
|
||||||
shader_param/THICKNESS = 25.0
|
shader_param/THICKNESS = 25.0
|
||||||
shader_param/ABSORPTION = 1.031
|
shader_param/ABSORPTION = 1.031
|
||||||
|
|
Loading…
Reference in a new issue