Add more utilities to default shader function + make the road shader more optimized

This commit is contained in:
samuncle 2018-08-13 18:44:15 +02:00
parent 2efe3afa9f
commit b8ce2da3f3
5 changed files with 45 additions and 13 deletions

View File

@ -4,6 +4,7 @@ in float hue_change;
in vec3 normal; in vec3 normal;
in vec3 tangent; in vec3 tangent;
in vec2 uv; in vec2 uv;
in vec4 world_position;
layout(location = 0) out vec4 o_diffuse_color; layout(location = 0) out vec4 o_diffuse_color;
layout(location = 1) out vec4 o_normal_color; layout(location = 1) out vec4 o_normal_color;
@ -12,9 +13,17 @@ layout(location = 1) out vec4 o_normal_color;
#stk_include "utils/rgb_conversion.frag" #stk_include "utils/rgb_conversion.frag"
#stk_include "utils/sp_texture_sampling.frag" #stk_include "utils/sp_texture_sampling.frag"
uniform sampler2D g_detail_map;
void main() void main()
{ {
// Triplanar detail map
vec2 xyuv = vec2(world_position.x, world_position.y);
float detail = texture(g_detail_map, uv * 32).r;
detail *= 2.5;
vec4 col = sampleTextureLayer0(uv); vec4 col = sampleTextureLayer0(uv);
col = (col - detail) + 0.5;
if (hue_change > 0.0) if (hue_change > 0.0)
{ {
float mask = col.a; float mask = col.a;

View File

@ -1,3 +1,5 @@
uniform sampler2D road_masking;
in vec3 bitangent; in vec3 bitangent;
in vec4 color; in vec4 color;
in float hue_change; in float hue_change;
@ -21,6 +23,7 @@ void main()
vec4 col = multi_sampleTextureLayer0(uv, camdist); vec4 col = multi_sampleTextureLayer0(uv, camdist);
float mask = sampleTextureLayer4(uuv * 2.0).r; float mask = sampleTextureLayer4(uuv * 2.0).r;
mask += sampleTextureLayer4(uuv * 0.5).r;
//* (1.0 - color.g) //* (1.0 - color.g)
mask = mix(1.0, mask, color.r); mask = mix(1.0, mask, color.r);
@ -36,16 +39,16 @@ void main()
mask_2 = pow(mask_2, 1.5); mask_2 = pow(mask_2, 1.5);
mask_2 *= pow(mask_3, 0.5); mask_2 *= pow(mask_3, 0.5);
float skidding_marks = sampleTextureLayer5(uv * 10.0).g; float skidding_marks = texture(road_masking, uv * 10.0).g;
skidding_marks *= mask_2; skidding_marks *= mask_2;
col = mix(col, vec4(0.0, 0.0, 0.0, 1.0), skidding_marks); col = mix(col, vec4(0.0, 0.0, 0.0, 1.0), skidding_marks);
float skidding_marks_2 = sampleTextureLayer5(uv * 15.0).g; float skidding_marks_2 = texture(road_masking, uv * 15.0).g;
skidding_marks_2 *= mask_2; skidding_marks_2 *= mask_2;
col = mix(col, vec4(0.0, 0.0, 0.0, 1.0), skidding_marks_2); col = mix(col, vec4(0.0, 0.0, 0.0, 1.0), skidding_marks_2);
// Add some cracks // Add some cracks
float cracks_marks = sampleTextureLayer5(uv * 11.0).b; float cracks_marks = texture(road_masking, uv * 11.0).b;
float crack_mask = sampleTextureLayer4(uuv * 0.5).r; float crack_mask = sampleTextureLayer4(uuv * 0.5).r;
cracks_marks *= crack_mask; cracks_marks *= crack_mask;
col = mix(col, vec4(0.0, 0.0, 0.0, 1.0), cracks_marks); col = mix(col, vec4(0.0, 0.0, 0.0, 1.0), cracks_marks);

View File

@ -3,6 +3,10 @@
<first-pass vertex-shader="sp_pass.vert" <first-pass vertex-shader="sp_pass.vert"
fragment-shader="sp_normal_map.frag" fragment-shader="sp_normal_map.frag"
skinned-mesh-shader="sp_skinning.vert"> skinned-mesh-shader="sp_skinning.vert">
<prefilled-textures>
<prefilled-texture name="g_detail_map" file="gfx_detailmap_a.png"
srgb="Y" sampler="trilinear"/>
</prefilled-textures>
</first-pass> </first-pass>
<shadow-pass vertex-shader="sp_shadow.vert" <shadow-pass vertex-shader="sp_shadow.vert"
fragment-shader="white.frag" fragment-shader="white.frag"

View File

@ -2,15 +2,8 @@
<shader-info name="roadBlending" fallback-shader="solid" use-tangents="Y"/> <shader-info name="roadBlending" fallback-shader="solid" use-tangents="Y"/>
<first-pass vertex-shader="sp_pass.vert" <first-pass vertex-shader="sp_pass.vert"
fragment-shader="sp_road_blending.frag"> fragment-shader="sp_road_blending.frag">
<prefilled-textures>
<prefilled-texture name="road_masking" file="hd_roadMarking_a_mask.png" srgb="Y" sampler="trilinear"/>
</prefilled-textures>
</first-pass> </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> </spshader>

View File

@ -109,6 +109,29 @@ vec4 sampleTextureLayer4(vec2 uv)
return texture(tex_layer_4, uv); return texture(tex_layer_4, uv);
} }
vec4 multi_sampleTextureLayer4(vec2 uv, float distance)
{
vec4 l_col = sampleTextureLayer4(uv * LOW_SAMPLING);
vec4 m_col = sampleTextureLayer4(uv * MEDIUM_SAMPLING);
vec4 h_col = sampleTextureLayer4(uv * HIGH_SAMPLING);
// From Low to medium
float factor = distance * 0.02;
factor = pow(factor, 2.5);
factor = clamp(factor, 0.0, 1.0);
vec4 f_col = mix(m_col, l_col, factor);
// From medium to high
factor = distance * 0.1;
factor = pow(factor, 2.5);
factor = clamp(factor, 0.0, 1.0);
f_col = mix(h_col, f_col, factor);
return f_col;
}
vec4 sampleTextureLayer5(vec2 uv) vec4 sampleTextureLayer5(vec2 uv)
{ {
return texture(tex_layer_5, uv); return texture(tex_layer_5, uv);