HDR: Normal mapping without precomputed tangents
Also tidy up model and terrain shaders. Inputs and outputs to vertex and fragment shaders are now interface blocks.
This commit is contained in:
parent
82d415cbd4
commit
10cd3fb8c4
23 changed files with 209 additions and 165 deletions
|
@ -1306,7 +1306,7 @@ please see Docs/README.model-combined.eff for documentation
|
|||
</pass>
|
||||
</technique>
|
||||
|
||||
<technique n="7">
|
||||
<technique n="108">
|
||||
<scheme>hdr-geometry</scheme>
|
||||
<pass>
|
||||
<!-- Reverse floating point depth buffer -->
|
||||
|
@ -1342,6 +1342,7 @@ please see Docs/README.model-combined.eff for documentation
|
|||
<fragment-shader>Shaders/HDR/model_combined.frag</fragment-shader>
|
||||
<fragment-shader>Shaders/HDR/gbuffer_pack.glsl</fragment-shader>
|
||||
<fragment-shader>Shaders/HDR/normal_encoding.glsl</fragment-shader>
|
||||
<fragment-shader>Shaders/HDR/normalmap.glsl</fragment-shader>
|
||||
<fragment-shader>Shaders/HDR/color.glsl</fragment-shader>
|
||||
</program>
|
||||
<uniform>
|
||||
|
@ -1372,6 +1373,9 @@ please see Docs/README.model-combined.eff for documentation
|
|||
</pass>
|
||||
</technique>
|
||||
|
||||
<technique n="7">
|
||||
<predicate><value type="bool">false</value></predicate>
|
||||
</technique>
|
||||
<technique n="9">
|
||||
<predicate><value type="bool">false</value></predicate>
|
||||
</technique>
|
||||
|
|
|
@ -95,6 +95,7 @@
|
|||
<vertex-shader>Shaders/HDR/model_pbr_transparent.vert</vertex-shader>
|
||||
<vertex-shader>Shaders/HDR/aerial_perspective.glsl</vertex-shader>
|
||||
<fragment-shader>Shaders/HDR/model_pbr_transparent.frag</fragment-shader>
|
||||
<fragment-shader>Shaders/HDR/normalmap.glsl</fragment-shader>
|
||||
<fragment-shader>Shaders/HDR/color.glsl</fragment-shader>
|
||||
<fragment-shader>Shaders/HDR/math.glsl</fragment-shader>
|
||||
<fragment-shader>Shaders/HDR/shading_transparent.glsl</fragment-shader>
|
||||
|
@ -105,14 +106,6 @@
|
|||
<fragment-shader>Shaders/HDR/atmos_spectral.glsl</fragment-shader>
|
||||
<fragment-shader>Shaders/HDR/clustered.glsl</fragment-shader>
|
||||
<fragment-shader>Shaders/HDR/exposure.glsl</fragment-shader>
|
||||
<attribute>
|
||||
<name>tangent</name>
|
||||
<index>6</index>
|
||||
</attribute>
|
||||
<attribute>
|
||||
<name>binormal</name>
|
||||
<index>7</index>
|
||||
</attribute>
|
||||
</program>
|
||||
<uniform>
|
||||
<name>base_color_tex</name>
|
||||
|
|
|
@ -30,11 +30,6 @@
|
|||
<flip-vertically>false</flip-vertically>
|
||||
</parameters>
|
||||
|
||||
<generate>
|
||||
<tangent type="int">6</tangent>
|
||||
<binormal type="int">7</binormal>
|
||||
</generate>
|
||||
|
||||
<technique n="109">
|
||||
<scheme>hdr-geometry</scheme>
|
||||
<pass>
|
||||
|
@ -93,15 +88,8 @@
|
|||
<fragment-shader>Shaders/HDR/model_pbr.frag</fragment-shader>
|
||||
<fragment-shader>Shaders/HDR/gbuffer_pack.glsl</fragment-shader>
|
||||
<fragment-shader>Shaders/HDR/normal_encoding.glsl</fragment-shader>
|
||||
<fragment-shader>Shaders/HDR/normalmap.glsl</fragment-shader>
|
||||
<fragment-shader>Shaders/HDR/color.glsl</fragment-shader>
|
||||
<attribute>
|
||||
<name>tangent</name>
|
||||
<index>6</index>
|
||||
</attribute>
|
||||
<attribute>
|
||||
<name>binormal</name>
|
||||
<index>7</index>
|
||||
</attribute>
|
||||
</program>
|
||||
<uniform>
|
||||
<name>base_color_tex</name>
|
||||
|
|
|
@ -929,6 +929,7 @@
|
|||
<fragment-shader>Shaders/HDR/terrain_runway.frag</fragment-shader>
|
||||
<fragment-shader>Shaders/HDR/gbuffer_pack.glsl</fragment-shader>
|
||||
<fragment-shader>Shaders/HDR/normal_encoding.glsl</fragment-shader>
|
||||
<fragment-shader>Shaders/HDR/normalmap.glsl</fragment-shader>
|
||||
<fragment-shader>Shaders/HDR/color.glsl</fragment-shader>
|
||||
</program>
|
||||
<uniform>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#version 330 core
|
||||
|
||||
in vec3 vN;
|
||||
in vec3 vertex_normal;
|
||||
|
||||
const float CHROME_METALLIC = 1.0;
|
||||
const float CHROME_ROUGHNESS = 0.1;
|
||||
|
@ -11,5 +11,6 @@ void gbuffer_pack(vec3 normal, vec3 base_color, float metallic, float roughness,
|
|||
|
||||
void main()
|
||||
{
|
||||
gbuffer_pack(vN, vec3(1.0), CHROME_METALLIC, CHROME_ROUGHNESS, 1.0, vec3(0.0), 3u);
|
||||
vec3 N = normalize(vertex_normal);
|
||||
gbuffer_pack(N, vec3(1.0), CHROME_METALLIC, CHROME_ROUGHNESS, 1.0, vec3(0.0), 3u);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
layout(location = 0) in vec4 pos;
|
||||
layout(location = 1) in vec3 normal;
|
||||
|
||||
out vec3 vN;
|
||||
out vec3 vertex_normal;
|
||||
|
||||
uniform mat4 osg_ModelViewProjectionMatrix;
|
||||
uniform mat3 osg_NormalMatrix;
|
||||
|
@ -11,5 +11,5 @@ uniform mat3 osg_NormalMatrix;
|
|||
void main()
|
||||
{
|
||||
gl_Position = osg_ModelViewProjectionMatrix * pos;
|
||||
vN = normalize(osg_NormalMatrix * normal);
|
||||
vertex_normal = osg_NormalMatrix * normal;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
#version 330 core
|
||||
|
||||
in vec2 texcoord;
|
||||
in mat3 TBN;
|
||||
in VS_OUT {
|
||||
vec2 texcoord;
|
||||
vec3 vertex_normal;
|
||||
vec3 view_vector;
|
||||
} fs_in;
|
||||
|
||||
uniform sampler2D color_tex;
|
||||
uniform sampler2D normal_tex;
|
||||
|
||||
uniform int normalmap_enabled;
|
||||
uniform int normalmap_dds;
|
||||
uniform float normalmap_tiling;
|
||||
|
||||
const float COMBINED_METALLIC = 0.0;
|
||||
|
@ -17,20 +19,18 @@ void gbuffer_pack(vec3 normal, vec3 base_color, float metallic, float roughness,
|
|||
float occlusion, vec3 emissive, uint mat_id);
|
||||
// color.glsl
|
||||
vec3 eotf_inverse_sRGB(vec3 srgb);
|
||||
// normalmap.glsl
|
||||
vec3 perturb_normal(vec3 N, vec3 V, vec2 texcoord);
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 texel = texture(color_tex, texcoord).rgb;
|
||||
vec3 texel = texture(color_tex, fs_in.texcoord).rgb;
|
||||
vec3 color = eotf_inverse_sRGB(texel);
|
||||
|
||||
vec3 normal = vec3(0.0, 0.0, 1.0);
|
||||
vec3 N = normalize(fs_in.vertex_normal);
|
||||
if (normalmap_enabled > 0) {
|
||||
normal = texture(normal_tex, texcoord * normalmap_tiling).rgb * 2.0 - 1.0;
|
||||
// DDS has flipped normals
|
||||
if (normalmap_dds > 0)
|
||||
normal = -normal;
|
||||
N = perturb_normal(N, fs_in.view_vector, fs_in.texcoord * normalmap_tiling);
|
||||
}
|
||||
vec3 N = normalize(TBN * normal);
|
||||
|
||||
gbuffer_pack(N, color, COMBINED_METALLIC, COMBINED_ROUGHNESS, 1.0, vec3(0.0), 3u);
|
||||
}
|
||||
|
|
|
@ -3,32 +3,23 @@
|
|||
layout(location = 0) in vec4 pos;
|
||||
layout(location = 1) in vec3 normal;
|
||||
layout(location = 3) in vec4 multitexcoord0;
|
||||
layout(location = 6) in vec3 tangent;
|
||||
layout(location = 7) in vec3 binormal;
|
||||
|
||||
out vec2 texcoord;
|
||||
out mat3 TBN;
|
||||
out VS_OUT {
|
||||
vec2 texcoord;
|
||||
vec3 vertex_normal;
|
||||
vec3 view_vector;
|
||||
} vs_out;
|
||||
|
||||
uniform int normalmap_enabled;
|
||||
|
||||
uniform mat4 osg_ModelViewMatrix;
|
||||
uniform mat4 osg_ModelViewProjectionMatrix;
|
||||
uniform mat3 osg_NormalMatrix;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = osg_ModelViewProjectionMatrix * pos;
|
||||
texcoord = multitexcoord0.st;
|
||||
|
||||
vec3 N = normalize(normal);
|
||||
vec3 T, B;
|
||||
if (normalmap_enabled > 0) {
|
||||
T = tangent;
|
||||
B = binormal;
|
||||
} else {
|
||||
T = cross(N, vec3(1.0, 0.0, 0.0));
|
||||
B = cross(N, T);
|
||||
}
|
||||
TBN = mat3(normalize(osg_NormalMatrix * T),
|
||||
normalize(osg_NormalMatrix * B),
|
||||
normalize(osg_NormalMatrix * N));
|
||||
vs_out.texcoord = multitexcoord0.st;
|
||||
vs_out.vertex_normal = osg_NormalMatrix * normal;
|
||||
vs_out.view_vector = (osg_ModelViewMatrix * pos).xyz;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
#version 330 core
|
||||
|
||||
in vec3 vN;
|
||||
in vec2 texcoord;
|
||||
in vec4 material_color;
|
||||
in VS_OUT {
|
||||
vec2 texcoord;
|
||||
vec3 vertex_normal;
|
||||
vec4 material_color;
|
||||
} fs_in;
|
||||
|
||||
uniform sampler2D color_tex;
|
||||
|
||||
|
@ -17,8 +19,10 @@ vec3 eotf_inverse_sRGB(vec3 srgb);
|
|||
|
||||
void main()
|
||||
{
|
||||
vec3 texel = texture(color_tex, texcoord).rgb;
|
||||
vec3 color = eotf_inverse_sRGB(texel) * material_color.rgb;
|
||||
vec3 texel = texture(color_tex, fs_in.texcoord).rgb;
|
||||
vec3 color = eotf_inverse_sRGB(texel) * fs_in.material_color.rgb;
|
||||
|
||||
gbuffer_pack(vN, color, DEFAULT_METALLIC, DEFAULT_ROUGHNESS, 1.0, vec3(0.0), 3u);
|
||||
vec3 N = normalize(fs_in.vertex_normal);
|
||||
|
||||
gbuffer_pack(N, color, DEFAULT_METALLIC, DEFAULT_ROUGHNESS, 1.0, vec3(0.0), 3u);
|
||||
}
|
||||
|
|
|
@ -9,9 +9,11 @@ layout(location = 1) in vec3 normal;
|
|||
layout(location = 2) in vec4 vertex_color;
|
||||
layout(location = 3) in vec4 multitexcoord0;
|
||||
|
||||
out vec3 vN;
|
||||
out vec2 texcoord;
|
||||
out vec4 material_color;
|
||||
out VS_OUT {
|
||||
vec2 texcoord;
|
||||
vec3 vertex_normal;
|
||||
vec4 material_color;
|
||||
} vs_out;
|
||||
|
||||
uniform int color_mode;
|
||||
uniform vec4 material_diffuse;
|
||||
|
@ -22,14 +24,14 @@ uniform mat3 osg_NormalMatrix;
|
|||
void main()
|
||||
{
|
||||
gl_Position = osg_ModelViewProjectionMatrix * pos;
|
||||
vN = normalize(osg_NormalMatrix * normal);
|
||||
texcoord = multitexcoord0.st;
|
||||
vs_out.texcoord = multitexcoord0.st;
|
||||
vs_out.vertex_normal = osg_NormalMatrix * normal;
|
||||
|
||||
// Legacy material handling
|
||||
if (color_mode == MODE_DIFFUSE)
|
||||
material_color = vertex_color;
|
||||
vs_out.material_color = vertex_color;
|
||||
else if (color_mode == MODE_AMBIENT_AND_DIFFUSE)
|
||||
material_color = vertex_color;
|
||||
vs_out.material_color = vertex_color;
|
||||
else
|
||||
material_color = material_diffuse;
|
||||
vs_out.material_color = material_diffuse;
|
||||
}
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
#version 330 core
|
||||
|
||||
in vec2 texcoord;
|
||||
in mat3 TBN;
|
||||
in VS_OUT {
|
||||
vec2 texcoord;
|
||||
vec3 vertex_normal;
|
||||
vec3 view_vector;
|
||||
} fs_in;
|
||||
|
||||
uniform sampler2D base_color_tex;
|
||||
uniform sampler2D normal_tex;
|
||||
uniform sampler2D orm_tex;
|
||||
uniform sampler2D emissive_tex;
|
||||
|
||||
|
@ -18,21 +20,22 @@ void gbuffer_pack(vec3 normal, vec3 base_color, float metallic, float roughness,
|
|||
float occlusion, vec3 emissive, uint mat_id);
|
||||
// color.glsl
|
||||
vec3 eotf_inverse_sRGB(vec3 srgb);
|
||||
// normalmap.glsl
|
||||
vec3 perturb_normal(vec3 N, vec3 V, vec2 texcoord);
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 base_color_texel = texture(base_color_tex, texcoord);
|
||||
vec4 base_color_texel = texture(base_color_tex, fs_in.texcoord);
|
||||
vec3 base_color = eotf_inverse_sRGB(base_color_texel.rgb) * base_color_factor.rgb;
|
||||
|
||||
vec3 normal = texture(normal_tex, texcoord).rgb * 2.0 - 1.0;
|
||||
vec3 N = normalize(TBN * normal);
|
||||
|
||||
vec3 orm = texture(orm_tex, texcoord).rgb;
|
||||
vec3 orm = texture(orm_tex, fs_in.texcoord).rgb;
|
||||
float occlusion = orm.r;
|
||||
float roughness = orm.g * roughness_factor;
|
||||
float metallic = orm.b * metallic_factor;
|
||||
vec3 emissive = texture(emissive_tex, fs_in.texcoord).rgb * emissive_factor;
|
||||
|
||||
vec3 emissive = texture(emissive_tex, texcoord).rgb * emissive_factor;
|
||||
vec3 N = normalize(fs_in.vertex_normal);
|
||||
N = perturb_normal(N, fs_in.view_vector, fs_in.texcoord);
|
||||
|
||||
gbuffer_pack(N, base_color, metallic, roughness, occlusion, emissive, 3u);
|
||||
}
|
||||
|
|
|
@ -3,26 +3,26 @@
|
|||
layout(location = 0) in vec4 pos;
|
||||
layout(location = 1) in vec3 normal;
|
||||
layout(location = 3) in vec4 multitexcoord0;
|
||||
layout(location = 6) in vec3 tangent;
|
||||
layout(location = 7) in vec3 binormal;
|
||||
|
||||
out vec2 texcoord;
|
||||
out mat3 TBN;
|
||||
|
||||
uniform mat4 osg_ModelViewProjectionMatrix;
|
||||
uniform mat3 osg_NormalMatrix;
|
||||
out VS_OUT {
|
||||
vec2 texcoord;
|
||||
vec3 vertex_normal;
|
||||
vec3 view_vector;
|
||||
} vs_out;
|
||||
|
||||
uniform bool flip_vertically;
|
||||
|
||||
uniform mat4 osg_ModelViewMatrix;
|
||||
uniform mat4 osg_ModelViewProjectionMatrix;
|
||||
uniform mat3 osg_NormalMatrix;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = osg_ModelViewProjectionMatrix * pos;
|
||||
texcoord = multitexcoord0.st;
|
||||
vs_out.texcoord = multitexcoord0.st;
|
||||
if (flip_vertically)
|
||||
texcoord.y = 1.0 - texcoord.y;
|
||||
vs_out.texcoord.y = 1.0 - vs_out.texcoord.y;
|
||||
|
||||
vec3 T = normalize(osg_NormalMatrix * tangent);
|
||||
vec3 B = normalize(osg_NormalMatrix * binormal);
|
||||
vec3 N = normalize(osg_NormalMatrix * normal);
|
||||
TBN = mat3(T, B, N);
|
||||
vs_out.vertex_normal = osg_NormalMatrix * normal;
|
||||
vs_out.view_vector = (osg_ModelViewMatrix * pos).xyz;
|
||||
}
|
||||
|
|
|
@ -2,13 +2,14 @@
|
|||
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
|
||||
in vec3 vP;
|
||||
in vec2 texcoord;
|
||||
in mat3 TBN;
|
||||
in vec4 ap_color;
|
||||
in VS_OUT {
|
||||
vec2 texcoord;
|
||||
vec3 vertex_normal;
|
||||
vec3 view_vector;
|
||||
vec4 ap_color;
|
||||
} fs_in;
|
||||
|
||||
uniform sampler2D base_color_tex;
|
||||
uniform sampler2D normal_tex;
|
||||
uniform sampler2D orm_tex;
|
||||
uniform sampler2D emissive_tex;
|
||||
|
||||
|
@ -29,30 +30,32 @@ vec3 eval_lights_transparent(
|
|||
vec3 base_color, float metallic, float roughness, float occlusion,
|
||||
vec3 P, vec3 N, vec3 V, vec2 uv, vec4 ap,
|
||||
mat4 view_matrix_inverse);
|
||||
// normalmap.glsl
|
||||
vec3 perturb_normal(vec3 N, vec3 V, vec2 texcoord);
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 base_color_texel = texture(base_color_tex, texcoord);
|
||||
vec4 base_color_texel = texture(base_color_tex, fs_in.texcoord);
|
||||
vec4 base_color = vec4(eotf_inverse_sRGB(base_color_texel.rgb), base_color_texel.a)
|
||||
* base_color_factor;
|
||||
if (base_color.a < alpha_cutoff)
|
||||
discard;
|
||||
|
||||
vec3 normal = texture(normal_tex, texcoord).rgb * 2.0 - 1.0;
|
||||
vec3 N = normalize(TBN * normal);
|
||||
|
||||
vec3 orm = texture(orm_tex, texcoord).rgb;
|
||||
vec3 orm = texture(orm_tex, fs_in.texcoord).rgb;
|
||||
float occlusion = orm.r;
|
||||
float roughness = orm.g * roughness_factor;
|
||||
float metallic = orm.b * metallic_factor;
|
||||
vec3 emissive = texture(emissive_tex, texcoord).rgb * emissive_factor;
|
||||
vec3 emissive = texture(emissive_tex, fs_in.texcoord).rgb * emissive_factor;
|
||||
|
||||
vec3 V = normalize(-vP);
|
||||
vec3 V = normalize(-fs_in.view_vector);
|
||||
vec2 uv = (gl_FragCoord.xy - fg_Viewport.xy) / fg_Viewport.zw;
|
||||
|
||||
vec3 N = normalize(fs_in.vertex_normal);
|
||||
N = perturb_normal(N, fs_in.view_vector, fs_in.texcoord);
|
||||
|
||||
vec3 color = eval_lights_transparent(
|
||||
base_color.rgb, metallic, roughness, occlusion,
|
||||
vP, N, V, uv, ap_color, osg_ViewMatrixInverse);
|
||||
fs_in.view_vector, N, V, uv, fs_in.ap_color, osg_ViewMatrixInverse);
|
||||
|
||||
fragColor = vec4(color, base_color.a);
|
||||
}
|
||||
|
|
|
@ -3,36 +3,33 @@
|
|||
layout(location = 0) in vec4 pos;
|
||||
layout(location = 1) in vec3 normal;
|
||||
layout(location = 3) in vec4 multitexcoord0;
|
||||
layout(location = 6) in vec3 tangent;
|
||||
layout(location = 7) in vec3 binormal;
|
||||
|
||||
out vec3 vP;
|
||||
out vec2 texcoord;
|
||||
out mat3 TBN;
|
||||
out vec4 ap_color;
|
||||
out VS_OUT {
|
||||
vec2 texcoord;
|
||||
vec3 vertex_normal;
|
||||
vec3 view_vector;
|
||||
vec4 ap_color;
|
||||
} vs_out;
|
||||
|
||||
uniform bool flip_vertically;
|
||||
|
||||
uniform mat4 osg_ModelViewMatrix;
|
||||
uniform mat4 osg_ModelViewProjectionMatrix;
|
||||
uniform mat3 osg_NormalMatrix;
|
||||
|
||||
uniform bool flip_vertically;
|
||||
|
||||
// aerial_perspective.glsl
|
||||
vec4 get_aerial_perspective(vec2 coord, float depth);
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = osg_ModelViewProjectionMatrix * pos;
|
||||
vP = (osg_ModelViewMatrix * pos).xyz;
|
||||
texcoord = multitexcoord0.st;
|
||||
vs_out.texcoord = multitexcoord0.st;
|
||||
if (flip_vertically)
|
||||
texcoord.y = 1.0 - texcoord.y;
|
||||
vs_out.texcoord.y = 1.0 - vs_out.texcoord.y;
|
||||
|
||||
vec3 T = normalize(osg_NormalMatrix * tangent);
|
||||
vec3 B = normalize(osg_NormalMatrix * binormal);
|
||||
vec3 N = normalize(osg_NormalMatrix * normal);
|
||||
TBN = mat3(T, B, N);
|
||||
vs_out.vertex_normal = osg_NormalMatrix * normal;
|
||||
vs_out.view_vector = (osg_ModelViewMatrix * pos).xyz;
|
||||
|
||||
vec2 coord = (gl_Position.xy / gl_Position.w) * 0.5 + 0.5;
|
||||
ap_color = get_aerial_perspective(coord, length(vP));
|
||||
vs_out.ap_color = get_aerial_perspective(coord, length(vs_out.view_vector));
|
||||
}
|
||||
|
|
|
@ -30,12 +30,13 @@ void main()
|
|||
vec3 base_color = eotf_inverse_sRGB(texel.rgb) * material_color.rgb;
|
||||
float alpha = material_color.a * texel.a;
|
||||
|
||||
vec3 N = normalize(vN);
|
||||
vec3 V = normalize(-vP);
|
||||
vec2 uv = (gl_FragCoord.xy - fg_Viewport.xy) / fg_Viewport.zw;
|
||||
|
||||
vec3 color = eval_lights_transparent(
|
||||
base_color, TRANSPARENT_METALLIC, TRANSPARENT_ROUGHNESS, 1.0,
|
||||
vP, vN, V, uv, ap_color, osg_ViewMatrixInverse);
|
||||
vP, N, V, uv, ap_color, osg_ViewMatrixInverse);
|
||||
|
||||
fragColor = vec4(color, alpha);
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ vec4 get_aerial_perspective(vec2 coord, float depth);
|
|||
void main()
|
||||
{
|
||||
gl_Position = osg_ModelViewProjectionMatrix * pos;
|
||||
vN = normalize(osg_NormalMatrix * normal);
|
||||
vN = osg_NormalMatrix * normal;
|
||||
vP = (osg_ModelViewMatrix * pos).xyz;
|
||||
texcoord = multitexcoord0.st;
|
||||
|
||||
|
|
42
Shaders/HDR/normalmap.glsl
Normal file
42
Shaders/HDR/normalmap.glsl
Normal file
|
@ -0,0 +1,42 @@
|
|||
#version 330 core
|
||||
|
||||
uniform sampler2D normal_tex;
|
||||
uniform int normalmap_dds = 0;
|
||||
|
||||
/*
|
||||
* Create a cotangent frame without a pre-computed tangent basis.
|
||||
* "Normal Mapping Without Precomputed Tangents" by Christian Schüler (2013).
|
||||
* http://www.thetenthplanet.de/archives/1180
|
||||
*/
|
||||
mat3 cotangent_frame(vec3 N, vec3 p, vec2 uv)
|
||||
{
|
||||
// get edge vectors of the pixel triangle
|
||||
vec3 dp1 = dFdx(p);
|
||||
vec3 dp2 = dFdy(p);
|
||||
vec2 duv1 = dFdx(uv);
|
||||
vec2 duv2 = dFdy(uv);
|
||||
// solve the linear system
|
||||
vec3 dp2perp = cross(dp2, N);
|
||||
vec3 dp1perp = cross(N, dp1);
|
||||
vec3 T = dp2perp * duv1.x + dp1perp * duv2.x;
|
||||
vec3 B = dp2perp * duv1.y + dp1perp * duv2.y;
|
||||
// construct a scale-invariant frame
|
||||
float invmax = inversesqrt(max(dot(T,T), dot(B,B)));
|
||||
return mat3(T * invmax, B * invmax, N);
|
||||
}
|
||||
|
||||
/*
|
||||
* Perturb the interpolated vertex normal N according to a normal map.
|
||||
* V is the view vector (eye to vertex, not normalized). Both N and V must be
|
||||
* in the same space.
|
||||
*/
|
||||
vec3 perturb_normal(vec3 N, vec3 V, vec2 texcoord)
|
||||
{
|
||||
vec3 normal = texture(normal_tex, texcoord).rgb * 2.0 - 1.0;
|
||||
if (normalmap_dds > 0) {
|
||||
// DDS has flipped normals
|
||||
normal = -normal;
|
||||
}
|
||||
mat3 TBN = cotangent_frame(N, V, texcoord);
|
||||
return normalize(TBN * normal);
|
||||
}
|
|
@ -1,8 +1,10 @@
|
|||
#version 330 core
|
||||
|
||||
in vec3 vN;
|
||||
in vec2 texcoord;
|
||||
in vec2 orthophoto_texcoord;
|
||||
in VS_OUT {
|
||||
vec2 texcoord;
|
||||
vec2 orthophoto_texcoord;
|
||||
vec3 vertex_normal;
|
||||
} fs_in;
|
||||
|
||||
uniform sampler2D color_tex;
|
||||
uniform sampler2D orthophoto_tex;
|
||||
|
@ -20,9 +22,9 @@ vec3 eotf_inverse_sRGB(vec3 srgb);
|
|||
|
||||
void main()
|
||||
{
|
||||
vec3 texel = texture(color_tex, texcoord).rgb;
|
||||
vec3 texel = texture(color_tex, fs_in.texcoord).rgb;
|
||||
if (orthophotoAvailable) {
|
||||
vec4 sat_texel = texture(orthophoto_tex, orthophoto_texcoord);
|
||||
vec4 sat_texel = texture(orthophoto_tex, fs_in.orthophoto_texcoord);
|
||||
if (sat_texel.a > 0.0) {
|
||||
texel.rgb = sat_texel.rgb;
|
||||
}
|
||||
|
@ -30,5 +32,7 @@ void main()
|
|||
|
||||
vec3 color = eotf_inverse_sRGB(texel);
|
||||
|
||||
gbuffer_pack(vN, color, TERRAIN_METALLIC, TERRAIN_ROUGHNESS, 1.0, vec3(0.0), 3u);
|
||||
vec3 N = normalize(fs_in.vertex_normal);
|
||||
|
||||
gbuffer_pack(N, color, TERRAIN_METALLIC, TERRAIN_ROUGHNESS, 1.0, vec3(0.0), 3u);
|
||||
}
|
||||
|
|
|
@ -5,9 +5,11 @@ layout(location = 1) in vec3 normal;
|
|||
layout(location = 3) in vec4 multitexcoord0;
|
||||
layout(location = 5) in vec4 multitexcoord2;
|
||||
|
||||
out vec3 vN;
|
||||
out vec2 texcoord;
|
||||
out vec2 orthophoto_texcoord;
|
||||
out VS_OUT {
|
||||
vec2 texcoord;
|
||||
vec2 orthophoto_texcoord;
|
||||
vec3 vertex_normal;
|
||||
} vs_out;
|
||||
|
||||
uniform mat4 osg_ModelViewProjectionMatrix;
|
||||
uniform mat3 osg_NormalMatrix;
|
||||
|
@ -15,7 +17,7 @@ uniform mat3 osg_NormalMatrix;
|
|||
void main()
|
||||
{
|
||||
gl_Position = osg_ModelViewProjectionMatrix * pos;
|
||||
vN = normalize(osg_NormalMatrix * normal);
|
||||
texcoord = multitexcoord0.st;
|
||||
orthophoto_texcoord = multitexcoord2.st;
|
||||
vs_out.texcoord = multitexcoord0.st;
|
||||
vs_out.orthophoto_texcoord = multitexcoord2.st;
|
||||
vs_out.vertex_normal = osg_NormalMatrix * normal;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
#version 330 core
|
||||
|
||||
in vec3 vN;
|
||||
in vec2 texcoord;
|
||||
in VS_OUT {
|
||||
vec2 texcoord;
|
||||
vec3 vertex_normal;
|
||||
} fs_in;
|
||||
|
||||
uniform sampler2D color_tex;
|
||||
|
||||
|
@ -13,11 +15,13 @@ vec3 eotf_inverse_sRGB(vec3 srgb);
|
|||
|
||||
void main()
|
||||
{
|
||||
vec4 texel = texture(color_tex, texcoord);
|
||||
vec4 texel = texture(color_tex, fs_in.texcoord);
|
||||
if (texel.a < 0.5)
|
||||
discard;
|
||||
|
||||
vec3 color = eotf_inverse_sRGB(texel.rgb);
|
||||
|
||||
gbuffer_pack(vN, color, 0.0, 0.9, 1.0, vec3(0.0), 3u);
|
||||
vec3 N = normalize(fs_in.vertex_normal);
|
||||
|
||||
gbuffer_pack(N, color, 0.0, 0.9, 1.0, vec3(0.0), 3u);
|
||||
}
|
||||
|
|
|
@ -4,8 +4,10 @@ layout(location = 0) in vec4 pos;
|
|||
layout(location = 1) in vec3 normal;
|
||||
layout(location = 3) in vec4 multitexcoord0;
|
||||
|
||||
out vec3 vN;
|
||||
out vec2 texcoord;
|
||||
out VS_OUT {
|
||||
vec2 texcoord;
|
||||
vec3 vertex_normal;
|
||||
} vs_out;
|
||||
|
||||
uniform mat4 osg_ModelViewProjectionMatrix;
|
||||
uniform mat3 osg_NormalMatrix;
|
||||
|
@ -16,6 +18,6 @@ void main()
|
|||
raised_pos.z += 0.05;
|
||||
|
||||
gl_Position = osg_ModelViewProjectionMatrix * raised_pos;
|
||||
vN = normalize(osg_NormalMatrix * normal);
|
||||
texcoord = multitexcoord0.st;
|
||||
vs_out.texcoord = multitexcoord0.st;
|
||||
vs_out.vertex_normal = osg_NormalMatrix * normal;
|
||||
}
|
||||
|
|
|
@ -1,31 +1,35 @@
|
|||
#version 330 core
|
||||
|
||||
in vec3 rawpos;
|
||||
in vec2 texcoord;
|
||||
in mat3 TBN;
|
||||
in VS_OUT {
|
||||
vec2 texcoord;
|
||||
vec3 vertex_normal;
|
||||
vec3 view_vector;
|
||||
vec3 rawpos;
|
||||
} fs_in;
|
||||
|
||||
uniform sampler2D color_tex;
|
||||
uniform sampler2D normal_tex;
|
||||
uniform sampler3D noise_tex;
|
||||
|
||||
const float NORMAL_MAP_SCALE = 8.0;
|
||||
const float NORMALMAP_SCALE = 8.0;
|
||||
|
||||
// gbuffer_pack.glsl
|
||||
void gbuffer_pack(vec3 normal, vec3 base_color, float metallic, float roughness,
|
||||
float occlusion, vec3 emissive, uint mat_id);
|
||||
// color.glsl
|
||||
vec3 eotf_inverse_sRGB(vec3 srgb);
|
||||
// normalmap.glsl
|
||||
vec3 perturb_normal(vec3 N, vec3 V, vec2 texcoord);
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 texel = texture(color_tex, texcoord);
|
||||
vec4 texel = texture(color_tex, fs_in.texcoord);
|
||||
vec3 color = eotf_inverse_sRGB(texel.rgb);
|
||||
|
||||
vec3 normal = texture(normal_tex, texcoord * NORMAL_MAP_SCALE).rgb * 2.0 - 1.0;
|
||||
vec3 N = normalize(TBN * normal);
|
||||
vec3 N = normalize(fs_in.vertex_normal);
|
||||
N = perturb_normal(N, fs_in.view_vector, fs_in.texcoord * NORMALMAP_SCALE);
|
||||
|
||||
vec3 noise_large = texture(noise_tex, rawpos * 0.0045).rgb;
|
||||
vec3 noise_small = texture(noise_tex, rawpos).rgb;
|
||||
vec3 noise_large = texture(noise_tex, fs_in.rawpos * 0.0045).rgb;
|
||||
vec3 noise_small = texture(noise_tex, fs_in.rawpos).rgb;
|
||||
|
||||
float mix_factor = noise_large.r * noise_large.g * noise_large.b * 350.0;
|
||||
mix_factor = smoothstep(0.0, 1.0, mix_factor);
|
||||
|
|
|
@ -4,24 +4,22 @@ layout(location = 0) in vec4 pos;
|
|||
layout(location = 1) in vec3 normal;
|
||||
layout(location = 3) in vec4 multitexcoord0;
|
||||
|
||||
out vec3 rawpos;
|
||||
out vec2 texcoord;
|
||||
out mat3 TBN;
|
||||
out VS_OUT {
|
||||
vec2 texcoord;
|
||||
vec3 vertex_normal;
|
||||
vec3 view_vector;
|
||||
vec3 rawpos;
|
||||
} vs_out;
|
||||
|
||||
uniform mat4 osg_ModelViewMatrix;
|
||||
uniform mat4 osg_ModelViewProjectionMatrix;
|
||||
uniform mat3 osg_NormalMatrix;
|
||||
|
||||
void main()
|
||||
{
|
||||
rawpos = pos.xyz / pos.w;
|
||||
gl_Position = osg_ModelViewProjectionMatrix * pos;
|
||||
texcoord = multitexcoord0.st;
|
||||
|
||||
vec3 tangent = cross(normal, vec3(1.0, 0.0, 0.0));
|
||||
vec3 binormal = cross(normal, tangent);
|
||||
|
||||
vec3 T = normalize(osg_NormalMatrix * tangent);
|
||||
vec3 B = normalize(osg_NormalMatrix * binormal);
|
||||
vec3 N = normalize(osg_NormalMatrix * normal);
|
||||
TBN = mat3(T, B, N);
|
||||
vs_out.texcoord = multitexcoord0.st;
|
||||
vs_out.vertex_normal = osg_NormalMatrix * normal;
|
||||
vs_out.view_vector = (osg_ModelViewMatrix * pos).xyz;
|
||||
vs_out.rawpos = pos.xyz / pos.w;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue