Use sampleTextureLayer in shader files

This commit is contained in:
Benau 2018-01-22 10:43:22 +08:00
parent 39f4f8e966
commit 4025883243
16 changed files with 89 additions and 89 deletions

View File

@ -1,8 +1,8 @@
uniform ivec4 color; uniform ivec4 color;
out vec4 FragColor; out vec4 FragColor;
void main() void main()
{ {
FragColor = vec4(color) / 255.; FragColor = vec4(color) / 255.;
} }

View File

@ -1,14 +1,14 @@
uniform vec2 center; uniform vec2 center;
uniform vec2 size; uniform vec2 size;
#ifdef Explicit_Attrib_Location_Usable #ifdef Explicit_Attrib_Location_Usable
layout(location = 0) in vec2 Position; layout(location = 0) in vec2 Position;
#else #else
in vec2 Position; in vec2 Position;
#endif #endif
void main() void main()
{ {
gl_Position = vec4(Position * size + center, 0., 1.); gl_Position = vec4(Position * size + center, 0., 1.);
} }

View File

@ -1,11 +1,11 @@
uniform sampler2D tex; uniform sampler2D tex;
in vec2 uv; in vec2 uv;
in vec4 col; in vec4 col;
out vec4 FragColor; out vec4 FragColor;
void main() void main()
{ {
vec4 res = texture(tex, uv); vec4 res = texture(tex, uv);
FragColor = res * col; FragColor = res * col;
} }

View File

@ -1,24 +1,24 @@
uniform vec2 center; uniform vec2 center;
uniform vec2 size; uniform vec2 size;
uniform vec2 texcenter; uniform vec2 texcenter;
uniform vec2 texsize; uniform vec2 texsize;
#ifdef Explicit_Attrib_Location_Usable #ifdef Explicit_Attrib_Location_Usable
layout(location=0) in vec2 Position; layout(location=0) in vec2 Position;
layout(location=3) in vec2 Texcoord; layout(location=3) in vec2 Texcoord;
layout(location=2) in vec4 Color; layout(location=2) in vec4 Color;
#else #else
in vec2 Position; in vec2 Position;
in vec2 Texcoord; in vec2 Texcoord;
in vec4 Color; in vec4 Color;
#endif #endif
out vec2 uv; out vec2 uv;
out vec4 col; out vec4 col;
void main() void main()
{ {
col = Color.zyxw; col = Color.zyxw;
uv = Texcoord * texsize + texcenter; uv = Texcoord * texsize + texcenter;
gl_Position = vec4(Position * size + center, 0., 1.); gl_Position = vec4(Position * size + center, 0., 1.);
} }

View File

