Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finish Modularizing PBRTerrainUtils.glsllb #2377

Merged
merged 27 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
06b7b1d
Finish modularizing PBRTerrain.j3md
yaRnMcDonuts Feb 11, 2025
acaa45a
Delete jme3-terrain/src/main/resources/Common/MatDefs/Terrain/PBRTerr…
yaRnMcDonuts Feb 11, 2025
ca07eb4
Update AdvancedPBRTerrain.frag to work with both MatDefs
yaRnMcDonuts Feb 11, 2025
8cc262b
Update AdvancedPBRTerrain.frag
yaRnMcDonuts Feb 11, 2025
d9ae33b
Update AdvancedPBRTerrain.j3md
yaRnMcDonuts Feb 11, 2025
b52a678
Update AdvancedPBRTerrain.j3md
yaRnMcDonuts Feb 11, 2025
1f28da6
Update AdvancedPBRTerrain.j3md
yaRnMcDonuts Feb 11, 2025
e5a0f28
Update PBRTerrainUtils.glsllib
yaRnMcDonuts Feb 20, 2025
db5b9f0
Change trigger for USE_TEXTURE_ARRAYS define
yaRnMcDonuts Feb 24, 2025
5cf3308
Update PBRTerrain.j3md
yaRnMcDonuts Mar 2, 2025
fed3972
Update AdvancedPBRTerrain.j3md
yaRnMcDonuts Mar 2, 2025
2a9d258
Update PBRTerrain.j3md
yaRnMcDonuts Mar 2, 2025
d2967f9
Update PBRTerrain.j3md
yaRnMcDonuts Mar 2, 2025
9d0e74e
Update AdvancedPBRTerrain.frag
yaRnMcDonuts Mar 3, 2025
8a9253b
Update PBRTerrain.j3md
yaRnMcDonuts Mar 3, 2025
232289d
Update PBRTerrainUtils.glsllib
yaRnMcDonuts Mar 3, 2025
14fc28d
Update PBRTerrainUtils.glsllib
yaRnMcDonuts Mar 3, 2025
4748826
Merge branch 'master' into yaRnMcDonuts-patch-9
yaRnMcDonuts Mar 3, 2025
d602311
Update PBRTerrainUtils.glsllib
yaRnMcDonuts Mar 3, 2025
50ece7c
Add NORMAL_TYPE to PBRTerrainUtils.glsllib
yaRnMcDonuts Mar 3, 2025
2285370
Update PBRTerrainUtils.glsllib
yaRnMcDonuts Mar 3, 2025
885f8f7
NORMAL_TYPE support for TriPlanarUtils.glsllib
yaRnMcDonuts Mar 3, 2025
f3c79f7
add NORMAL_TYPE define to AdvancedPBRTerrain.j3md
yaRnMcDonuts Mar 3, 2025
7ebab5f
add NORMAL_TYPE define to PBRTerrain.j3md
yaRnMcDonuts Mar 3, 2025
8f1a0c8
Add emissive vars to PBRTerrain.j3md
yaRnMcDonuts Mar 3, 2025
24f6bb2
Update PBRTerrainUtils.glsllib
yaRnMcDonuts Mar 4, 2025
3c5eb5c
Update TriPlanarUtils.glsllib
yaRnMcDonuts Mar 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#ifndef __TRIPLANAR_UTILS_MODULE__
#define __TRIPLANAR_UTILS_MODULE__

#ifndef NORMAL_TYPE
#define NORMAL_TYPE -1.0
#endif

vec3 triBlending;

