Skip to content

Commit

Permalink
Merge pull request #2352 from yaRnMcDonuts/master
Browse files Browse the repository at this point in the history
Updates, features, and refactoring for Modular PBR Shaders (redo PR)
  • Loading branch information
yaRnMcDonuts authored Feb 1, 2025
2 parents 03c26a8 + f25d69a commit 8ba6574
Show file tree
Hide file tree
Showing 12 changed files with 900 additions and 1,445 deletions.
399 changes: 52 additions & 347 deletions jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.j3md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,29 @@ MaterialDef PBR Lighting {
Boolean UseVertexColor

Boolean BackfaceShadows : false

Boolean UseFog
Color FogColor
Vector2 LinearFog
Float ExpFog
Float ExpSqFog

Texture2D SunLightExposureMap
Boolean UseVertexColorsAsSunIntensity
Float StaticSunIntensity
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

// debug the final value of the selected layer as a color output
Int DebugValuesMode
// Layers:
// 0 - albedo (un-shaded)
// 1 - normals
// 2 - roughness
// 3 - metallic
// 4 - ao
// 5 - emissive
// 6 - exposure
// 7 - alpha
}

Technique {
Expand Down Expand Up @@ -182,6 +205,15 @@ MaterialDef PBR Lighting {
NUM_MORPH_TARGETS: NumberOfMorphTargets
NUM_TARGETS_BUFFERS: NumberOfTargetsBuffers
HORIZON_FADE: HorizonFade
EXPOSUREMAP : SunLightExposureMap
USE_VERTEX_COLORS_AS_SUN_INTENSITY : UseVertexColorsAsSunIntensity
STATIC_SUN_INTENSITY : StaticSunIntensity
BRIGHTEN_INDOOR_SHADOWS : BrightenIndoorShadows
DEBUG_VALUES_MODE : DebugValuesMode
USE_FOG : UseFog
FOG_LINEAR : LinearFog
FOG_EXP : ExpFog
FOG_EXPSQ : ExpSqFog
}
}

Expand Down
58 changes: 39 additions & 19 deletions jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.vert
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
#import "Common/ShaderLib/MorphAnim.glsllib"

uniform vec4 m_BaseColor;

uniform vec4 g_AmbientLightColor;
varying vec2 texCoord;

#ifdef SEPARATE_TEXCOORD
varying vec2 texCoord2;
attribute vec2 inTexCoord2;
varying vec2 texCoord2;
attribute vec2 inTexCoord2;
#endif

varying vec4 Color;
Expand All @@ -18,25 +19,41 @@ attribute vec3 inPosition;
attribute vec2 inTexCoord;
attribute vec3 inNormal;

#ifdef VERTEX_COLOR
attribute vec4 inColor;
#if defined (VERTEX_COLOR) || defined(USE_VERTEX_COLORS_AS_SUN_INTENSITY)
attribute vec4 inColor;
#endif

#if defined(USE_VERTEX_COLORS_AS_SUN_INTENSITY)
varying vec4 vertColors;
#endif

varying vec3 wNormal;
varying vec3 wPosition;
#if defined(NORMALMAP) || defined(PARALLAXMAP)
attribute vec4 inTangent;
varying vec4 wTangent;

varying vec4 lPosition;

attribute vec4 inTangent;
varying vec4 wTangent;

#ifdef USE_FOG
varying float fogDistance;
uniform vec3 g_CameraPosition;
#endif

void main(){
void main(){

vec4 modelSpacePos = vec4(inPosition, 1.0);
vec3 modelSpaceNorm = inNormal;

#if ( defined(NORMALMAP) || defined(PARALLAXMAP)) && !defined(VERTEX_LIGHTING)
vec3 modelSpaceTan = inTangent.xyz;
vec3 modelSpaceTan = inTangent.xyz;

lPosition = modelSpacePos;


#ifdef USE_VERTEX_COLORS_AS_SUN_INTENSITY
vertColors = inColor;
#endif


#ifdef NUM_MORPH_TARGETS
#if defined(NORMALMAP) && !defined(VERTEX_LIGHTING)
Morph_Compute(modelSpacePos, modelSpaceNorm, modelSpaceTan);
Expand All @@ -47,9 +64,9 @@ void main(){

#ifdef NUM_BONES
#if defined(NORMALMAP) && !defined(VERTEX_LIGHTING)
Skinning_Compute(modelSpacePos, modelSpaceNorm, modelSpaceTan);
Skinning_Compute(modelSpacePos, modelSpaceNorm, modelSpaceTan);
#else
Skinning_Compute(modelSpacePos, modelSpaceNorm);
Skinning_Compute(modelSpacePos, modelSpaceNorm);
#endif
#endif

Expand All @@ -59,16 +76,19 @@ void main(){
texCoord2 = inTexCoord2;
#endif

wPosition = TransformWorld(modelSpacePos).xyz;
wPosition = (g_WorldMatrix * vec4(inPosition, 1.0)).xyz;
wNormal = TransformWorldNormal(modelSpaceNorm);

#if defined(NORMALMAP) || defined(PARALLAXMAP)
wTangent = vec4(TransformWorldNormal(modelSpaceTan),inTangent.w);
#endif

wTangent = vec4(TransformWorldNormal(modelSpaceTan),inTangent.w);

Color = m_BaseColor;

#ifdef VERTEX_COLOR
#ifdef VERTEX_COLOR
Color *= inColor;
#endif

#ifdef USE_FOG
fogDistance = distance(g_CameraPosition, (g_WorldMatrix * modelSpacePos).xyz);
#endif

}

This file was deleted.

Loading

0 comments on commit 8ba6574

Please sign in to comment.