1
0
Fork 0

HDR: Support glTF models

This commit is contained in:
Fernando García Liñán 2021-08-16 17:04:18 +02:00
parent d1b7bd154f
commit 13df616ca6
3 changed files with 52 additions and 43 deletions

View file

@ -10,32 +10,33 @@
<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>repeat</wrap-s>
<wrap-t>repeat</wrap-t>
<internal-format>normalized</internal-format>
<type>null-normalmap</type>
</texture>
<!-- Metallic -->
<!-- Metallic and Roughness -->
<texture n="2">
<type>white</type>
</texture>
<metallic-factor type="float">1.0</metallic-factor>
<!-- Roughness -->
<roughness-factor type="float">1.0</roughness-factor>
<!-- Occlusion -->
<texture n="3">
<type>white</type>
</texture>
<roughness-factor type="float">1.0</roughness-factor>
<!-- Occlusion -->
<!-- Emissive -->
<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>
<!-- Alpha Coverage -->
<blend>
<active>false</active>
</blend>
<rendering-hint>opaque</rendering-hint>
<alpha-cutoff>-1.0</alpha-cutoff>
<!-- Double Sided -->
<cull-face>back</cull-face>
<!-- Whether to flip the texture vertically -->
<flip-vertically>false</flip-vertically>
</parameters>
<generate>
@ -51,56 +52,49 @@
<type><use>texture[0]/type</use></type>
<image><use>texture[0]/image</use></image>
<filter><use>texture[0]/filter</use></filter>
<mag-filter><use>texture[0]/mag-filter</use></mag-filter>
<wrap-s><use>texture[0]/wrap-s</use></wrap-s>
<wrap-t><use>texture[0]/wrap-t</use></wrap-t>
<internal-format><use>texture[0]/internal-format</use></internal-format>
</texture-unit>
<texture-unit>
<unit>1</unit>
<type><use>texture[1]/type</use></type>
<image><use>texture[1]/image</use></image>
<filter><use>texture[1]/filter</use></filter>
<mag-filter><use>texture[1]/mag-filter</use></mag-filter>
<wrap-s><use>texture[1]/wrap-s</use></wrap-s>
<wrap-t><use>texture[1]/wrap-t</use></wrap-t>
<internal-format><use>texture[1]/internal-format</use></internal-format>
</texture-unit>
<texture-unit>
<unit>2</unit>
<type><use>texture[2]/type</use></type>
<image><use>texture[2]/image</use></image>
<filter><use>texture[2]/filter</use></filter>
<mag-filter><use>texture[2]/mag-filter</use></mag-filter>
<wrap-s><use>texture[2]/wrap-s</use></wrap-s>
<wrap-t><use>texture[2]/wrap-t</use></wrap-t>
<internal-format><use>texture[2]/internal-format</use></internal-format>
</texture-unit>
<texture-unit>
<unit>3</unit>
<type><use>texture[3]/type</use></type>
<image><use>texture[3]/image</use></image>
<filter><use>texture[3]/filter</use></filter>
<mag-filter><use>texture[3]/mag-filter</use></mag-filter>
<wrap-s><use>texture[3]/wrap-s</use></wrap-s>
<wrap-t><use>texture[3]/wrap-t</use></wrap-t>
<internal-format><use>texture[3]/internal-format</use></internal-format>
</texture-unit>
<texture-unit>
<unit>4</unit>
<type><use>texture[4]/type</use></type>
<image><use>texture[4]/image</use></image>
<filter><use>texture[4]/filter</use></filter>
<mag-filter><use>texture[0]/mag-filter</use></mag-filter>
<wrap-s><use>texture[4]/wrap-s</use></wrap-s>
<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>
<blend><active><use>blend/active</use></active></blend>
<rendering-hint><use>rendering-hint</use></rendering-hint>
<cull-face><use>cull-face</use></cull-face>
<program>
<vertex-shader>Shaders/HDR/geometry-pbr.vert</vertex-shader>
<fragment-shader>Shaders/HDR/geometry-pbr.frag</fragment-shader>
@ -125,24 +119,19 @@
<value type="int">1</value>
</uniform>
<uniform>
<name>metallic_tex</name>
<name>metallic_roughness_tex</name>
<type>sampler-2d</type>
<value type="int">2</value>
</uniform>
<uniform>
<name>roughness_tex</name>
<name>occlusion_tex</name>
<type>sampler-2d</type>
<value type="int">3</value>
</uniform>
<uniform>
<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>
<value type="int">4</value>
</uniform>
<uniform>
<name>base_color_factor</name>
@ -164,6 +153,16 @@
<type>float-vec3</type>
<value><use>emissive-factor</use></value>
</uniform>
<uniform>
<name>alpha_cutoff</name>
<type>float</type>
<value><use>alpha-cutoff</use></value>
</uniform>
<uniform>
<name>flip_vertically</name>
<type>bool</type>
<value><use>flip-vertically</use></value>
</uniform>
</pass>
</technique>
</PropertyList>

View file

@ -9,22 +9,27 @@ in mat3 TBN;
uniform sampler2D base_color_tex;
uniform sampler2D normal_tex;
uniform sampler2D metallic_tex;
uniform sampler2D roughness_tex;
uniform sampler2D metallic_roughness_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;
uniform float alpha_cutoff;
vec2 encodeNormal(vec3 n);
vec3 decodeSRGB(vec3 screenRGB);
void main()
{
vec4 base_color_texel = texture(base_color_tex, texCoord);
gbuffer0.rgb = decodeSRGB(base_color_texel.rgb); // Ignore alpha
vec4 baseColorTexel = texture(base_color_tex, texCoord);
vec4 baseColor = vec4(decodeSRGB(baseColorTexel.rgb), baseColorTexel.a)
* base_color_factor;
if (baseColor.a < alpha_cutoff)
discard;
gbuffer0.rgb = baseColor.rgb;
float occlusion = texture(occlusion_tex, texCoord).r;
gbuffer0.a = occlusion;
@ -32,8 +37,9 @@ void main()
normal = normalize(TBN * normal);
gbuffer1 = encodeNormal(normal);
float metallic = texture(metallic_tex, texCoord).r * metallic_factor;
float roughness = texture(roughness_tex, texCoord).r * roughness_factor;
vec4 metallicRoughness = texture(metallic_roughness_tex, texCoord);
float metallic = metallicRoughness.r * metallic_factor;
float roughness = metallicRoughness.g * roughness_factor;
gbuffer2 = vec4(metallic, roughness, 0.0, 0.0);
vec3 emissive = texture(emissive_tex, texCoord).rgb * emissive_factor;

View file

@ -12,10 +12,14 @@ out mat3 TBN;
uniform mat4 osg_ModelViewProjectionMatrix;
uniform mat3 osg_NormalMatrix;
uniform bool flip_vertically;
void main()
{
gl_Position = osg_ModelViewProjectionMatrix * pos;
texCoord = multiTexCoord0.st;
if (flip_vertically)
texCoord.y = 1.0 - texCoord.y;
vec3 T = normalize(osg_NormalMatrix * tangent);
vec3 B = normalize(osg_NormalMatrix * binormal);