HDR: Improve PBR Effect
This commit is contained in:
parent
871654c16f
commit
5c1c28c536
5 changed files with 83 additions and 36 deletions
|
@ -3,41 +3,39 @@
|
|||
<PropertyList>
|
||||
<name>Effects/model-pbr</name>
|
||||
<parameters>
|
||||
<!-- Albedo -->
|
||||
<!-- Base Color -->
|
||||
<texture n="0">
|
||||
<type>white</type>
|
||||
</texture>
|
||||
<base-color-factor type="vec4d">1.0 1.0 1.0 1.0</base-color-factor>
|
||||
<!-- Normalmap -->
|
||||
<texture n="1">
|
||||
<image>Aircraft/Generic/Effects/null_bumpspec.png</image>
|
||||
<type>2d</type>
|
||||
<filter>linear-mipmap-linear</filter>
|
||||
<wrap-s>clamp</wrap-s>
|
||||
<wrap-t>clamp</wrap-t>
|
||||
<wrap-s>repeat</wrap-s>
|
||||
<wrap-t>repeat</wrap-t>
|
||||
<internal-format>normalized</internal-format>
|
||||
</texture>
|
||||
<!-- Metalness -->
|
||||
<!-- Metallic -->
|
||||
<texture n="2">
|
||||
<image>Aircraft/Generic/Effects/ReflectMaps/null_reflectdirt.png</image>
|
||||
<type>2d</type>
|
||||
<filter>linear-mipmap-linear</filter>
|
||||
<wrap-s>clamp</wrap-s>
|
||||
<wrap-t>clamp</wrap-t>
|
||||
<internal-format>normalized</internal-format>
|
||||
<type>white</type>
|
||||
</texture>
|
||||
<metallic-factor type="float">1.0</metallic-factor>
|
||||
<!-- Roughness -->
|
||||
<texture n="3">
|
||||
<image>Aircraft/Generic/Effects/greymap.png</image>
|
||||
<type>2d</type>
|
||||
<filter>linear-mipmap-linear</filter>
|
||||
<wrap-s>clamp</wrap-s>
|
||||
<wrap-t>clamp</wrap-t>
|
||||
<internal-format>normalized</internal-format>
|
||||
<type>white</type>
|
||||
</texture>
|
||||
<!-- Cavity -->
|
||||
<roughness-factor type="float">1.0</roughness-factor>
|
||||
<!-- Occlusion -->
|
||||
<texture n="4">
|
||||
<type>white</type>
|
||||
</texture>
|
||||
<!-- Emissive -->
|
||||
<texture n="5">
|
||||
<type>white</type>
|
||||
</texture>
|
||||
<emissive-factor type="vec3d">0.0 0.0 0.0</emissive-factor>
|
||||
</parameters>
|
||||
|
||||
<generate>
|
||||
|
@ -93,6 +91,15 @@
|
|||
<wrap-t><use>texture[4]/wrap-t</use></wrap-t>
|
||||
<internal-format><use>texture[4]/internal-format</use></internal-format>
|
||||
</texture-unit>
|
||||
<texture-unit>
|
||||
<unit>5</unit>
|
||||
<type><use>texture[5]/type</use></type>
|
||||
<image><use>texture[5]/image</use></image>
|
||||
<filter><use>texture[5]/filter</use></filter>
|
||||
<wrap-s><use>texture[5]/wrap-s</use></wrap-s>
|
||||
<wrap-t><use>texture[5]/wrap-t</use></wrap-t>
|
||||
<internal-format><use>texture[5]/internal-format</use></internal-format>
|
||||
</texture-unit>
|
||||
<cull-face>back</cull-face>
|
||||
<program>
|
||||
<vertex-shader>Shaders/HDR/geometry-pbr.vert</vertex-shader>
|
||||
|
@ -108,7 +115,7 @@
|
|||
</attribute>
|
||||
</program>
|
||||
<uniform>
|
||||
<name>albedo_tex</name>
|
||||
<name>base_color_tex</name>
|
||||
<type>sampler-2d</type>
|
||||
<value type="int">0</value>
|
||||
</uniform>
|
||||
|
@ -118,7 +125,7 @@
|
|||
<value type="int">1</value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>metalness_tex</name>
|
||||
<name>metallic_tex</name>
|
||||
<type>sampler-2d</type>
|
||||
<value type="int">2</value>
|
||||
</uniform>
|
||||
|
@ -128,10 +135,35 @@
|
|||
<value type="int">3</value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>cavity_tex</name>
|
||||
<name>occlusion_tex</name>
|
||||
<type>sampler-2d</type>
|
||||
<value type="int">4</value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>emissive_tex</name>
|
||||
<type>sampler-2d</type>
|
||||
<value type="int">5</value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>base_color_factor</name>
|
||||
<type>float-vec4</type>
|
||||
<value><use>base-color-factor</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>metallic_factor</name>
|
||||
<type>float</type>
|
||||
<value><use>metallic-factor</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>roughness_factor</name>
|
||||
<type>float</type>
|
||||
<value><use>roughness-factor</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>emissive_factor</name>
|
||||
<type>float-vec3</type>
|
||||
<value><use>emissive-factor</use></value>
|
||||
</uniform>
|
||||
</pass>
|
||||
</technique>
|
||||
</PropertyList>
|
||||
|
|
|
@ -16,10 +16,10 @@ vec3 decodeNormal(vec2 enc)
|
|||
{
|
||||
vec2 fenc = enc * 4.0 - 2.0;
|
||||
float f = dot(fenc, fenc);
|
||||
float g = sqrt(1.0 - f / 4.0);
|
||||
float g = sqrt(1.0 - f * 0.25);
|
||||
vec3 n;
|
||||
n.xy = fenc * g;
|
||||
n.z = 1.0 - f / 2.0;
|
||||
n.z = 1.0 - f * 0.5;
|
||||
return n;
|
||||
}
|
||||
|
||||
|
@ -38,3 +38,11 @@ float linearizeDepth(float depth)
|
|||
return (2.0 * fg_NearFar.x) / (
|
||||
fg_NearFar.y + fg_NearFar.x - depth * (fg_NearFar.y - fg_NearFar.x));
|
||||
}
|
||||
|
||||
vec3 decodeSRGB(vec3 screenRGB)
|
||||
{
|
||||
vec3 a = screenRGB / 12.92;
|
||||
vec3 b = pow((screenRGB + 0.055) / 1.055, vec3(2.4));
|
||||
vec3 c = step(vec3(0.04045), screenRGB);
|
||||
return mix(a, b, c);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
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;
|
||||
|
@ -10,9 +12,6 @@ out mat3 TBN;
|
|||
uniform mat4 osg_ModelViewProjectionMatrix;
|
||||
uniform mat3 osg_NormalMatrix;
|
||||
|
||||
attribute vec3 tangent;
|
||||
attribute vec3 binormal;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = osg_ModelViewProjectionMatrix * pos;
|
||||
|
|
|
@ -7,25 +7,34 @@ layout(location = 2) out vec4 gbuffer2;
|
|||
in vec2 texCoord;
|
||||
in mat3 TBN;
|
||||
|
||||
uniform sampler2D albedo_tex;
|
||||
uniform sampler2D base_color_tex;
|
||||
uniform sampler2D normal_tex;
|
||||
uniform sampler2D metalness_tex;
|
||||
uniform sampler2D metallic_tex;
|
||||
uniform sampler2D roughness_tex;
|
||||
uniform sampler2D cavity_tex;
|
||||
uniform sampler2D occlusion_tex;
|
||||
uniform sampler2D emissive_tex;
|
||||
uniform vec4 base_color_factor;
|
||||
uniform float metallic_factor;
|
||||
uniform float roughness_factor;
|
||||
uniform vec3 emissive_factor;
|
||||
|
||||
vec2 encodeNormal(vec3 n);
|
||||
vec3 decodeSRGB(vec3 screenRGB);
|
||||
|
||||
void main()
|
||||
{
|
||||
gbuffer0.rgb = pow(texture(albedo_tex, texCoord).rgb, vec3(2.2)); // Gamma correction
|
||||
gbuffer0.a = texture(cavity_tex, texCoord).r;
|
||||
vec4 base_color_texel = texture(base_color_tex, texCoord);
|
||||
gbuffer0.rgb = decodeSRGB(base_color_texel.rgb); // Ignore alpha
|
||||
float occlusion = texture(occlusion_tex, texCoord).r;
|
||||
gbuffer0.a = occlusion;
|
||||
|
||||
vec3 normal = texture(normal_tex, texCoord).rgb * 2.0 - 1.0;
|
||||
normal = normalize(TBN * normal);
|
||||
gbuffer1 = encodeNormal(normal);
|
||||
|
||||
float metalness = texture(metalness_tex, texCoord).r;
|
||||
float roughness = texture(roughness_tex, texCoord).r;
|
||||
float metallic = texture(metallic_tex, texCoord).r * metallic_factor;
|
||||
float roughness = texture(roughness_tex, texCoord).r * roughness_factor;
|
||||
gbuffer2 = vec4(metallic, roughness, 0.0, 0.0);
|
||||
|
||||
gbuffer2 = vec4(metalness, roughness, 0.0, 0.0);
|
||||
vec3 emissive = texture(emissive_tex, texCoord).rgb * emissive_factor;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
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;
|
||||
|
@ -10,9 +12,6 @@ out mat3 TBN;
|
|||
uniform mat4 osg_ModelViewProjectionMatrix;
|
||||
uniform mat3 osg_NormalMatrix;
|
||||
|
||||
attribute vec3 tangent;
|
||||
attribute vec3 binormal;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = osg_ModelViewProjectionMatrix * pos;
|
||||
|
|
Loading…
Add table
Reference in a new issue