Add vertical / horizontal mapping for snow, sand, moss, etc (everything going on top of something)
This commit is contained in:
parent
daf4721fa9
commit
434f74b4ac
@ -37,6 +37,7 @@ out vec2 uv;
|
|||||||
out vec2 uv_two;
|
out vec2 uv_two;
|
||||||
out vec4 color;
|
out vec4 color;
|
||||||
out vec4 world_position;
|
out vec4 world_position;
|
||||||
|
out vec3 world_normal;
|
||||||
out float camdist;
|
out float camdist;
|
||||||
out float hue_change;
|
out float hue_change;
|
||||||
|
|
||||||
@ -52,15 +53,15 @@ void main()
|
|||||||
vec4 quaternion = normalize(vec4(i_rotation.xyz, i_scale.w));
|
vec4 quaternion = normalize(vec4(i_rotation.xyz, i_scale.w));
|
||||||
vec4 v_world_position = getWorldPosition(i_origin, quaternion, i_scale.xyz,
|
vec4 v_world_position = getWorldPosition(i_origin, quaternion, i_scale.xyz,
|
||||||
i_position);
|
i_position);
|
||||||
vec3 world_normal = rotateVector(quaternion, i_normal.xyz);
|
vec3 v_world_normal = rotateVector(quaternion, i_normal.xyz);
|
||||||
vec3 world_tangent = rotateVector(quaternion, i_tangent.xyz);
|
vec3 world_tangent = rotateVector(quaternion, i_tangent.xyz);
|
||||||
|
|
||||||
tangent = (u_view_matrix * vec4(world_tangent, 0.0)).xyz;
|
tangent = (u_view_matrix * vec4(world_tangent, 0.0)).xyz;
|
||||||
bitangent = (u_view_matrix *
|
bitangent = (u_view_matrix *
|
||||||
// bitangent sign
|
// bitangent sign
|
||||||
vec4(cross(world_normal, world_tangent) * i_tangent.w, 0.0)
|
vec4(cross(v_world_normal, world_tangent) * i_tangent.w, 0.0)
|
||||||
).xyz;
|
).xyz;
|
||||||
normal = (u_view_matrix * vec4(world_normal, 0.0)).xyz;
|
normal = (u_view_matrix * vec4(v_world_normal, 0.0)).xyz;
|
||||||
|
|
||||||
uv = vec2(i_uv.x + (i_texture_trans.x * i_normal.w),
|
uv = vec2(i_uv.x + (i_texture_trans.x * i_normal.w),
|
||||||
i_uv.y + (i_texture_trans.y * i_normal.w));
|
i_uv.y + (i_texture_trans.y * i_normal.w));
|
||||||
@ -71,4 +72,5 @@ void main()
|
|||||||
hue_change = float(i_misc_data.y) * 0.01;
|
hue_change = float(i_misc_data.y) * 0.01;
|
||||||
gl_Position = u_projection_view_matrix * v_world_position;
|
gl_Position = u_projection_view_matrix * v_world_position;
|
||||||
world_position = v_world_position;
|
world_position = v_world_position;
|
||||||
|
world_normal = v_world_normal;
|
||||||
}
|
}
|
||||||
|
63
data/shaders/sp_vertical_mapping.frag
Normal file
63
data/shaders/sp_vertical_mapping.frag
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
in vec3 bitangent;
|
||||||
|
in vec4 color;
|
||||||
|
in float hue_change;
|
||||||
|
in vec3 normal;
|
||||||
|
in vec3 world_normal;
|
||||||
|
in vec3 tangent;
|
||||||
|
in vec2 uv;
|
||||||
|
|
||||||
|
layout(location = 0) out vec4 o_diffuse_color;
|
||||||
|
layout(location = 1) out vec4 o_normal_color;
|
||||||
|
|
||||||
|
#stk_include "utils/encode_normal.frag"
|
||||||
|
#stk_include "utils/rgb_conversion.frag"
|
||||||
|
#stk_include "utils/sp_texture_sampling.frag"
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec4 col = sampleTextureLayer4(uv * 2.0);
|
||||||
|
//col = vec4(1.0, 0.0, 0.0, 1.0);
|
||||||
|
vec4 col_2 = sampleTextureLayer5(uv * 2.0);//vec4(0.0, 1.0, 0.0, 1.0);
|
||||||
|
|
||||||
|
float factor = dot(vec3(0.,1.,1.), world_normal);
|
||||||
|
factor = clamp(factor, 0.0, 1.0);
|
||||||
|
col = mix(col_2, col, factor);
|
||||||
|
|
||||||
|
if (hue_change > 0.0)
|
||||||
|
{
|
||||||
|
float mask = col.a;
|
||||||
|
vec3 old_hsv = rgbToHsv(col.rgb);
|
||||||
|
float mask_step = step(mask, 0.5);
|
||||||
|
#if !defined(Advanced_Lighting_Enabled)
|
||||||
|
// For similar color
|
||||||
|
float saturation = mask * 1.825; // 2.5 * 0.5 ^ (1. / 2.2)
|
||||||
|
#else
|
||||||
|
float saturation = mask * 2.5;
|
||||||
|
#endif
|
||||||
|
vec2 new_xy = mix(vec2(old_hsv.x, old_hsv.y), vec2(hue_change,
|
||||||
|
max(old_hsv.y, saturation)), vec2(mask_step, mask_step));
|
||||||
|
vec3 new_color = hsvToRgb(vec3(new_xy.x, new_xy.y, old_hsv.z));
|
||||||
|
col = vec4(new_color.r, new_color.g, new_color.b, 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 final_color = col.xyz * color.xyz;
|
||||||
|
|
||||||
|
#if defined(Advanced_Lighting_Enabled)
|
||||||
|
vec4 layer_2 = sampleTextureLayer2(uv);
|
||||||
|
vec4 layer_3 = sampleTextureLayer3(uv);
|
||||||
|
o_diffuse_color = vec4(final_color, layer_2.z);
|
||||||
|
|
||||||
|
vec3 tangent_space_normal = 2.0 * layer_3.xyz - 1.0;
|
||||||
|
vec3 frag_tangent = normalize(tangent);
|
||||||
|
vec3 frag_bitangent = normalize(bitangent);
|
||||||
|
vec3 frag_normal = normalize(normal);
|
||||||
|
mat3 t_b_n = mat3(frag_tangent, frag_bitangent, frag_normal);
|
||||||
|
|
||||||
|
vec3 world_normal = t_b_n * tangent_space_normal;
|
||||||
|
|
||||||
|
o_normal_color.xy = 0.5 * EncodeNormal(normalize(world_normal)) + 0.5;
|
||||||
|
o_normal_color.zw = layer_2.xy;
|
||||||
|
#else
|
||||||
|
o_diffuse_color = vec4(final_color, 1.0);
|
||||||
|
#endif
|
||||||
|
}
|
15
data/shaders/sps_11_verticalMapping.xml
Normal file
15
data/shaders/sps_11_verticalMapping.xml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<spshader>
|
||||||
|
<shader-info name="verticalMapping" fallback-shader="solid" use-tangents="Y"/>
|
||||||
|
<first-pass vertex-shader="sp_pass.vert"
|
||||||
|
fragment-shader="sp_vertical_mapping.frag"
|
||||||
|
skinned-mesh-shader="sp_skinning.vert">
|
||||||
|
</first-pass>
|
||||||
|
<shadow-pass vertex-shader="sp_shadow.vert"
|
||||||
|
fragment-shader="white.frag"
|
||||||
|
skinned-mesh-shader="sp_skinning_shadow.vert">
|
||||||
|
</shadow-pass>
|
||||||
|
<uniform-assigners>
|
||||||
|
<uniform-assigner name="layer"
|
||||||
|
function="shadowCascadeUniformAssigner"/>
|
||||||
|
</uniform-assigners>
|
||||||
|
</spshader>
|
Loading…
Reference in New Issue
Block a user