@ -14,7 +14,7 @@ layout(location = 2) out vec2 o_gloss_map;
void main(void) void main(void)
{ {
vec4 col = sampleTextureSlot0(uv); vec4 col = sampleTextureLayer0(uv);
if (col.a * color.a < 0.5) if (col.a * color.a < 0.5)
{ {
discard; discard;
@ -40,7 +40,7 @@ void main(void)
o_diffuse_color = vec4(final_color, 1.0); o_diffuse_color = vec4(final_color, 1.0);
#if defined(Advanced_Lighting_Enabled) #if defined(Advanced_Lighting_Enabled)
vec4 layer_2 = sampleTextureSlot2(uv); vec4 layer_2 = sampleTextureLayer2(uv);
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;

View File

@ -11,8 +11,8 @@ layout(location = 2) out vec2 o_gloss_map;
void main(void) void main(void)
{ {
vec4 color = sampleTextureSlot0(uv); vec4 color = sampleTextureLayer0(uv);
vec4 layer_two_tex = sampleTextureSlot1(uv_two); vec4 layer_two_tex = sampleTextureLayer1(uv_two);
layer_two_tex.rgb = layer_two_tex.a * layer_two_tex.rgb; layer_two_tex.rgb = layer_two_tex.a * layer_two_tex.rgb;
vec3 final_color = layer_two_tex.rgb + color.rgb * (1.0 - layer_two_tex.a); vec3 final_color = layer_two_tex.rgb + color.rgb * (1.0 - layer_two_tex.a);
@ -26,7 +26,7 @@ void main(void)
o_diffuse_color = vec4(final_color, 1.0); o_diffuse_color = vec4(final_color, 1.0);
#if defined(Advanced_Lighting_Enabled) #if defined(Advanced_Lighting_Enabled)
vec4 layer_2 = sampleTextureSlot2(uv); vec4 layer_2 = sampleTextureLayer2(uv);
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;

View File

@ -41,7 +41,7 @@ void main()
tc += (mask < 1.) ? vec2(0.) : shift; tc += (mask < 1.) ? vec2(0.) : shift;
vec4 col = texture(color_tex, tc); vec4 col = texture(color_tex, tc);
vec4 blend_tex = sampleTextureSlot0(uv); vec4 blend_tex = sampleTextureLayer0(uv);
col.rgb = blend_tex.rgb * blend_tex.a + (1. - blend_tex.a) * col.rgb; col.rgb = blend_tex.rgb * blend_tex.a + (1. - blend_tex.a) * col.rgb;
o_diffuse_color = vec4(col.rgb, 1.); o_diffuse_color = vec4(col.rgb, 1.);
} }

View File

@ -11,7 +11,7 @@ out vec4 o_diffuse_color;
void main() void main()
{ {
vec4 col = sampleTextureSlot0(uv); vec4 col = sampleTextureLayer0(uv);
if (hue_change > 0.0) if (hue_change > 0.0)
{ {
float mask = col.a; float mask = col.a;

View File

@ -13,7 +13,7 @@ layout(location = 2) out vec2 o_gloss_map;
void main(void) void main(void)
{ {
vec4 col = sampleTextureSlot0(uv); vec4 col = sampleTextureLayer0(uv);
if (col.a < 0.5) if (col.a < 0.5)
{ {
discard; discard;
@ -38,7 +38,7 @@ void main(void)
o_diffuse_color = vec4(final_color, 1.0); o_diffuse_color = vec4(final_color, 1.0);
#if defined(Advanced_Lighting_Enabled) #if defined(Advanced_Lighting_Enabled)
vec4 layer_2 = sampleTextureSlot2(uv); vec4 layer_2 = sampleTextureLayer2(uv);
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;

View File

@ -16,7 +16,7 @@ layout(location = 2) out vec2 o_gloss_map;
void main() void main()
{ {
vec4 col = sampleTextureSlot0(uv); vec4 col = sampleTextureLayer0(uv);
if (hue_change > 0.0) if (hue_change > 0.0)
{ {
float mask = col.a; float mask = col.a;
@ -44,7 +44,7 @@ void main()
o_diffuse_color = vec4(final_color, 1.0); o_diffuse_color = vec4(final_color, 1.0);
#if defined(Advanced_Lighting_Enabled) #if defined(Advanced_Lighting_Enabled)
vec4 layer_3 = sampleTextureSlot3(uv); vec4 layer_3 = sampleTextureLayer3(uv);
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);
@ -52,7 +52,7 @@ 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;
vec4 layer_2 = sampleTextureSlot2(uv); vec4 layer_2 = sampleTextureLayer2(uv);
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;

View File

@ -5,7 +5,7 @@ out vec4 o_frag_color;
void main(void) void main(void)
{ {
vec4 col = sampleTextureSlot0(uv); vec4 col = sampleTextureLayer0(uv);
if (col.a < 0.5) if (col.a < 0.5)
{ {
discard; discard;

View File

@ -14,7 +14,7 @@ layout(location = 2) out vec2 o_gloss_map;
void main(void) void main(void)
{ {
vec4 col = sampleTextureSlot0(uv); vec4 col = sampleTextureLayer0(uv);
if (hue_change > 0.0) if (hue_change > 0.0)
{ {
float mask = col.a; float mask = col.a;
@ -42,7 +42,7 @@ void main(void)
o_diffuse_color = vec4(final_color, 1.0); o_diffuse_color = vec4(final_color, 1.0);
#if defined(Advanced_Lighting_Enabled) #if defined(Advanced_Lighting_Enabled)
vec4 layer_2 = sampleTextureSlot2(uv); vec4 layer_2 = sampleTextureLayer2(uv);
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;

View File

@ -9,7 +9,7 @@ out vec4 o_diffuse_color;
void main() void main()
{ {
vec4 diffusecolor = sampleTextureSlot0(uv); vec4 diffusecolor = sampleTextureLayer0(uv);
vec4 finalcolor = vec4(0.); vec4 finalcolor = vec4(0.);
if (fog_enabled == 0) if (fog_enabled == 0)
{ {

View File

@ -11,7 +11,7 @@ layout(location = 2) out vec2 o_gloss_map;
void main(void) void main(void)
{ {
vec4 col = sampleTextureSlot0(uv); vec4 col = sampleTextureLayer0(uv);
if (col.a < 0.5) if (col.a < 0.5)
{ {
discard; discard;

View File

@ -1,9 +1,9 @@
uniform sampler2D tex; uniform sampler2D tex;
in vec2 uv; in vec2 uv;
out vec4 FragColor; out vec4 FragColor;
void main() void main()
{ {
FragColor = texture(tex, uv); FragColor = texture(tex, uv);
} }

View File

@ -1,4 +1,4 @@
// Wrapper to allow easy sampling for material texture slots // Wrapper to allow easy sampling for material texture layers
uniform sampler2D tex_layer_0; uniform sampler2D tex_layer_0;
uniform sampler2D tex_layer_1; uniform sampler2D tex_layer_1;
uniform sampler2D tex_layer_2; uniform sampler2D tex_layer_2;
@ -6,32 +6,32 @@ uniform sampler2D tex_layer_3;
uniform sampler2D tex_layer_4; uniform sampler2D tex_layer_4;
uniform sampler2D tex_layer_5; uniform sampler2D tex_layer_5;
vec4 sampleTextureSlot0(vec2 uv) vec4 sampleTextureLayer0(vec2 uv)
{ {
return texture(tex_layer_0, uv); return texture(tex_layer_0, uv);
} }
vec4 sampleTextureSlot1(vec2 uv) vec4 sampleTextureLayer1(vec2 uv)
{ {
return texture(tex_layer_1, uv); return texture(tex_layer_1, uv);
} }
vec4 sampleTextureSlot2(vec2 uv) vec4 sampleTextureLayer2(vec2 uv)
{ {
return texture(tex_layer_2, uv); return texture(tex_layer_2, uv);
} }
vec4 sampleTextureSlot3(vec2 uv) vec4 sampleTextureLayer3(vec2 uv)
{ {
return texture(tex_layer_3, uv); return texture(tex_layer_3, uv);
} }
vec4 sampleTextureSlot4(vec2 uv) vec4 sampleTextureLayer4(vec2 uv)
{ {
return texture(tex_layer_4, uv); return texture(tex_layer_4, uv);
} }
vec4 sampleTextureSlot5(vec2 uv) vec4 sampleTextureLayer5(vec2 uv)
{ {
return texture(tex_layer_5, uv); return texture(tex_layer_5, uv);
} }