diff --git a/Effects/glass.eff b/Effects/glass.eff
index 0a1b1be57..46ab33021 100644
--- a/Effects/glass.eff
+++ b/Effects/glass.eff
@@ -68,6 +68,15 @@
1.0 1.0 1.0
1.0
1.0 1.0 1.0
+
+ Textures/PBR/dfg_lut.dds
+ 2d
+ linear
+ linear
+ clamp-to-edge
+ clamp-to-edge
+ normalized
+
@@ -519,9 +528,93 @@
hdr-geometry
-
+
hdr-forward
+
+
+
+ gequal
+ 1.0
+ 0.0
+
+
+ 0
+
+
+
+
+
+
+
+
+ 8
+
+
+
+
+
+
+
+
+ 1
+ transparent
+
+
+ Shaders/HDR/geometry-transparent.vert
+ Shaders/HDR/geometry-transparent.frag
+ Shaders/HDR/gbuffer-include.frag
+ Shaders/HDR/lighting-include.frag
+ Shaders/HDR/aerial-perspective-include.frag
+
+
+ color_tex
+ sampler-2d
+ 0
+
+
+ color_mode
+ int
+
+
+
+ material_diffuse
+ float-vec4
+
+
+
+ minimum_alpha
+ float
+ 0.1
+
+
+
+ dfg_lut
+ sampler-2d
+ 8
+
+
+ prefiltered_envmap
+ sampler-cube
+ 9
+
+
+ shadow_tex
+ sampler-2d-shadow
+ 10
+
+
+
+ aerial_perspective_lut
+ sampler-2d
+ 11
+
+
+ transmittance_lut
+ sampler-2d
+ 12
+
+
diff --git a/Effects/model-combined-transparent.eff b/Effects/model-combined-transparent.eff
index 31849d184..c369166ef 100644
--- a/Effects/model-combined-transparent.eff
+++ b/Effects/model-combined-transparent.eff
@@ -6,11 +6,102 @@ and fallback to plain transparency when the model shader is disabled.
Effects/model-combined-transparent
Effects/model-combined
+
+
+ Textures/PBR/dfg_lut.dds
+ 2d
+ linear
+ linear
+ clamp-to-edge
+ clamp-to-edge
+ normalized
+
+
hdr-geometry
+
hdr-forward
+
+
+
+ gequal
+ 1.0
+ 0.0
+
+
+ 0
+
+
+
+
+
+
+
+
+ 8
+
+
+
+
+
+
+
+
+ 1
+ transparent
+
+
+ Shaders/HDR/geometry-transparent.vert
+ Shaders/HDR/geometry-transparent.frag
+ Shaders/HDR/gbuffer-include.frag
+ Shaders/HDR/lighting-include.frag
+ Shaders/HDR/aerial-perspective-include.frag
+
+
+ color_tex
+ sampler-2d
+ 0
+
+
+ color_mode
+ int
+
+
+
+ material_diffuse
+ float-vec4
+
+
+
+
+ dfg_lut
+ sampler-2d
+ 8
+
+
+ prefiltered_envmap
+ sampler-cube
+ 9
+
+
+ shadow_tex
+ sampler-2d-shadow
+ 10
+
+
+
+ aerial_perspective_lut
+ sampler-2d
+ 11
+
+
+ transmittance_lut
+ sampler-2d
+ 12
+
+
diff --git a/Effects/model-combined.eff b/Effects/model-combined.eff
index 6f3b3174e..f6cb73ef0 100644
--- a/Effects/model-combined.eff
+++ b/Effects/model-combined.eff
@@ -1340,6 +1340,11 @@ please see Docs/README.model-combined.eff for documentation
int
+
+ normalmap_dds
+ int
+
+
normalmap_tiling
float
@@ -1347,7 +1352,7 @@ please see Docs/README.model-combined.eff for documentation
-
+
false
diff --git a/Effects/model-default.eff b/Effects/model-default.eff
index 88284f914..7b4f77640 100644
--- a/Effects/model-default.eff
+++ b/Effects/model-default.eff
@@ -651,4 +651,47 @@
+
+ hdr-geometry
+
+
+
+ gequal
+ 1.0
+ 0.0
+
+
+ 0
+
+
+
+
+
+
+ 0
+ opaque
+
+
+ Shaders/HDR/geometry.vert
+ Shaders/HDR/geometry.frag
+ Shaders/HDR/gbuffer-include.frag
+
+
+ color_tex
+ sampler-2d
+ 0
+
+
+ color_mode
+ int
+
+
+
+ material_diffuse
+ float-vec4
+
+
+
+
+
diff --git a/Effects/model-transparent.eff b/Effects/model-transparent.eff
index b81bcff55..1f9c26590 100644
--- a/Effects/model-transparent.eff
+++ b/Effects/model-transparent.eff
@@ -31,6 +31,15 @@
+
+ Textures/PBR/dfg_lut.dds
+ 2d
+ linear
+ linear
+ clamp-to-edge
+ clamp-to-edge
+ normalized
+
@@ -123,6 +132,84 @@
hdr-forward
+
+
+
+ gequal
+ 1.0
+ 0.0
+
+
+ 0
+
+
+
+
+
+
+
+
+ 8
+
+
+
+
+
+
+
+
+ 1
+ transparent
+
+
+ Shaders/HDR/geometry-transparent.vert
+ Shaders/HDR/geometry-transparent.frag
+ Shaders/HDR/gbuffer-include.frag
+ Shaders/HDR/lighting-include.frag
+ Shaders/HDR/aerial-perspective-include.frag
+
+
+ color_tex
+ sampler-2d
+ 0
+
+
+ color_mode
+ int
+
+
+
+ material_diffuse
+ float-vec4
+
+
+
+
+ dfg_lut
+ sampler-2d
+ 8
+
+
+ prefiltered_envmap
+ sampler-cube
+ 9
+
+
+ shadow_tex
+ sampler-2d-shadow
+ 10
+
+
+
+ aerial_perspective_lut
+ sampler-2d
+ 11
+
+
+ transmittance_lut
+ sampler-2d
+ 12
+
+
-
diff --git a/Shaders/HDR/geometry-combined.frag b/Shaders/HDR/geometry-combined.frag
index a9ff63f8a..b6593c01b 100644
--- a/Shaders/HDR/geometry-combined.frag
+++ b/Shaders/HDR/geometry-combined.frag
@@ -10,6 +10,7 @@ in mat3 TBN;
uniform sampler2D color_tex;
uniform sampler2D normal_tex;
uniform int normalmap_enabled;
+uniform int normalmap_dds;
uniform float normalmap_tiling;
const float DEFAULT_COMBINED_METALNESS = 0.0;
@@ -26,6 +27,9 @@ void main()
vec3 normal = vec3(0.5, 0.5, 1.0);
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;
}
normal = normalize(TBN * normal);
gbuffer1 = encodeNormal(normal);
diff --git a/Shaders/HDR/geometry-transparent.frag b/Shaders/HDR/geometry-transparent.frag
new file mode 100644
index 000000000..5523b5b45
--- /dev/null
+++ b/Shaders/HDR/geometry-transparent.frag
@@ -0,0 +1,94 @@
+#version 330 core
+
+out vec4 fragColor;
+
+in vec3 normalVS;
+in vec2 texCoord;
+in vec4 materialColor;
+in vec3 ecPos;
+
+uniform sampler2D color_tex;
+uniform float minimum_alpha = 0.0;
+
+uniform mat4 osg_ViewMatrixInverse;
+uniform vec4 fg_Viewport;
+uniform vec3 fg_SunDirection;
+
+const float DEFAULT_TRANSPARENT_ROUGHNESS = 0.1;
+
+vec3 decodeSRGB(vec3 screenRGB);
+vec3 getF0Reflectance(vec3 baseColor, float metallic);
+float getShadowing(vec3 p, vec3 n, float NdotL);
+vec3 evaluateLight(
+ vec3 baseColor,
+ float metallic,
+ float roughness,
+ float clearcoat,
+ float clearcoatRoughness,
+ vec3 f0,
+ vec3 intensity,
+ float occlusion,
+ vec3 n,
+ vec3 l,
+ vec3 v,
+ float NdotL,
+ float NdotV);
+vec3 evaluateIBL(
+ vec3 baseColor,
+ float metallic,
+ float roughness,
+ vec3 f0,
+ float occlusion,
+ vec3 nWorldSpace,
+ float NdotV,
+ vec3 reflected);
+vec3 addAerialPerspective(vec3 color, vec2 coord, float depth);
+vec3 getSunIntensity();
+
+void main()
+{
+ vec4 baseColorTexel = texture(color_tex, texCoord);
+ vec3 baseColor = decodeSRGB(baseColorTexel.rgb) * materialColor.rgb;
+ // HACK: Force a minimum value to stay compatible with glass.eff
+ float alpha = max(materialColor.a * baseColorTexel.a, minimum_alpha);
+
+ vec3 n = normalize(normalVS);
+ vec3 v = normalize(-ecPos);
+ vec3 l = fg_SunDirection;
+
+ float NdotL = dot(n, l);
+ float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);
+
+ vec3 f0 = getF0Reflectance(baseColor.rgb, 0.0);
+
+ vec3 sunIlluminance = getSunIntensity() * clamp(NdotL, 0.0, 1.0);
+ float shadowFactor = getShadowing(ecPos, n, NdotL);
+
+ vec3 color = evaluateLight(baseColor,
+ 0.0,
+ DEFAULT_TRANSPARENT_ROUGHNESS,
+ 0.0,
+ 0.0,
+ f0,
+ sunIlluminance,
+ shadowFactor,
+ n, l, v,
+ NdotL, NdotV);
+
+ vec3 worldNormal = (osg_ViewMatrixInverse * vec4(n, 0.0)).xyz;
+ vec3 worldReflected = (osg_ViewMatrixInverse * vec4(reflect(-v, n), 0.0)).xyz;
+
+ color += evaluateIBL(baseColor,
+ 0.0,
+ DEFAULT_TRANSPARENT_ROUGHNESS,
+ f0,
+ 1.0,
+ worldNormal,
+ NdotV,
+ worldReflected);
+
+ vec2 coord = (gl_FragCoord.xy - fg_Viewport.xy) / fg_Viewport.zw;
+ color = addAerialPerspective(color, coord, length(ecPos));
+
+ fragColor = vec4(color, alpha);
+}
diff --git a/Shaders/HDR/geometry-transparent.vert b/Shaders/HDR/geometry-transparent.vert
new file mode 100644
index 000000000..b39d617d3
--- /dev/null
+++ b/Shaders/HDR/geometry-transparent.vert
@@ -0,0 +1,44 @@
+#version 330 core
+
+#define MODE_OFF 0
+#define MODE_DIFFUSE 1
+#define MODE_AMBIENT_AND_DIFFUSE 2
+
+layout(location = 0) in vec4 pos;
+layout(location = 1) in vec3 normal;
+layout(location = 2) in vec4 vertexColor;
+layout(location = 3) in vec4 multiTexCoord0;
+
+out vec3 normalVS;
+out vec2 texCoord;
+out vec4 materialColor;
+out vec3 ecPos;
+
+uniform int color_mode;
+uniform vec4 material_diffuse;
+
+uniform mat4 osg_ModelViewMatrix;
+uniform mat4 osg_ModelViewProjectionMatrix;
+uniform mat3 osg_NormalMatrix;
+
+void main()
+{
+ gl_Position = osg_ModelViewProjectionMatrix * pos;
+ normalVS = normalize(osg_NormalMatrix * normal);
+ texCoord = multiTexCoord0.st;
+ ecPos = (osg_ModelViewMatrix * pos).xyz;
+
+ // Legacy material handling
+ if (color_mode == MODE_DIFFUSE)
+ materialColor = vertexColor;
+ else if (color_mode == MODE_AMBIENT_AND_DIFFUSE)
+ materialColor = vertexColor;
+ else
+ materialColor = material_diffuse;
+ // Super hack: if diffuse material alpha is less than 1, assume a
+ // transparency animation is at work
+ if (material_diffuse.a < 1.0)
+ materialColor.a = material_diffuse.a;
+ else
+ materialColor.a = vertexColor.a;
+}
diff --git a/Shaders/HDR/geometry.frag b/Shaders/HDR/geometry.frag
index 9ec86494f..211ddf04f 100644
--- a/Shaders/HDR/geometry.frag
+++ b/Shaders/HDR/geometry.frag
@@ -6,6 +6,7 @@ layout(location = 2) out vec4 gbuffer2;
in vec3 normalVS;
in vec2 texCoord;
+in vec4 materialColor;
uniform sampler2D color_tex;
@@ -17,7 +18,9 @@ vec3 decodeSRGB(vec3 screenRGB);
void main()
{
- gbuffer0.rgb = decodeSRGB(texture(color_tex, texCoord).rgb);
+ vec3 texel = texture(color_tex, texCoord).rgb;
+ vec3 color = decodeSRGB(texel) * materialColor.rgb; // Ignore transparency
+ gbuffer0.rgb = color;
gbuffer0.a = 1.0;
gbuffer1 = encodeNormal(normalVS);
gbuffer2 = vec4(DEFAULT_METALNESS,
diff --git a/Shaders/HDR/geometry.vert b/Shaders/HDR/geometry.vert
index 232eb73fe..6284fd441 100644
--- a/Shaders/HDR/geometry.vert
+++ b/Shaders/HDR/geometry.vert
@@ -1,11 +1,20 @@
#version 330 core
+#define MODE_OFF 0
+#define MODE_DIFFUSE 1
+#define MODE_AMBIENT_AND_DIFFUSE 2
+
layout(location = 0) in vec4 pos;
layout(location = 1) in vec3 normal;
+layout(location = 2) in vec4 vertexColor;
layout(location = 3) in vec4 multiTexCoord0;
out vec3 normalVS;
out vec2 texCoord;
+out vec4 materialColor;
+
+uniform int color_mode;
+uniform vec4 material_diffuse;
uniform mat4 osg_ModelViewProjectionMatrix;
uniform mat3 osg_NormalMatrix;
@@ -15,4 +24,12 @@ void main()
gl_Position = osg_ModelViewProjectionMatrix * pos;
normalVS = normalize(osg_NormalMatrix * normal);
texCoord = multiTexCoord0.st;
+
+ // Legacy material handling
+ if (color_mode == MODE_DIFFUSE)
+ materialColor = vertexColor;
+ else if (color_mode == MODE_AMBIENT_AND_DIFFUSE)
+ materialColor = vertexColor;
+ else
+ materialColor = material_diffuse;
}
diff --git a/Shaders/HDR/lighting-include.frag b/Shaders/HDR/lighting-include.frag
index 816f2120a..a9da53bd5 100644
--- a/Shaders/HDR/lighting-include.frag
+++ b/Shaders/HDR/lighting-include.frag
@@ -149,9 +149,9 @@ float getShadowing(vec3 p, vec3 n, float NdotL)
vec4 lightSpacePos[4];
lightSpacePos[0] = getLightSpacePosition(p, n, NdotL, 0.05, fg_LightMatrix_csm0);
- lightSpacePos[1] = getLightSpacePosition(p, n, NdotL, 0.2, fg_LightMatrix_csm1);
- lightSpacePos[2] = getLightSpacePosition(p, n, NdotL, 1.0, fg_LightMatrix_csm2);
- lightSpacePos[3] = getLightSpacePosition(p, n, NdotL, 5.0, fg_LightMatrix_csm3);
+ lightSpacePos[1] = getLightSpacePosition(p, n, NdotL, 0.1, fg_LightMatrix_csm1);
+ lightSpacePos[2] = getLightSpacePosition(p, n, NdotL, 0.5, fg_LightMatrix_csm2);
+ lightSpacePos[3] = getLightSpacePosition(p, n, NdotL, 1.0, fg_LightMatrix_csm3);
for (int i = 0; i < 4; ++i) {
// Map-based cascade selection