Skip to content

Commit 8ba6574

Browse files
authored
Merge pull request jMonkeyEngine#2352 from yaRnMcDonuts/master
Updates, features, and refactoring for Modular PBR Shaders (redo PR)
2 parents 03c26a8 + f25d69a commit 8ba6574

File tree

12 files changed

+900
-1445
lines changed

12 files changed

+900
-1445
lines changed

jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag

+52-347
Large diffs are not rendered by default.

jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.j3md

+32
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,29 @@ MaterialDef PBR Lighting {
132132
Boolean UseVertexColor
133133

134134
Boolean BackfaceShadows : false
135+
136+
Boolean UseFog
137+
Color FogColor
138+
Vector2 LinearFog
139+
Float ExpFog
140+
Float ExpSqFog
141+
142+
Texture2D SunLightExposureMap
143+
Boolean UseVertexColorsAsSunIntensity
144+
Float StaticSunIntensity
145+
Boolean BrightenIndoorShadows //should be set true when shadows are enabled, in order to prevent areas with low SunExposure from being way too dark when shadows are cast
146+
147+
// debug the final value of the selected layer as a color output
148+
Int DebugValuesMode
149+
// Layers:
150+
// 0 - albedo (un-shaded)
151+
// 1 - normals
152+
// 2 - roughness
153+
// 3 - metallic
154+
// 4 - ao
155+
// 5 - emissive
156+
// 6 - exposure
157+
// 7 - alpha
135158
}
136159

137160
Technique {
@@ -182,6 +205,15 @@ MaterialDef PBR Lighting {
182205
NUM_MORPH_TARGETS: NumberOfMorphTargets
183206
NUM_TARGETS_BUFFERS: NumberOfTargetsBuffers
184207
HORIZON_FADE: HorizonFade
208+
EXPOSUREMAP : SunLightExposureMap
209+
USE_VERTEX_COLORS_AS_SUN_INTENSITY : UseVertexColorsAsSunIntensity
210+
STATIC_SUN_INTENSITY : StaticSunIntensity
211+
BRIGHTEN_INDOOR_SHADOWS : BrightenIndoorShadows
212+
DEBUG_VALUES_MODE : DebugValuesMode
213+
USE_FOG : UseFog
214+
FOG_LINEAR : LinearFog
215+
FOG_EXP : ExpFog
216+
FOG_EXPSQ : ExpSqFog
185217
}
186218
}
187219

jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.vert

+39-19
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
#import "Common/ShaderLib/MorphAnim.glsllib"
55

66
uniform vec4 m_BaseColor;
7+
78
uniform vec4 g_AmbientLightColor;
89
varying vec2 texCoord;
910

1011
#ifdef SEPARATE_TEXCOORD
11-
varying vec2 texCoord2;
12-
attribute vec2 inTexCoord2;
12+
varying vec2 texCoord2;
13+
attribute vec2 inTexCoord2;
1314
#endif
1415

1516
varying vec4 Color;
@@ -18,25 +19,41 @@ attribute vec3 inPosition;
1819
attribute vec2 inTexCoord;
1920
attribute vec3 inNormal;
2021

21-
#ifdef VERTEX_COLOR
22-
attribute vec4 inColor;
22+
#if defined (VERTEX_COLOR) || defined(USE_VERTEX_COLORS_AS_SUN_INTENSITY)
23+
attribute vec4 inColor;
24+
#endif
25+
26+
#if defined(USE_VERTEX_COLORS_AS_SUN_INTENSITY)
27+
varying vec4 vertColors;
2328
#endif
2429

2530
varying vec3 wNormal;
2631
varying vec3 wPosition;
27-
#if defined(NORMALMAP) || defined(PARALLAXMAP)
28-
attribute vec4 inTangent;
29-
varying vec4 wTangent;
32+
33+
varying vec4 lPosition;
34+
35+
attribute vec4 inTangent;
36+
varying vec4 wTangent;
37+
38+
#ifdef USE_FOG
39+
varying float fogDistance;
40+
uniform vec3 g_CameraPosition;
3041
#endif
3142

32-
void main(){
43+
void main(){
44+
3345
vec4 modelSpacePos = vec4(inPosition, 1.0);
3446
vec3 modelSpaceNorm = inNormal;
35-
36-
#if ( defined(NORMALMAP) || defined(PARALLAXMAP)) && !defined(VERTEX_LIGHTING)
37-
vec3 modelSpaceTan = inTangent.xyz;
47+
vec3 modelSpaceTan = inTangent.xyz;
48+
49+
lPosition = modelSpacePos;
50+
51+
52+
#ifdef USE_VERTEX_COLORS_AS_SUN_INTENSITY
53+
vertColors = inColor;
3854
#endif
3955

56+
4057
#ifdef NUM_MORPH_TARGETS
4158
#if defined(NORMALMAP) && !defined(VERTEX_LIGHTING)
4259
Morph_Compute(modelSpacePos, modelSpaceNorm, modelSpaceTan);
@@ -47,9 +64,9 @@ void main(){
4764

4865
#ifdef NUM_BONES
4966
#if defined(NORMALMAP) && !defined(VERTEX_LIGHTING)
50-
Skinning_Compute(modelSpacePos, modelSpaceNorm, modelSpaceTan);
67+
Skinning_Compute(modelSpacePos, modelSpaceNorm, modelSpaceTan);
5168
#else
52-
Skinning_Compute(modelSpacePos, modelSpaceNorm);
69+
Skinning_Compute(modelSpacePos, modelSpaceNorm);
5370
#endif
5471
#endif
5572

@@ -59,16 +76,19 @@ void main(){
5976
texCoord2 = inTexCoord2;
6077
#endif
6178

62-
wPosition = TransformWorld(modelSpacePos).xyz;
79+
wPosition = (g_WorldMatrix * vec4(inPosition, 1.0)).xyz;
6380
wNormal = TransformWorldNormal(modelSpaceNorm);
64-
65-
#if defined(NORMALMAP) || defined(PARALLAXMAP)
66-
wTangent = vec4(TransformWorldNormal(modelSpaceTan),inTangent.w);
67-
#endif
81+
82+
wTangent = vec4(TransformWorldNormal(modelSpaceTan),inTangent.w);
6883

6984
Color = m_BaseColor;
7085

71-
#ifdef VERTEX_COLOR
86+
#ifdef VERTEX_COLOR
7287
Color *= inColor;
7388
#endif
89+
90+
#ifdef USE_FOG
91+
fogDistance = distance(g_CameraPosition, (g_WorldMatrix * modelSpacePos).xyz);
92+
#endif
93+
7494
}

jme3-core/src/main/resources/Common/MatDefs/Light/modular/PBRLighting.frag

-73
This file was deleted.

0 commit comments

Comments
 (0)