Add samuncle way to sample texture slot
This commit is contained in:
parent
4ad7934a85
commit
711fb8211a
@ -1,19 +1,3 @@
|
|||||||
#ifdef Use_Bindless_Texture
|
|
||||||
flat in sampler2D tex_layer_0;
|
|
||||||
flat in sampler2D tex_layer_2;
|
|
||||||
#else
|
|
||||||
// spm layer 1 texture
|
|
||||||
uniform sampler2D tex_layer_0;
|
|
||||||
// gloss map
|
|
||||||
uniform sampler2D tex_layer_2;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef Use_Array_Texture
|
|
||||||
uniform sampler2DArray tex_array;
|
|
||||||
flat in float array_0;
|
|
||||||
flat in float array_2;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
flat in float hue_change;
|
flat in float hue_change;
|
||||||
|
|
||||||
in vec3 normal;
|
in vec3 normal;
|
||||||
@ -25,15 +9,11 @@ layout(location = 2) out vec2 o_gloss_map;
|
|||||||
|
|
||||||
#stk_include "utils/encode_normal.frag"
|
#stk_include "utils/encode_normal.frag"
|
||||||
#stk_include "utils/rgb_conversion.frag"
|
#stk_include "utils/rgb_conversion.frag"
|
||||||
|
#stk_include "utils/sp_texture_sampling.frag"
|
||||||
|
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
#ifdef Use_Array_Texture
|
vec4 col = sampleTextureSlot0(uv);
|
||||||
vec4 col = texture(tex_array, vec3(uv, array_0));
|
|
||||||
#else
|
|
||||||
vec4 col = texture(tex_layer_0, uv);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (col.a < 0.5)
|
if (col.a < 0.5)
|
||||||
{
|
{
|
||||||
discard;
|
discard;
|
||||||
@ -57,16 +37,8 @@ void main(void)
|
|||||||
#endif
|
#endif
|
||||||
o_diffuse_color = vec4(final_color, 1.0);
|
o_diffuse_color = vec4(final_color, 1.0);
|
||||||
|
|
||||||
#if defined(Advanced_Lighting_Enabled)
|
vec4 layer_2 = sampleTextureSlot2(uv);
|
||||||
#ifdef Use_Array_Texture
|
|
||||||
vec4 layer_2 = texture(tex_array, vec3(uv, array_2));
|
|
||||||
#else
|
|
||||||
vec4 layer_2 = texture(tex_layer_2, uv);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
o_normal_depth.xy = 0.5 * EncodeNormal(normalize(normal)) + 0.5;
|
o_normal_depth.xy = 0.5 * EncodeNormal(normalize(normal)) + 0.5;
|
||||||
o_normal_depth.z = layer_2.x;
|
o_normal_depth.z = layer_2.x;
|
||||||
o_gloss_map = 0.1 * layer_2.yz;
|
o_gloss_map = 0.1 * layer_2.yz;
|
||||||
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,3 @@
|
|||||||
#ifdef Use_Bindless_Texture
|
|
||||||
flat in sampler2D tex_layer_0;
|
|
||||||
flat in sampler2D tex_layer_2;
|
|
||||||
flat in sampler2D tex_layer_3;
|
|
||||||
#else
|
|
||||||
// spm layer 1 texture
|
|
||||||
uniform sampler2D tex_layer_0;
|
|
||||||
// gloss map
|
|
||||||
uniform sampler2D tex_layer_2;
|
|
||||||
// normal map
|
|
||||||
uniform sampler2D tex_layer_3;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef Use_Array_Texture
|
|
||||||
uniform sampler2DArray tex_array;
|
|
||||||
flat in float array_0;
|
|
||||||
flat in float array_2;
|
|
||||||
flat in float array_3;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
flat in float hue_change;
|
flat in float hue_change;
|
||||||
|
|
||||||
in vec4 color;
|
in vec4 color;
|
||||||
@ -33,15 +12,11 @@ layout(location = 2) out vec2 o_gloss_map;
|
|||||||
|
|
||||||
#stk_include "utils/encode_normal.frag"
|
#stk_include "utils/encode_normal.frag"
|
||||||
#stk_include "utils/rgb_conversion.frag"
|
#stk_include "utils/rgb_conversion.frag"
|
||||||
|
#stk_include "utils/sp_texture_sampling.frag"
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
#ifdef Use_Array_Texture
|
vec4 col = sampleTextureSlot0(uv);
|
||||||
vec4 col = texture(tex_array, vec3(uv, array_0));
|
|
||||||
#else
|
|
||||||
vec4 col = texture(tex_layer_0, uv);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (hue_change > 0.0)
|
if (hue_change > 0.0)
|
||||||
{
|
{
|
||||||
float mask = col.a;
|
float mask = col.a;
|
||||||
@ -68,13 +43,7 @@ void main()
|
|||||||
#endif
|
#endif
|
||||||
o_diffuse_color = vec4(final_color, 1.0);
|
o_diffuse_color = vec4(final_color, 1.0);
|
||||||
|
|
||||||
#if defined(Advanced_Lighting_Enabled)
|
vec4 layer_3 = sampleTextureSlot3(uv);
|
||||||
#ifdef Use_Array_Texture
|
|
||||||
vec4 layer_3 = texture(tex_array, vec3(uv, array_3));
|
|
||||||
#else
|
|
||||||
vec4 layer_3 = texture(tex_layer_3, uv);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
vec3 tangent_space_normal = 2.0 * layer_3.xyz - 1.0;
|
vec3 tangent_space_normal = 2.0 * layer_3.xyz - 1.0;
|
||||||
vec3 frag_tangent = normalize(tangent);
|
vec3 frag_tangent = normalize(tangent);
|
||||||
vec3 frag_bitangent = normalize(bitangent);
|
vec3 frag_bitangent = normalize(bitangent);
|
||||||
@ -82,15 +51,8 @@ void main()
|
|||||||
mat3 t_b_n = mat3(frag_tangent, frag_bitangent, frag_normal);
|
mat3 t_b_n = mat3(frag_tangent, frag_bitangent, frag_normal);
|
||||||
vec3 world_normal = t_b_n * tangent_space_normal;
|
vec3 world_normal = t_b_n * tangent_space_normal;
|
||||||
|
|
||||||
#ifdef Use_Array_Texture
|
vec4 layer_2 = sampleTextureSlot2(uv);
|
||||||
vec4 layer_2 = texture(tex_array, vec3(uv, array_2));
|
|
||||||
#else
|
|
||||||
vec4 layer_2 = texture(tex_layer_2, uv);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
o_normal_depth.xy = 0.5 * EncodeNormal(normalize(world_normal)) + 0.5;
|
o_normal_depth.xy = 0.5 * EncodeNormal(normalize(world_normal)) + 0.5;
|
||||||
o_normal_depth.z = layer_2.x;
|
o_normal_depth.z = layer_2.x;
|
||||||
o_gloss_map = layer_2.yz;
|
o_gloss_map = layer_2.yz;
|
||||||
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,3 @@
|
|||||||
#ifdef Use_Bindless_Texture
|
|
||||||
flat in sampler2D tex_layer_0;
|
|
||||||
flat in sampler2D tex_layer_2;
|
|
||||||
#else
|
|
||||||
// spm layer 1 texture
|
|
||||||
uniform sampler2D tex_layer_0;
|
|
||||||
// gloss map
|
|
||||||
uniform sampler2D tex_layer_2;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef Use_Array_Texture
|
|
||||||
uniform sampler2DArray tex_array;
|
|
||||||
flat in float array_0;
|
|
||||||
flat in float array_2;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
flat in float hue_change;
|
flat in float hue_change;
|
||||||
|
|
||||||
in vec4 color;
|
in vec4 color;
|
||||||
@ -26,15 +10,11 @@ layout(location = 2) out vec2 o_gloss_map;
|
|||||||
|
|
||||||
#stk_include "utils/encode_normal.frag"
|
#stk_include "utils/encode_normal.frag"
|
||||||
#stk_include "utils/rgb_conversion.frag"
|
#stk_include "utils/rgb_conversion.frag"
|
||||||
|
#stk_include "utils/sp_texture_sampling.frag"
|
||||||
|
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
#ifdef Use_Array_Texture
|
vec4 col = sampleTextureSlot0(uv);
|
||||||
vec4 col = texture(tex_array, vec3(uv, array_0));
|
|
||||||
#else
|
|
||||||
vec4 col = texture(tex_layer_0, uv);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (hue_change > 0.0)
|
if (hue_change > 0.0)
|
||||||
{
|
{
|
||||||
float mask = col.a;
|
float mask = col.a;
|
||||||
@ -61,16 +41,8 @@ void main(void)
|
|||||||
#endif
|
#endif
|
||||||
o_diffuse_color = vec4(final_color, 1.0);
|
o_diffuse_color = vec4(final_color, 1.0);
|
||||||
|
|
||||||
#if defined(Advanced_Lighting_Enabled)
|
vec4 layer_2 = sampleTextureSlot2(uv);
|
||||||
#ifdef Use_Array_Texture
|
|
||||||
vec4 layer_2 = texture(tex_array, vec3(uv, array_2));
|
|
||||||
#else
|
|
||||||
vec4 layer_2 = texture(tex_layer_2, uv);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
o_normal_depth.xy = 0.5 * EncodeNormal(normalize(normal)) + 0.5;
|
o_normal_depth.xy = 0.5 * EncodeNormal(normalize(normal)) + 0.5;
|
||||||
o_normal_depth.z = layer_2.x;
|
o_normal_depth.z = layer_2.x;
|
||||||
o_gloss_map = layer_2.yz;
|
o_gloss_map = layer_2.yz;
|
||||||
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
78
data/shaders/utils/sp_texture_sampling.frag
Normal file
78
data/shaders/utils/sp_texture_sampling.frag
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
// Wrapper to allow easy sampling for material texture slots
|
||||||
|
#if defined(Use_Array_Texture)
|
||||||
|
flat in float array_0;
|
||||||
|
flat in float array_1;
|
||||||
|
flat in float array_2;
|
||||||
|
flat in float array_3;
|
||||||
|
flat in float array_4;
|
||||||
|
flat in float array_5;
|
||||||
|
uniform sampler2DArray tex_array;
|
||||||
|
#elif defined(Use_Bindless_Texture)
|
||||||
|
flat in sampler2D tex_layer_0;
|
||||||
|
flat in sampler2D tex_layer_1;
|
||||||
|
flat in sampler2D tex_layer_2;
|
||||||
|
flat in sampler2D tex_layer_3;
|
||||||
|
flat in sampler2D tex_layer_4;
|
||||||
|
flat in sampler2D tex_layer_5;
|
||||||
|
#else
|
||||||
|
uniform sampler2D tex_layer_0;
|
||||||
|
uniform sampler2D tex_layer_1;
|
||||||
|
uniform sampler2D tex_layer_2;
|
||||||
|
uniform sampler2D tex_layer_3;
|
||||||
|
uniform sampler2D tex_layer_4;
|
||||||
|
uniform sampler2D tex_layer_5;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
vec4 sampleTextureSlot0(vec2 uv)
|
||||||
|
{
|
||||||
|
#ifdef Use_Array_Texture
|
||||||
|
return texture(tex_array, vec3(uv, array_0));
|
||||||
|
#else
|
||||||
|
return texture(tex_layer_0, uv);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
vec4 sampleTextureSlot1(vec2 uv)
|
||||||
|
{
|
||||||
|
#ifdef Use_Array_Texture
|
||||||
|
return texture(tex_array, vec3(uv, array_1));
|
||||||
|
#else
|
||||||
|
return texture(tex_layer_1, uv);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
vec4 sampleTextureSlot2(vec2 uv)
|
||||||
|
{
|
||||||
|
#ifdef Use_Array_Texture
|
||||||
|
return texture(tex_array, vec3(uv, array_2));
|
||||||
|
#else
|
||||||
|
return texture(tex_layer_2, uv);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
vec4 sampleTextureSlot3(vec2 uv)
|
||||||
|
{
|
||||||
|
#ifdef Use_Array_Texture
|
||||||
|
return texture(tex_array, vec3(uv, array_3));
|
||||||
|
#else
|
||||||
|
return texture(tex_layer_3, uv);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
vec4 sampleTextureSlot4(vec2 uv)
|
||||||
|
{
|
||||||
|
#ifdef Use_Array_Texture
|
||||||
|
return texture(tex_array, vec3(uv, array_4));
|
||||||
|
#else
|
||||||
|
return texture(tex_layer_4, uv);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
vec4 sampleTextureSlot5(vec2 uv)
|
||||||
|
{
|
||||||
|
#ifdef Use_Array_Texture
|
||||||
|
return texture(tex_array, vec3(uv, array_5));
|
||||||
|
#else
|
||||||
|
return texture(tex_layer_5, uv);
|
||||||
|
#endif
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user