Add layer of abstraction to output pbrData
This commit is contained in:
parent
f5a0e6477e
commit
c4b42c1852
@ -1,9 +1,6 @@
|
||||
flat in float hue_change;
|
||||
|
||||
in vec4 color;
|
||||
in vec3 tangent;
|
||||
in vec3 bitangent;
|
||||
in vec3 normal;
|
||||
in vec2 uv;
|
||||
|
||||
layout(location = 0) out vec4 o_diffuse_color;
|
||||
@ -13,6 +10,7 @@ layout(location = 2) out vec2 o_gloss_map;
|
||||
#stk_include "utils/encode_normal.frag"
|
||||
#stk_include "utils/rgb_conversion.frag"
|
||||
#stk_include "utils/sp_texture_sampling.frag"
|
||||
#stk_include "utils/sp_normalMapOutput.frag"
|
||||
|
||||
void main()
|
||||
{
|
||||
@ -39,16 +37,7 @@ void main()
|
||||
|
||||
#if defined(Advanced_Lighting_Enabled)
|
||||
vec4 layer_3 = sampleTextureLayer3(uv);
|
||||
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;
|
||||
|
||||
vec4 layer_2 = sampleTextureLayer2(uv);
|
||||
o_normal_depth.xy = 0.5 * EncodeNormal(normalize(world_normal)) + 0.5;
|
||||
o_normal_depth.z = layer_2.x;
|
||||
o_gloss_map = layer_2.yz;
|
||||
outputNormalMapPbrData(layer_3.rgb, layer_2.rgb);
|
||||
#endif
|
||||
}
|
||||
|
21
data/shaders/utils/sp_normalMapOutput.frag
Normal file
21
data/shaders/utils/sp_normalMapOutput.frag
Normal file
@ -0,0 +1,21 @@
|
||||
// This function encapsulate the computation of normal maps
|
||||
in vec3 tangent;
|
||||
in vec3 bitangent;
|
||||
in vec3 normal;
|
||||
|
||||
void outputNormalMapPbrData(vec3 layer_3, vec3 layer_2)
|
||||
{
|
||||
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_depth.xy = 0.5 * EncodeNormal(normalize(world_normal)) + 0.5;
|
||||
o_normal_depth.z = layer_2.x;
|
||||
o_gloss_map = layer_2.yz;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user