void TriPlanarUtils_calculateBlending(vec3 geometryNormal){
Expand Down Expand Up @@ -39,9 +43,9 @@
vec4 col2 = texture2D( map, coords.xz * scale);
vec4 col3 = texture2D( map, coords.xy * scale);

col1.xyz = col1.xyz * vec3(2.0) - vec3(1.0);
col2.xyz = col2.xyz * vec3(2.0) - vec3(1.0);
col3.xyz = col3.xyz * vec3(2.0) - vec3(1.0);
col1.xyz = col1.xyz * vec3(2.0, NORMAL_TYPE * 2.0, 2.0) - vec3(1.0, NORMAL_TYPE * 1.0, 1.0);
col2.xyz = col2.xyz * vec3(2.0, NORMAL_TYPE * 2.0, 2.0) - vec3(1.0, NORMAL_TYPE * 1.0, 1.0);
col3.xyz = col3.xyz * vec3(2.0, NORMAL_TYPE * 2.0, 2.0) - vec3(1.0, NORMAL_TYPE * 1.0, 1.0);

// blend the results of the 3 planar projections.
vec4 tex = normalize(col1 * triBlending.x + col2 * triBlending.y + col3 * triBlending.z);
Expand All @@ -51,16 +55,16 @@

// triplanar blend for Normal maps in a TextureArray:
vec4 getTriPlanarNormalBlendFromTexArray(in vec3 coords, in int idInTexArray, in float scale, in sampler2DArray texArray) {
vec4 col1 = texture2DArray( texArray, vec3((coords.yz * scale), idInTexArray ) );
vec4 col2 = texture2DArray( texArray, vec3((coords.xz * scale), idInTexArray ) );
vec4 col3 = texture2DArray( texArray, vec3((coords.xy * scale), idInTexArray ) );
vec4 col1 = texture2DArray( texArray, vec3((coords.yz * scale), idInTexArray ));
vec4 col2 = texture2DArray( texArray, vec3((coords.xz * scale), idInTexArray ));
vec4 col3 = texture2DArray( texArray, vec3((coords.xy * scale), idInTexArray ));

col1.xyz = col1.xyz * vec3(2.0) - vec3(1.0);
col2.xyz = col2.xyz * vec3(2.0) - vec3(1.0);
col3.xyz = col3.xyz * vec3(2.0) - vec3(1.0);
col1.xyz = col1.xyz * vec3(2.0, NORMAL_TYPE * 2.0, 2.0) - vec3(1.0, NORMAL_TYPE * 1.0, 1.0);
col2.xyz = col2.xyz * vec3(2.0, NORMAL_TYPE * 2.0, 2.0) - vec3(1.0, NORMAL_TYPE * 1.0, 1.0);
col3.xyz = col3.xyz * vec3(2.0, NORMAL_TYPE * 2.0, 2.0) - vec3(1.0, NORMAL_TYPE * 1.0, 1.0);

// blend the results of the 3 planar projections.
vec4 tex = normalize(col1 * triBlending.x + col2 * triBlending.y + col3 * triBlending.z);
vec4 tex = normalize(col1 * triBlending.x + col2 * triBlending.y + col3 * triBlending.z);

return tex;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void main(){
// read and blend up to 12 texture layers
#for i=0..12 (#ifdef ALBEDOMAP_$i $0 #endif)

PBRTerrainTextureLayer terrainTextureLayer_$i = PBRTerrainUtils_createAdvancedPBRTerrainLayer($i);
PBRTerrainTextureLayer terrainTextureLayer_$i = PBRTerrainUtils_createAdvancedPBRTerrainLayer($i, surface.geometryNormal);

#ifdef USE_FIRST_LAYER_AS_TRANSPARENCY
if($i == 0){
Expand All @@ -59,29 +59,51 @@ void main(){
}
#endif

terrainTextureLayer_$i.roughness = m_Roughness_$i;
terrainTextureLayer_$i.metallic = m_Metallic_$i;
terrainTextureLayer_$i.emission = m_EmissiveColor_$i;

#if defined(TRI_PLANAR_MAPPING) || defined(TRI_PLANAR_MAPPING_$i)
//triplanar:

PBRTerrainUtils_readTriPlanarAlbedoTexArray(ALBEDOMAP_$i, m_AlbedoMap_$i_scale, m_AlbedoTextureArray, terrainTextureLayer_$i);
#ifdef NORMALMAP_$i
PBRTerrainUtils_readTriPlanarNormalTexArray(NORMALMAP_$i, m_AlbedoMap_$i_scale, m_NormalParallaxTextureArray, terrainTextureLayer_$i);
#endif
#ifdef METALLICROUGHNESSMAP_$i
PBRTerrainUtils_readTriPlanarMetallicRoughnessAoEiTexArray(METALLICROUGHNESSMAP_$i, m_AlbedoMap_$i_scale, m_MetallicRoughnessAoEiTextureArray, terrainTextureLayer_$i);
#endif
#else
//non tri-planar:

PBRTerrainUtils_readAlbedoTexArray(ALBEDOMAP_$i, m_AlbedoMap_$i_scale, m_AlbedoTextureArray, terrainTextureLayer_$i);
#ifdef NORMALMAP_$i
PBRTerrainUtils_readNormalTexArray(NORMALMAP_$i, m_AlbedoMap_$i_scale, m_NormalParallaxTextureArray, terrainTextureLayer_$i);
#endif
#ifdef METALLICROUGHNESSMAP_$i
PBRTerrainUtils_readMetallicRoughnessAoEiTexArray(METALLICROUGHNESSMAP_$i, m_AlbedoMap_$i_scale, m_MetallicRoughnessAoEiTextureArray, terrainTextureLayer_$i);
#endif
#endif

#ifdef USE_TEXTURE_ARRAYS
#if defined(TRI_PLANAR_MAPPING) || defined(TRI_PLANAR_MAPPING_$i)
//triplanar for texture arrays:
PBRTerrainUtils_readTriPlanarAlbedoTexArray(m_AlbedoMap_$i, m_AlbedoMap_$i_scale, m_AlbedoTextureArray, terrainTextureLayer_$i);
#ifdef NORMALMAP_$i
PBRTerrainUtils_readTriPlanarNormalTexArray(m_NormalMap_$i, m_AlbedoMap_$i_scale, m_NormalParallaxTextureArray, terrainTextureLayer_$i);
#endif
#ifdef METALLICROUGHNESSMAP_$i
PBRTerrainUtils_readTriPlanarMetallicRoughnessAoEiTexArray(m_MetallicRoughnessMap_$i, m_AlbedoMap_$i_scale, m_MetallicRoughnessAoEiTextureArray, terrainTextureLayer_$i);
#endif
#else
//non tri-planar for texture arrays:
PBRTerrainUtils_readAlbedoTexArray(m_AlbedoMap_$i, m_AlbedoMap_$i_scale, m_AlbedoTextureArray, terrainTextureLayer_$i);
#ifdef NORMALMAP_$i
PBRTerrainUtils_readNormalTexArray(m_NormalMap_$i, m_AlbedoMap_$i_scale, m_NormalParallaxTextureArray, terrainTextureLayer_$i);
#endif
#ifdef METALLICROUGHNESSMAP_$i
PBRTerrainUtils_readMetallicRoughnessAoEiTexArray(m_MetallicRoughnessMap_$i, m_AlbedoMap_$i_scale, m_MetallicRoughnessAoEiTextureArray, terrainTextureLayer_$i);
#endif
#endif
#else
#if defined(TRI_PLANAR_MAPPING) || defined(TRI_PLANAR_MAPPING_$i)
//triplanar texture reads:
PBRTerrainUtils_readTriPlanarAlbedoTexture(m_AlbedoMap_$i, m_AlbedoMap_$i_scale, terrainTextureLayer_$i);
#ifdef NORMALMAP_$i
PBRTerrainUtils_readTriPlanarNormalTexture(m_NormalMap_$i, m_AlbedoMap_$i_scale, terrainTextureLayer_$i);
#endif
#ifdef METALLICROUGHNESSMAP_$i
PBRTerrainUtils_readTriPlanarMetallicRoughnessAoEiTexture(m_MetallicRoughnessMap_$i, m_AlbedoMap_$i_scale, terrainTextureLayer_$i);
#endif
#else
//non tri-planar texture reads:
PBRTerrainUtils_readAlbedoTexture(m_AlbedoMap_$i, m_AlbedoMap_$i_scale, terrainTextureLayer_$i);
#ifdef NORMALMAP_$i
PBRTerrainUtils_readNormalTexture(m_NormalMap_$i, m_AlbedoMap_$i_scale, terrainTextureLayer_$i);
#endif
#ifdef METALLICROUGHNESSMAP_$i
PBRTerrainUtils_readMetallicRoughnessAoEiTexture(m_MetallicRoughnessMap_$i, m_AlbedoMap_$i_scale, terrainTextureLayer_$i);
#endif
#endif
#endif

//CUSTOM LIB EXAMPLE: uses a custom alpha map to desaturate albedo color for a color-removal effect
#ifdef AFFLICTIONTEXTURE
Expand Down Expand Up @@ -129,14 +151,14 @@ void main(){
gl_FragColor.rgb += surface.directLightContribution;
gl_FragColor.rgb += surface.envLightContribution;
gl_FragColor.rgb += surface.emission;
gl_FragColor.a = surface.alpha;

gl_FragColor.a = surface.alpha;
#ifdef USE_FOG
gl_FragColor = MaterialFog_calculateFogColor(vec4(gl_FragColor));
#endif

//outputs the final value of the selected layer as a color for debug purposes.
#ifdef DEBUG_VALUES_MODE
gl_FragColor = PBRLightingUtils_getColorOutputForDebugMode(m_DebugValuesMode, vec4(gl_FragColor.rgba), surface);
#endif
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ MaterialDef AdvancedPBRTerrain {
Int BoundDrawBuffer

Texture2D SunLightExposureMap
Boolean UseVertexColorsAsSunIntensity //set true to make the vertex color's R channel how exposed a vertex is to the sun
Float StaticSunIntensity //used for setting the sun exposure value for a whole material
Boolean UseVertexColorsAsSunExposure //set true to make the vertex color's R channel how exposed a vertex is to the sun
Float StaticSunExposure //used for setting the sun exposure value for a whole material
//these are usually generated at run time or setup in a level editor per-geometry, so that models indoors can have the DirectionalLight dimmed accordingly.

Boolean BrightenIndoorShadows //set true if shadows are enabled and indoor areas without full sun exposure are too dark compared to when shadows are turned off in settings
Expand All @@ -16,6 +16,9 @@ MaterialDef AdvancedPBRTerrain {
TextureArray NormalParallaxTextureArray -LINEAR
TextureArray MetallicRoughnessAoEiTextureArray -LINEAR

//The type of normal map: -1.0 (DirectX), 1.0 (OpenGl)
Float NormalType : -1.0

// Specular-AA
Boolean UseSpecularAA : true
// screen space variance,Use the slider to set the strength of the geometric specular anti-aliasing effect between 0 and 1. Higher values produce a blurrier result with less aliasing.
Expand All @@ -28,7 +31,6 @@ MaterialDef AdvancedPBRTerrain {
Float AfflictionMetallicValue : 0.0
Float AfflictionEmissiveValue : 0.0 //note that this is simplified into one value, rather than 2 with power and intensity like the regular pbr values.


// affliction texture splatting & desaturation functionality
Boolean UseTriplanarAfflictionMapping

Expand All @@ -43,7 +45,6 @@ MaterialDef AdvancedPBRTerrain {

Float SplatNoiseVar


Int AfflictionMode_0 : 1
Int AfflictionMode_1 : 1
Int AfflictionMode_2 : 1
Expand Down Expand Up @@ -109,7 +110,6 @@ MaterialDef AdvancedPBRTerrain {
Int AlbedoMap_10
Int AlbedoMap_11


Float AlbedoMap_0_scale : 1
Float AlbedoMap_1_scale : 1
Float AlbedoMap_2_scale : 1
Expand All @@ -136,7 +136,6 @@ MaterialDef AdvancedPBRTerrain {
Boolean UseTriPlanarMapping_10
Boolean UseTriPlanarMapping_11


Int NormalMap_0
Int NormalMap_1
Int NormalMap_2
Expand All @@ -150,7 +149,6 @@ MaterialDef AdvancedPBRTerrain {
Int NormalMap_10
Int NormalMap_11


Int MetallicRoughnessMap_0
Int MetallicRoughnessMap_1
Int MetallicRoughnessMap_2
Expand All @@ -164,7 +162,6 @@ MaterialDef AdvancedPBRTerrain {
Int MetallicRoughnessMap_10
Int MetallicRoughnessMap_11


Float ParallaxHeight_0
Float ParallaxHeight_1
Float ParallaxHeight_2
Expand All @@ -178,13 +175,11 @@ MaterialDef AdvancedPBRTerrain {
Float ParallaxHeight_10
Float ParallaxHeight_11



//used in order to convert world coords to tex coords so afflictionTexture accurately represents the world in cases where terrain is not scaled at a 1,1,1 value
Float TileWidth : 0
Vector3 TileLocation

// debug the final value of the selected layer as a color output
// debug the final value of the selected layer as a color output
Int DebugValuesMode
// Layers:
// 0 - albedo (unshaded)
Expand All @@ -195,6 +190,7 @@ MaterialDef AdvancedPBRTerrain {
// 5 - emissive
// 6 - exposure
// 7 - alpha
// 8 - geometryNormals

// use tri-planar mapping
Boolean useTriPlanarMapping
Expand All @@ -204,13 +200,6 @@ MaterialDef AdvancedPBRTerrain {
Texture2D AlphaMap_1 -LINEAR
Texture2D AlphaMap_2 -LINEAR

Boolean UseSpecGloss
Texture2D SpecularMap
Texture2D GlossinessMap
Texture2D SpecularGlossinessMap
Color Specular : 1.0 1.0 1.0 1.0
Float Glossiness : 1.0

Vector4 ProbeData

// Prefiltered Env Map for indirect specular lighting
Expand All @@ -222,7 +211,6 @@ MaterialDef AdvancedPBRTerrain {
//integrate BRDF map for indirect Lighting
Texture2D IntegrateBRDF -LINEAR


//shadows
Int FilterMode
Boolean HardwareShadows
Expand Down Expand Up @@ -289,7 +277,6 @@ MaterialDef AdvancedPBRTerrain {
ViewProjectionMatrix
ViewMatrix
Time

}

Defines {
Expand All @@ -301,10 +288,12 @@ MaterialDef AdvancedPBRTerrain {
FOG_EXPSQ : ExpSqFog

EXPOSUREMAP : SunLightExposureMap
USE_VERTEX_COLORS_AS_SUN_EXPOSURE : UseVertexColorsAsSunIntensity
STATIC_SUN_EXPOSURE : StaticSunIntensity
USE_VERTEX_COLORS_AS_SUN_EXPOSURE : UseVertexColorsAsSunExposure
STATIC_SUN_EXPOSURE : StaticSunExposure
BRIGHTEN_INDOOR_SHADOWS : BrightenIndoorShadows

NORMAL_TYPE: NormalType

USE_FIRST_LAYER_AS_TRANSPARENCY : UseFirstLayerAsTransparency

SPECULAR_AA : UseSpecularAA
Expand All @@ -323,6 +312,8 @@ MaterialDef AdvancedPBRTerrain {
AFFLICTIONEMISSIVEMAP : SplatEmissiveMap
USE_SPLAT_NOISE : SplatNoiseVar

USE_TRIPLANAR_AFFLICTION_MAPPING : UseTriplanarAfflictionMapping

TRI_PLANAR_MAPPING : useTriPlanarMapping

ALPHAMAP : AlphaMap
Expand Down Expand Up @@ -383,10 +374,10 @@ MaterialDef AdvancedPBRTerrain {

DEBUG_VALUES_MODE : DebugValuesMode

USE_TEXTURE_ARRAYS : AlbedoTextureArray
}
}


Technique PreShadow {

VertexShader GLSL300 GLSL150 GLSL100 : Common/MatDefs/Shadow/PreShadow.vert
Expand Down
Loading