From 06b7b1d4ce1e518ff8ed0964557f180154805882 Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Tue, 11 Feb 2025 04:44:49 -0500 Subject: [PATCH 01/26] Finish modularizing PBRTerrain.j3md Previously I only modularized AdvnacedPBRTerrain.j3md But now this PR applies the same concept to PBRTerrain.j3md I ended up deleting the PBRTerrain.frag file, so now both of the terrain's .j3md files reference the same fragment shader, but the advanced version has a boolean called UseTextureArrays set to true to tell the fragment shader to read from texture arrays instead of normal textures. I also added suppor for metallicRoughnessAoEi maps in the regular PRRTerrain shader (Ao being ambient occlusion that is packed in blue channel, and Ei being emissiv intensity which gets packed in the alpha channel). You will still be limited to 16 textures without using texture arrays, and as always I'd suggest most people juts use the advanced version of the shader primarily, but atleast the option is there. --- .../src/main/resources/Common/MatDefs/Terrain/PBRTerrain.j3md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/PBRTerrain.j3md b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/PBRTerrain.j3md index 707442fafd..ea7151267a 100644 --- a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/PBRTerrain.j3md +++ b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/PBRTerrain.j3md @@ -237,7 +237,7 @@ MaterialDef PBR Terrain { LightMode SinglePassAndImageBased VertexShader GLSL300 GLSL150 GLSL130 GLSL100: Common/MatDefs/Terrain/PBRTerrain.vert - FragmentShader GLSL300 GLSL150 GLSL130 GLSL100: Common/MatDefs/Terrain/PBRTerrain.frag + FragmentShader GLSL300 GLSL150 GLSL130 GLSL100: Common/MatDefs/Terrain/AdvancedPBRTerrain.frag WorldParameters { WorldViewProjectionMatrix From acaa45aacf384e8f7ed3ce6841628db08b4fa3e0 Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Tue, 11 Feb 2025 04:53:04 -0500 Subject: [PATCH 02/26] Delete jme3-terrain/src/main/resources/Common/MatDefs/Terrain/PBRTerrain.frag --- .../Common/MatDefs/Terrain/PBRTerrain.frag | 601 ------------------ 1 file changed, 601 deletions(-) delete mode 100644 jme3-terrain/src/main/resources/Common/MatDefs/Terrain/PBRTerrain.frag diff --git a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/PBRTerrain.frag b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/PBRTerrain.frag deleted file mode 100644 index b3705383c3..0000000000 --- a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/PBRTerrain.frag +++ /dev/null @@ -1,601 +0,0 @@ -#import "Common/ShaderLib/GLSLCompat.glsllib" -#import "Common/ShaderLib/PBR.glsllib" -#import "Common/ShaderLib/Parallax.glsllib" -#import "Common/ShaderLib/Lighting.glsllib" -#import "Common/MatDefs/Terrain/AfflictionLib.glsllib" - -varying vec3 wPosition; -varying vec3 vNormal; -varying vec2 texCoord; -uniform vec3 g_CameraPosition; -varying vec3 vPosition; -varying vec3 vnPosition; -varying vec3 vViewDir; -varying vec4 vLightDir; -varying vec4 vnLightDir; -varying vec3 lightVec; -varying vec3 inNormal; -varying vec3 wNormal; - -// Specular-AA -#ifdef SPECULAR_AA_SCREEN_SPACE_VARIANCE - uniform float m_SpecularAASigma; -#endif -#ifdef SPECULAR_AA_THRESHOLD - uniform float m_SpecularAAKappa; -#endif - -#ifdef DEBUG_VALUES_MODE - uniform int m_DebugValuesMode; -#endif - -uniform vec4 g_LightData[NB_LIGHTS]; -uniform vec4 g_AmbientLightColor; - -#if NB_PROBES >= 1 - uniform samplerCube g_PrefEnvMap; - uniform vec3 g_ShCoeffs[9]; - uniform mat4 g_LightProbeData; -#endif -#if NB_PROBES >= 2 - uniform samplerCube g_PrefEnvMap2; - uniform vec3 g_ShCoeffs2[9]; - uniform mat4 g_LightProbeData2; -#endif -#if NB_PROBES == 3 - uniform samplerCube g_PrefEnvMap3; - uniform vec3 g_ShCoeffs3[9]; - uniform mat4 g_LightProbeData3; -#endif - -#ifdef TRI_PLANAR_MAPPING - varying vec4 wVertex; -#endif - -//texture-slot params for 12 unique texture slots (0-11) : -#for i=0..12 ( $0 ) - uniform int m_AfflictionMode_$i; - uniform float m_Roughness_$i; - uniform float m_Metallic_$i; - - #ifdef ALBEDOMAP_$i - uniform sampler2D m_AlbedoMap_$i; - #endif - #ifdef ALBEDOMAP_$i_SCALE - uniform float m_AlbedoMap_$i_scale; - #endif - #ifdef NORMALMAP_$i - uniform sampler2D m_NormalMap_$i; - #endif -#endfor - -//3 alpha maps : -#ifdef ALPHAMAP - uniform sampler2D m_AlphaMap; -#endif -#ifdef ALPHAMAP_1 - uniform sampler2D m_AlphaMap_1; -#endif -#ifdef ALPHAMAP_2 - uniform sampler2D m_AlphaMap_2; -#endif - -#ifdef DISCARD_ALPHA - uniform float m_AlphaDiscardThreshold; -#endif - -//fog vars for basic fog : -#ifdef USE_FOG -#import "Common/ShaderLib/MaterialFog.glsllib" - uniform vec4 m_FogColor; - float fogDistance; - - uniform vec2 m_LinearFog; -#endif -#ifdef FOG_EXP - uniform float m_ExpFog; -#endif -#ifdef FOG_EXPSQ - uniform float m_ExpSqFog; -#endif - -//sun intensity is a secondary AO value that can be painted per-vertex in the red channel of the -// vertex colors, or it can be set as a static value for an entire material with the StaticSunIntensity float param -#if defined(USE_VERTEX_COLORS_AS_SUN_INTENSITY) - varying vec4 vertColors; -#endif - -#ifdef STATIC_SUN_INTENSITY - uniform float m_StaticSunIntensity; -#endif -//sun intensity AO value is only applied to the directional light, not to point lights, so it is important to track if the -//sun is more/less bright than the brightest point light for each fragment to determine how the light probe's ambient light should be scaled later on in light calculation code -float brightestPointLight = 0.0; - -//optional affliction paramaters that use the AfflictionAlphaMap's green channel for splatting m_SplatAlbedoMap and the red channel for splatting desaturation : -#ifdef AFFLICTIONTEXTURE - uniform sampler2D m_AfflictionAlphaMap; -#endif -#ifdef USE_SPLAT_NOISE - uniform float m_SplatNoiseVar; -#endif -//only defined for non-terrain geoemtries and terrains that are not positioned nor sized in correlation to the 2d array of AfflictionAlphaMaps used for splatting accross large tile based scenes in a grid -#ifdef TILELOCATION - uniform float m_TileWidth; - uniform vec3 m_TileLocation; -#endif -#ifdef AFFLICTIONALBEDOMAP - uniform sampler2D m_SplatAlbedoMap; -#endif -#ifdef AFFLICTIONNORMALMAP - uniform sampler2D m_SplatNormalMap; -#endif -#ifdef AFFLICTIONROUGHNESSMETALLICMAP - uniform sampler2D m_SplatRoughnessMetallicMap; -#endif -#ifdef AFFLICTIONEMISSIVEMAP - uniform sampler2D m_SplatEmissiveMap; -#endif - -uniform int m_AfflictionSplatScale; -uniform float m_AfflictionRoughnessValue; -uniform float m_AfflictionMetallicValue; -uniform float m_AfflictionEmissiveValue; -uniform vec4 m_AfflictionEmissiveColor; - -vec4 afflictionVector; -float noiseHash; -float livelinessValue; -float afflictionValue; -int afflictionMode = 1; - -//general temp vars : -vec4 tempAlbedo, tempNormal, tempEmissiveColor; -float tempParallax, tempMetallic, tempRoughness, tempAo, tempEmissiveIntensity; - -vec3 viewDir; -vec2 coord; -vec4 albedo = vec4(1.0); -vec3 normal = vec3(0.5,0.5,1); -vec3 norm; -float Metallic; -float Roughness; -float packedAoValue = 1.0; -vec4 emissive; -float emissiveIntensity = 1.0; -float indoorSunLightExposure = 1.0; - -vec4 packedMetallicRoughnessAoEiVec; -vec4 packedNormalParallaxVec; - -void main(){ - - #ifdef USE_FOG - fogDistance = distance(g_CameraPosition, wPosition.xyz); - #endif - - indoorSunLightExposure = 1.0; - - viewDir = normalize(g_CameraPosition - wPosition); - - norm = normalize(wNormal); - normal = norm; - - afflictionVector = vec4(1.0, 0.0, 1.0, 0.0); //r channel is sturation, g channel is affliction splat texture intensity, b and a unused (might use b channel for wetness eventually) - - #ifdef AFFLICTIONTEXTURE - - #ifdef TILELOCATION - //subterrains that are not centred in tile or equal to tile width in total size need to have m_TileWidth pre-set. (tileWidth is the x,z dimesnions that the AfflictionAlphaMap represents) - vec2 tileCoords; - float xPos, zPos; - - vec3 locInTile = (wPosition - m_TileLocation); - - locInTile += vec3(m_TileWidth/2, 0, m_TileWidth/2); - - xPos = (locInTile.x / m_TileWidth); - zPos = 1 - (locInTile.z / m_TileWidth); - - tileCoords = vec2(xPos, zPos); - - afflictionVector = texture2D(m_AfflictionAlphaMap, tileCoords).rgba; - #else - // ..othrewise when terrain size matches tileWidth and location matches tileLocation, the terrain's texCoords can be used for simple texel fetching of the AfflictionAlphaMap - afflictionVector = texture2D(m_AfflictionAlphaMap, texCoord.xy).rgba; - #endif - #endif - - livelinessValue = afflictionVector.r; - afflictionValue = afflictionVector.g; - - #ifdef ALBEDOMAP_0 - #ifdef ALPHAMAP - - vec4 alphaBlend; - vec4 alphaBlend_0, alphaBlend_1, alphaBlend_2; - int texChannelForAlphaBlending; - - alphaBlend_0 = texture2D( m_AlphaMap, texCoord.xy ); - - #ifdef ALPHAMAP_1 - alphaBlend_1 = texture2D( m_AlphaMap_1, texCoord.xy ); - #endif - #ifdef ALPHAMAP_2 - alphaBlend_2 = texture2D( m_AlphaMap_2, texCoord.xy ); - #endif - - vec2 texSlotCoords; - - float finalAlphaBlendForLayer = 1.0; - - vec3 blending = abs( norm ); - blending = (blending -0.2) * 0.7; - blending = normalize(max(blending, 0.00001)); // Force weights to sum to 1.0 (very important!) - float b = (blending.x + blending.y + blending.z); - blending /= vec3(b, b, b); - - #for i=0..12 (#ifdef ALBEDOMAP_$i $0 #endif) - - //assign texture slot's blending from index's correct alpha map - if($i <= 3){ - alphaBlend = alphaBlend_0; - }else if($i <= 7){ - alphaBlend = alphaBlend_1; - }else if($i <= 11){ - alphaBlend = alphaBlend_2; - } - - texChannelForAlphaBlending = int(mod(float($i), 4.0)); //pick the correct channel (r g b or a) based on the layer's index - switch(texChannelForAlphaBlending) { - case 0: - finalAlphaBlendForLayer = alphaBlend.r; - break; - case 1: - finalAlphaBlendForLayer = alphaBlend.g; - break; - case 2: - finalAlphaBlendForLayer = alphaBlend.b; - break; - case 3: - finalAlphaBlendForLayer = alphaBlend.a; - break; - } - - afflictionMode = m_AfflictionMode_$i; - - #ifdef TRI_PLANAR_MAPPING - //tri planar - tempAlbedo = getTriPlanarBlend(wVertex, blending, m_AlbedoMap_$i, m_AlbedoMap_$i_scale); - - #ifdef NORMALMAP_$i - tempNormal.rgb = getTriPlanarBlend(wVertex, blending, m_NormalMap_$i, m_AlbedoMap_$i_scale).rgb; - tempNormal.rgb = calculateTangentsAndApplyToNormals(tempNormal.rgb, wNormal);// this gets rid of the need for pre-generating tangents for TerrainPatches, since doing so doesn't seem to work (tbnMat is always blank for terrains even with tangents pre-generated, not sure why...) - #else - tempNormal.rgb = wNormal.rgb; - #endif - #else - - // non triplanar - texSlotCoords = texCoord * m_AlbedoMap_$i_scale; - - tempAlbedo.rgb = texture2D(m_AlbedoMap_$i, texSlotCoords).rgb; - #ifdef NORMALMAP_$i - tempNormal.xyz = texture2D(m_NormalMap_$i, texSlotCoords).xyz; - tempNormal.rgb = calculateTangentsAndApplyToNormals(tempNormal.rgb, wNormal); - #else - tempNormal.rgb = wNormal.rgb; - #endif - #endif - - //note: most of these functions can be found in AfflictionLib.glslib - tempAlbedo.rgb = alterLiveliness(tempAlbedo.rgb, livelinessValue, afflictionMode); //changes saturation of albedo for this layer; does nothing if not using AfflictionAlphaMap for affliction splatting - - //mix values from this index layer to final output values based on finalAlphaBlendForLayer - albedo.rgb = mix(albedo.rgb, tempAlbedo.rgb , finalAlphaBlendForLayer); - normal.rgb = mix(normal.rgb, tempNormal.rgb, finalAlphaBlendForLayer); - Metallic = mix(Metallic, m_Metallic_$i, finalAlphaBlendForLayer); - Roughness = mix(Roughness, m_Roughness_$i, finalAlphaBlendForLayer); - - #endfor - #endif - #endif - - - float alpha = albedo.a; - #ifdef DISCARD_ALPHA - if(alpha < m_AlphaDiscardThreshold){ - discard; - } - #endif - - - //APPLY AFFLICTIONN TO THE PIXEL - #ifdef AFFLICTIONTEXTURE - vec4 afflictionAlbedo; - - float newAfflictionScale = m_AfflictionSplatScale; - vec2 newScaledCoords; - - #ifdef AFFLICTIONALBEDOMAP - #ifdef TRI_PLANAR_MAPPING - newAfflictionScale = newAfflictionScale / 256; - afflictionAlbedo = getTriPlanarBlend(wVertex, blending, m_SplatAlbedoMap , newAfflictionScale); - #else - newScaledCoords = mod(wPosition.xz / m_AfflictionSplatScale, 0.985); - afflictionAlbedo = texture2D(m_SplatAlbedoMap , newScaledCoords); - #endif - - #else - afflictionAlbedo = vec4(1.0, 1.0, 1.0, 1.0); - #endif - - vec3 afflictionNormal; - #ifdef AFFLICTIONNORMALMAP - #ifdef TRI_PLANAR_MAPPING - - afflictionNormal = getTriPlanarBlend(wVertex, blending, m_SplatNormalMap , newAfflictionScale).rgb; - - #else - afflictionNormal = texture2D(m_SplatNormalMap , newScaledCoords).rgb; - #endif - - #else - afflictionNormal = norm; - - #endif - float afflictionMetallic = m_AfflictionMetallicValue; - float afflictionRoughness = m_AfflictionRoughnessValue; - float afflictionAo = 1.0; - - - vec4 afflictionEmissive = m_AfflictionEmissiveColor; - float afflictionEmissiveIntensity = m_AfflictionEmissiveValue; - - - #ifdef AFFLICTIONROUGHNESSMETALLICMAP - vec4 metallicRoughnessAoEiVec = texture2D(m_SplatRoughnessMetallicMap, newScaledCoords); - afflictionRoughness *= metallicRoughnessAoEiVec.g; - afflictionMetallic *= metallicRoughnessAoEiVec.b; - afflictionAo = metallicRoughnessAoEiVec.r; - afflictionEmissiveIntensity *= metallicRoughnessAoEiVec.a; //important not to leave this channel all black by accident when creating the mraoei map if using affliction emissiveness - - #endif - - #ifdef AFFLICTIONEMISSIVEMAP - vec4 emissiveMapColor = texture2D(m_SplatEmissiveMap, newScaledCoords); - afflictionEmissive *= emissiveMapColor; - #endif - - float adjustedAfflictionValue = afflictionValue; - #ifdef USE_SPLAT_NOISE - noiseHash = getStaticNoiseVar0(wPosition, afflictionValue * m_SplatNoiseVar); - - adjustedAfflictionValue = getAdjustedAfflictionVar(afflictionValue); - if(afflictionValue >= 0.99){ - adjustedAfflictionValue = afflictionValue; - } - #else - noiseHash = 1.0; - #endif - - Roughness = alterAfflictionRoughness(adjustedAfflictionValue, Roughness, afflictionRoughness, noiseHash); - Metallic = alterAfflictionMetallic(adjustedAfflictionValue, Metallic, afflictionMetallic, noiseHash); - albedo = alterAfflictionColor(adjustedAfflictionValue, albedo, afflictionAlbedo, noiseHash ); - normal = alterAfflictionNormalsForTerrain(adjustedAfflictionValue, normal, afflictionNormal, noiseHash , wNormal); - emissive = alterAfflictionGlow(adjustedAfflictionValue, emissive, afflictionEmissive, noiseHash); - emissiveIntensity = alterAfflictionEmissiveIntensity(adjustedAfflictionValue, emissiveIntensity, afflictionEmissiveIntensity, noiseHash); - emissiveIntensity *= afflictionEmissive.a; - //affliction ao value blended below after specular calculation - #endif - -// spec gloss pipeline code would go here if supported, but likely will not be for terrain shaders as defines are limited and heavily used - -float specular = 0.5; -float nonMetalSpec = 0.08 * specular; -vec4 specularColor = (nonMetalSpec - nonMetalSpec * Metallic) + albedo * Metallic; -vec4 diffuseColor = albedo - albedo * Metallic; -vec3 fZero = vec3(specular); - -gl_FragColor.rgb = vec3(0.0); - -//simple ao calculation, no support for lightmaps like stock pbr shader.. (probably could add lightmap support with another texture array, but -// that would add another texture read per slot and require removing 12 other defines to make room...) - vec3 ao = vec3(packedAoValue); - - #ifdef AFFLICTIONTEXTURE - ao = alterAfflictionAo(afflictionValue, ao, vec3(afflictionAo), noiseHash); // alter the AO map for affliction values - #endif - ao.rgb = ao.rrr; - specularColor.rgb *= ao; - - #ifdef STATIC_SUN_INTENSITY - indoorSunLightExposure = m_StaticSunIntensity; //single float value to indicate percentage of - //sunlight hitting the model (only works for small models or models with 100% consistent sunlighting accross every pixel) - #endif - #ifdef USE_VERTEX_COLORS_AS_SUN_INTENSITY - indoorSunLightExposure = vertColors.r * indoorSunLightExposure; //use R channel of vertexColors for.. - #endif - // similar purpose as above... - //but uses r channel vert colors like an AO map specifically - //for sunlight (solution for scaling lighting for indoor - // and shadey/dimly lit models, especially big ones that - // span accross varying directionalLight exposure) - brightestPointLight = 0.0; - - - float ndotv = max( dot( normal, viewDir ),0.0); - #ifdef SPECULAR_AA - float sigma = 1.0; - float kappa = 0.18; - #ifdef SPECULAR_AA_SCREEN_SPACE_VARIANCE - sigma = m_SpecularAASigma; - #endif - #ifdef SPECULAR_AA_THRESHOLD - kappa = m_SpecularAAKappa; - #endif - #endif - for( int i = 0;i < NB_LIGHTS; i+=3){ - vec4 lightColor = g_LightData[i]; - vec4 lightData1 = g_LightData[i+1]; - vec4 lightDir; - vec3 lightVec; - lightComputeDir(wPosition, lightColor.w, lightData1, lightDir, lightVec); - - float fallOff = 1.0; - #if __VERSION__ >= 110 - // allow use of control flow - if(lightColor.w > 1.0){ - #endif - fallOff = computeSpotFalloff(g_LightData[i+2], lightVec); - #if __VERSION__ >= 110 - } - #endif - //point light attenuation - fallOff *= lightDir.w; - - lightDir.xyz = normalize(lightDir.xyz); - vec3 directDiffuse; - vec3 directSpecular; - - #ifdef SPECULAR_AA - float hdotv = PBR_ComputeDirectLightWithSpecularAA( - normal, lightDir.xyz, viewDir, - lightColor.rgb, fZero, Roughness, sigma, kappa, ndotv, - directDiffuse, directSpecular); - #else - float hdotv = PBR_ComputeDirectLight( - normal, lightDir.xyz, viewDir, - lightColor.rgb, fZero, Roughness, ndotv, - directDiffuse, directSpecular); - #endif - - vec3 directLighting = diffuseColor.rgb *directDiffuse + directSpecular; - - #if defined(USE_VERTEX_COLORS_AS_SUN_INTENSITY) || defined(STATIC_SUN_INTENSITY) - if(fallOff == 1.0){ - directLighting.rgb *= indoorSunLightExposure;// ... *^. to scale down how intense just the sun is (ambient and direct light are 1.0 fallOff) - - } - else{ - brightestPointLight = max(fallOff, brightestPointLight); - - } - #endif - - gl_FragColor.rgb += directLighting * fallOff; - - } - - float minVertLighting; - #ifdef BRIGHTEN_INDOOR_SHADOWS - minVertLighting = 0.0833; //brighten shadows so that caves/indoors which are naturally covered from the DL shadows are not way too dark compared to when shadows are off (mostly only necessary for naturally dark scenes, or dark areas when using the sun intensity code above) - #else - minVertLighting = 0.0533; - - #endif - - indoorSunLightExposure = max(indoorSunLightExposure, brightestPointLight); - indoorSunLightExposure = max(indoorSunLightExposure, minVertLighting); //scale the indoorSunLightExposure back up to account for the brightest point light nearby before scaling light probes by this value below - - #if NB_PROBES >= 1 - vec3 color1 = vec3(0.0); - vec3 color2 = vec3(0.0); - vec3 color3 = vec3(0.0); - float weight1 = 1.0; - float weight2 = 0.0; - float weight3 = 0.0; - - float ndf = renderProbe(viewDir, wPosition, normal, norm, Roughness, diffuseColor, specularColor, ndotv, ao, g_LightProbeData, g_ShCoeffs, g_PrefEnvMap, color1); - #if NB_PROBES >= 2 - float ndf2 = renderProbe(viewDir, wPosition, normal, norm, Roughness, diffuseColor, specularColor, ndotv, ao, g_LightProbeData2, g_ShCoeffs2, g_PrefEnvMap2, color2); - #endif - #if NB_PROBES == 3 - float ndf3 = renderProbe(viewDir, wPosition, normal, norm, Roughness, diffuseColor, specularColor, ndotv, ao, g_LightProbeData3, g_ShCoeffs3, g_PrefEnvMap3, color3); - #endif - - #if NB_PROBES >= 2 - float invNdf = max(1.0 - ndf,0.0); - float invNdf2 = max(1.0 - ndf2,0.0); - float sumNdf = ndf + ndf2; - float sumInvNdf = invNdf + invNdf2; - #if NB_PROBES == 3 - float invNdf3 = max(1.0 - ndf3,0.0); - sumNdf += ndf3; - sumInvNdf += invNdf3; - weight3 = ((1.0 - (ndf3 / sumNdf)) / (NB_PROBES - 1)) * (invNdf3 / sumInvNdf); - #endif - - weight1 = ((1.0 - (ndf / sumNdf)) / (NB_PROBES - 1)) * (invNdf / sumInvNdf); - weight2 = ((1.0 - (ndf2 / sumNdf)) / (NB_PROBES - 1)) * (invNdf2 / sumInvNdf); - - float weightSum = weight1 + weight2 + weight3; - - weight1 /= weightSum; - weight2 /= weightSum; - weight3 /= weightSum; - #endif - - #ifdef USE_AMBIENT_LIGHT - color1.rgb *= g_AmbientLightColor.rgb; - color2.rgb *= g_AmbientLightColor.rgb; - color3.rgb *= g_AmbientLightColor.rgb; - #endif - - -// multiply probes by the indoorSunLightExposure, as determined by pixel's sunlightExposure and adjusted for -// nearby point/spot lights ( will be multiplied by 1.0 and left unchanged if you are not defining any of the sunlight exposure variables for dimming indoors areas) - color1.rgb *= indoorSunLightExposure; - color2.rgb *= indoorSunLightExposure; - color3.rgb *= indoorSunLightExposure; - - gl_FragColor.rgb += color1 * clamp(weight1,0.0,1.0) + color2 * clamp(weight2,0.0,1.0) + color3 * clamp(weight3,0.0,1.0); - - #endif - - if(emissive.a > 0){ - emissive = emissive * pow(emissive.a * 5, emissiveIntensity) * emissiveIntensity * 20 * emissive.a; - } - - // emissive = emissive * pow(emissiveIntensity * 2.3, emissive.a); - - gl_FragColor += emissive; - - // add fog after the lighting because shadows will cause the fog to darken - // which just results in the geometry looking like it's changed color - #ifdef USE_FOG - #ifdef FOG_LINEAR - gl_FragColor = getFogLinear(gl_FragColor, m_FogColor, m_LinearFog.x, m_LinearFog.y, fogDistance); - #endif - #ifdef FOG_EXP - gl_FragColor = getFogExp(gl_FragColor, m_FogColor, m_ExpFog, fogDistance); - #endif - #ifdef FOG_EXPSQ - gl_FragColor = getFogExpSquare(gl_FragColor, m_FogColor, m_ExpSqFog, fogDistance); - #endif - #endif - - //outputs the final value of the selected layer as a color for debug purposes. - #ifdef DEBUG_VALUES_MODE - if(m_DebugValuesMode == 0){ - gl_FragColor.rgb = vec3(albedo); - } - else if(m_DebugValuesMode == 1){ - gl_FragColor.rgb = vec3(normal); - } - else if(m_DebugValuesMode == 2){ - gl_FragColor.rgb = vec3(Roughness); - } - else if(m_DebugValuesMode == 3){ - gl_FragColor.rgb = vec3(Metallic); - } - else if(m_DebugValuesMode == 4){ - gl_FragColor.rgb = ao.rgb; - } - else if(m_DebugValuesMode == 5){ - gl_FragColor.rgb = vec3(emissive.rgb); - } - #endif - gl_FragColor.a = albedo.a; - -} From ca07eb42a41c2c0c74acf24b5b094e85d2f81b3d Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Tue, 11 Feb 2025 04:55:08 -0500 Subject: [PATCH 03/26] Update AdvancedPBRTerrain.frag to work with both MatDefs --- .../MatDefs/Terrain/AdvancedPBRTerrain.frag | 80 +++++++++++++------ 1 file changed, 54 insertions(+), 26 deletions(-) diff --git a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.frag b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.frag index d889ec82b7..3fced2dd6e 100644 --- a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.frag +++ b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.frag @@ -25,7 +25,7 @@ uniform vec3 g_CameraPosition; #endif #ifdef USE_FOG - #import "Common/ShaderLib/MaterialFog.glsllib" + #import "MatDefs/ShaderLib/MaterialFog.glsllib" #endif void main(){ @@ -35,6 +35,8 @@ void main(){ // Create a blank PBRSurface. PBRSurface surface = PBRLightingUtils_createPBRSurface(worldViewDir); + surface.alpha = 1.0; + surface.normal = surface.geometryNormal; //pre-calculate necessary values for tri-planar blending TriPlanarUtils_calculateBlending(surface.geometryNormal); @@ -49,7 +51,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){ @@ -59,29 +61,52 @@ void main(){ } #endif + terrainTextureLayer_$i.roughness = m_Roughness_$i; + terrainTextureLayer_$i.metallic = m_Metallic_$i; terrainTextureLayer_$i.emission = m_EmissiveColor_$i; + + #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_MetallicRoughnessAoEiTextureArray, 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 - #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 + #endif //CUSTOM LIB EXAMPLE: uses a custom alpha map to desaturate albedo color for a color-removal effect #ifdef AFFLICTIONTEXTURE @@ -91,7 +116,8 @@ void main(){ //blends this layer PBRTerrainUtils_blendPBRTerrainLayer(surface, terrainTextureLayer_$i); - #endfor + #endfor + #ifdef DISCARD_ALPHA if(surface.alpha < m_AlphaDiscardThreshold){ @@ -129,7 +155,8 @@ 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)); @@ -138,5 +165,6 @@ void main(){ //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 + } From 8cc262bc678df6bbf231a3ce8485f82a26980853 Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Tue, 11 Feb 2025 04:57:11 -0500 Subject: [PATCH 04/26] Update AdvancedPBRTerrain.frag --- .../resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.frag | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.frag b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.frag index 3fced2dd6e..7dd7a79694 100644 --- a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.frag +++ b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.frag @@ -25,7 +25,7 @@ uniform vec3 g_CameraPosition; #endif #ifdef USE_FOG - #import "MatDefs/ShaderLib/MaterialFog.glsllib" + #import "Common/ShaderLib/MaterialFog.glsllib" #endif void main(){ From d9ae33bc3052cfbce42bf9b790fe4a037b3b0a0a Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Tue, 11 Feb 2025 06:34:02 -0500 Subject: [PATCH 05/26] Update AdvancedPBRTerrain.j3md --- .../MatDefs/Terrain/AdvancedPBRTerrain.j3md | 40 +++++++++++-------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.j3md b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.j3md index 105a38b8b0..452dc85d21 100644 --- a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.j3md +++ b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.j3md @@ -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 @@ -272,6 +272,9 @@ MaterialDef AdvancedPBRTerrain { // Alpha threshold for fragment discarding Float AlphaDiscardThreshold (AlphaTestFallOff) + + //do not change this or AdvancedPBRTerrain will break + Boolean UseTextureArrays : true } Technique { @@ -301,11 +304,11 @@ 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 - USE_FIRST_LAYER_AS_TRANSPARENCY : UseFirstLayerAsTransparency + USE_FIRST_LAYER_AS_TRANSPARENCY : FirstLayerAsTransparency; SPECULAR_AA : UseSpecularAA SPECULAR_AA_SCREEN_SPACE_VARIANCE : SpecularAASigma @@ -323,6 +326,8 @@ MaterialDef AdvancedPBRTerrain { AFFLICTIONEMISSIVEMAP : SplatEmissiveMap USE_SPLAT_NOISE : SplatNoiseVar + USE_TRIPLANAR_AFFLICTION_MAPPING : UseTriplanarAfflictionMapping + TRI_PLANAR_MAPPING : useTriPlanarMapping ALPHAMAP : AlphaMap @@ -368,21 +373,22 @@ MaterialDef AdvancedPBRTerrain { METALLICROUGHNESSMAP_10 : MetallicRoughnessMap_10 METALLICROUGHNESSMAP_11 : MetallicRoughnessMap_11 - TRI_PLANAR_MAPPING_0 : UseTriPlanarMapping_0 - TRI_PLANAR_MAPPING_1 : UseTriPlanarMapping_1 - TRI_PLANAR_MAPPING_2 : UseTriPlanarMapping_2 - TRI_PLANAR_MAPPING_3 : UseTriPlanarMapping_3 - TRI_PLANAR_MAPPING_4 : UseTriPlanarMapping_4 - TRI_PLANAR_MAPPING_5 : UseTriPlanarMapping_5 - TRI_PLANAR_MAPPING_6 : UseTriPlanarMapping_6 - TRI_PLANAR_MAPPING_7 : UseTriPlanarMapping_7 - TRI_PLANAR_MAPPING_8 : UseTriPlanarMapping_8 - TRI_PLANAR_MAPPING_9 : UseTriPlanarMapping_9 - TRI_PLANAR_MAPPING_10 : UseTriPlanarMapping_10 - TRI_PLANAR_MAPPING_11 : UseTriPlanarMapping_11 + TRI_PLANAR_MAPPING_0 : TriPlanar_0 + TRI_PLANAR_MAPPING_1 : TriPlanar_1 + TRI_PLANAR_MAPPING_2 : TriPlanar_2 + TRI_PLANAR_MAPPING_3 : TriPlanar_3 + TRI_PLANAR_MAPPING_4 : TriPlanar_4 + TRI_PLANAR_MAPPING_5 : TriPlanar_5 + TRI_PLANAR_MAPPING_6 : TriPlanar_6 + TRI_PLANAR_MAPPING_7 : TriPlanar_7 + TRI_PLANAR_MAPPING_8 : TriPlanar_8 + TRI_PLANAR_MAPPING_9 : TriPlanar_9 + TRI_PLANAR_MAPPING_10 : TriPlanar_10 + TRI_PLANAR_MAPPING_11 : TriPlanar_11 DEBUG_VALUES_MODE : DebugValuesMode + USE_TEXTURE_ARRAYS : UseTextureArrays } } From b52a678ac090d83e83689123b636667eb7d86d5c Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Tue, 11 Feb 2025 06:38:29 -0500 Subject: [PATCH 06/26] Update AdvancedPBRTerrain.j3md --- .../MatDefs/Terrain/AdvancedPBRTerrain.j3md | 34 ++++++++----------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.j3md b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.j3md index 452dc85d21..6b7552d530 100644 --- a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.j3md +++ b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.j3md @@ -43,7 +43,6 @@ MaterialDef AdvancedPBRTerrain { Float SplatNoiseVar - Int AfflictionMode_0 : 1 Int AfflictionMode_1 : 1 Int AfflictionMode_2 : 1 @@ -109,7 +108,6 @@ MaterialDef AdvancedPBRTerrain { Int AlbedoMap_10 Int AlbedoMap_11 - Float AlbedoMap_0_scale : 1 Float AlbedoMap_1_scale : 1 Float AlbedoMap_2_scale : 1 @@ -136,7 +134,6 @@ MaterialDef AdvancedPBRTerrain { Boolean UseTriPlanarMapping_10 Boolean UseTriPlanarMapping_11 - Int NormalMap_0 Int NormalMap_1 Int NormalMap_2 @@ -150,7 +147,6 @@ MaterialDef AdvancedPBRTerrain { Int NormalMap_10 Int NormalMap_11 - Int MetallicRoughnessMap_0 Int MetallicRoughnessMap_1 Int MetallicRoughnessMap_2 @@ -164,7 +160,6 @@ MaterialDef AdvancedPBRTerrain { Int MetallicRoughnessMap_10 Int MetallicRoughnessMap_11 - Float ParallaxHeight_0 Float ParallaxHeight_1 Float ParallaxHeight_2 @@ -178,8 +173,6 @@ 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 @@ -195,6 +188,7 @@ MaterialDef AdvancedPBRTerrain { // 5 - emissive // 6 - exposure // 7 - alpha + // 8 - geometryNormals // use tri-planar mapping Boolean useTriPlanarMapping @@ -308,7 +302,7 @@ MaterialDef AdvancedPBRTerrain { STATIC_SUN_EXPOSURE : StaticSunExposure BRIGHTEN_INDOOR_SHADOWS : BrightenIndoorShadows - USE_FIRST_LAYER_AS_TRANSPARENCY : FirstLayerAsTransparency; + USE_FIRST_LAYER_AS_TRANSPARENCY : UseFirstLayerAsTransparency; SPECULAR_AA : UseSpecularAA SPECULAR_AA_SCREEN_SPACE_VARIANCE : SpecularAASigma @@ -373,18 +367,18 @@ MaterialDef AdvancedPBRTerrain { METALLICROUGHNESSMAP_10 : MetallicRoughnessMap_10 METALLICROUGHNESSMAP_11 : MetallicRoughnessMap_11 - TRI_PLANAR_MAPPING_0 : TriPlanar_0 - TRI_PLANAR_MAPPING_1 : TriPlanar_1 - TRI_PLANAR_MAPPING_2 : TriPlanar_2 - TRI_PLANAR_MAPPING_3 : TriPlanar_3 - TRI_PLANAR_MAPPING_4 : TriPlanar_4 - TRI_PLANAR_MAPPING_5 : TriPlanar_5 - TRI_PLANAR_MAPPING_6 : TriPlanar_6 - TRI_PLANAR_MAPPING_7 : TriPlanar_7 - TRI_PLANAR_MAPPING_8 : TriPlanar_8 - TRI_PLANAR_MAPPING_9 : TriPlanar_9 - TRI_PLANAR_MAPPING_10 : TriPlanar_10 - TRI_PLANAR_MAPPING_11 : TriPlanar_11 + TRI_PLANAR_MAPPING_0 : UseTriPlanarMapping_0 + TRI_PLANAR_MAPPING_1 : UseTriPlanarMapping_1 + TRI_PLANAR_MAPPING_2 : UseTriPlanarMapping_2 + TRI_PLANAR_MAPPING_3 : UseTriPlanarMapping_3 + TRI_PLANAR_MAPPING_4 : UseTriPlanarMapping_4 + TRI_PLANAR_MAPPING_5 : UseTriPlanarMapping_5 + TRI_PLANAR_MAPPING_6 : UseTriPlanarMapping_6 + TRI_PLANAR_MAPPING_7 : UseTriPlanarMapping_7 + TRI_PLANAR_MAPPING_8 : UseTriPlanarMapping_8 + TRI_PLANAR_MAPPING_9 : UseTriPlanarMapping_9 + TRI_PLANAR_MAPPING_10 : UseTriPlanarMapping_10 + TRI_PLANAR_MAPPING_11 : UseTriPlanarMapping_11 DEBUG_VALUES_MODE : DebugValuesMode From 1f28da663bfa4e6d1147015227a9b1a3b897a105 Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Tue, 11 Feb 2025 06:40:06 -0500 Subject: [PATCH 07/26] Update AdvancedPBRTerrain.j3md --- .../resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.j3md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.j3md b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.j3md index 6b7552d530..968e7ca283 100644 --- a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.j3md +++ b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.j3md @@ -177,7 +177,7 @@ MaterialDef AdvancedPBRTerrain { 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) @@ -302,7 +302,7 @@ MaterialDef AdvancedPBRTerrain { STATIC_SUN_EXPOSURE : StaticSunExposure BRIGHTEN_INDOOR_SHADOWS : BrightenIndoorShadows - USE_FIRST_LAYER_AS_TRANSPARENCY : UseFirstLayerAsTransparency; + USE_FIRST_LAYER_AS_TRANSPARENCY : UseFirstLayerAsTransparency SPECULAR_AA : UseSpecularAA SPECULAR_AA_SCREEN_SPACE_VARIANCE : SpecularAASigma @@ -386,7 +386,6 @@ MaterialDef AdvancedPBRTerrain { } } - Technique PreShadow { VertexShader GLSL300 GLSL150 GLSL100 : Common/MatDefs/Shadow/PreShadow.vert From e5a0f28287f3a45e8b6fdd495f63b0076f1648d0 Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Thu, 20 Feb 2025 00:08:51 -0500 Subject: [PATCH 08/26] Update PBRTerrainUtils.glsllib --- .../Common/MatDefs/Terrain/Modular/PBRTerrainUtils.glsllib | 1 - 1 file changed, 1 deletion(-) diff --git a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/Modular/PBRTerrainUtils.glsllib b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/Modular/PBRTerrainUtils.glsllib index 6afaf13141..90e8eb5c5e 100644 --- a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/Modular/PBRTerrainUtils.glsllib +++ b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/Modular/PBRTerrainUtils.glsllib @@ -217,4 +217,3 @@ #endif #endif - From db5b9f00b10ea9f89d164d881daf0c7653ce62ba Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Sun, 23 Feb 2025 21:46:29 -0500 Subject: [PATCH 09/26] Change trigger for USE_TEXTURE_ARRAYS define Removes the UseTextureArrays boolean, and instead map the define to the AlbedoTextureArray. This should be a cleaner way to do it that the define doesn't rely on users going back and setting a boolean on old terrain mats, and gives less chance to accidentally break the shader if the boolean value is cleared by mistake for some reason. --- .../resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.j3md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.j3md b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.j3md index 968e7ca283..90992865f7 100644 --- a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.j3md +++ b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.j3md @@ -266,9 +266,6 @@ MaterialDef AdvancedPBRTerrain { // Alpha threshold for fragment discarding Float AlphaDiscardThreshold (AlphaTestFallOff) - - //do not change this or AdvancedPBRTerrain will break - Boolean UseTextureArrays : true } Technique { @@ -382,7 +379,7 @@ MaterialDef AdvancedPBRTerrain { DEBUG_VALUES_MODE : DebugValuesMode - USE_TEXTURE_ARRAYS : UseTextureArrays + USE_TEXTURE_ARRAYS : AlbedoTextureArray } } From 5cf33088f382d0a4a195273d936e69c445d2bae5 Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Sun, 2 Mar 2025 05:39:49 -0500 Subject: [PATCH 10/26] Update PBRTerrain.j3md --- .../Common/MatDefs/Terrain/PBRTerrain.j3md | 58 ++++++++++++------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/PBRTerrain.j3md b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/PBRTerrain.j3md index ea7151267a..d70ac7eeb7 100644 --- a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/PBRTerrain.j3md +++ b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/PBRTerrain.j3md @@ -4,13 +4,14 @@ MaterialDef PBR Terrain { MaterialParameters { Int BoundDrawBuffer - - 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 + Texture2D SunLightExposureMap + 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 + Boolean UseFirstLayerAsTransparency Int AfflictionSplatScale : 8 @@ -78,18 +79,31 @@ MaterialDef PBR Terrain { Float Metallic_10 : 0.0 Float Metallic_11 : 0.0 - - // debug the final value of the selected layer as a color output + Boolean UseTriPlanarMapping_0 + Boolean UseTriPlanarMapping_1 + Boolean UseTriPlanarMapping_2 + Boolean UseTriPlanarMapping_3 + Boolean UseTriPlanarMapping_4 + Boolean UseTriPlanarMapping_5 + Boolean UseTriPlanarMapping_6 + Boolean UseTriPlanarMapping_7 + Boolean UseTriPlanarMapping_8 + Boolean UseTriPlanarMapping_9 + Boolean UseTriPlanarMapping_10 + Boolean UseTriPlanarMapping_11 + + // debug the final value of the selected layer as a color output Int DebugValuesMode - // Layers: - // 0 - albedo (un-shaded) + // 0 - albedo (unshaded) // 1 - normals // 2 - roughness // 3 - metallic // 4 - ao - // 5 - emissive - + // 5 - emissive + // 6 - exposure + // 7 - alpha + // 8 - geometryNormals // use tri-planar mapping Boolean useTriPlanarMapping @@ -154,21 +168,11 @@ MaterialDef PBR Terrain { Float AlbedoMap_11_scale Texture2D NormalMap_11 -LINEAR - - // Texture that specifies alpha values Texture2D AlphaMap -LINEAR Texture2D AlphaMap_1 -LINEAR Texture2D AlphaMap_2 -LINEAR - // For Spec gloss pipeline - 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 @@ -221,7 +225,6 @@ MaterialDef PBR Terrain { Boolean BackfaceShadows : false - Boolean UseFog Color FogColor Vector2 LinearFog @@ -247,7 +250,6 @@ MaterialDef PBR Terrain { ViewProjectionMatrix ViewMatrix Time - } Defines { @@ -267,7 +269,6 @@ MaterialDef PBR Terrain { SPECULAR_AA_SCREEN_SPACE_VARIANCE : SpecularAASigma SPECULAR_AA_THRESHOLD : SpecularAAKappa - USE_VERTEX_COLORS_AS_SUN_INTENSITY : UseVertexColorsAsSunIntensity STATIC_SUN_INTENSITY : StaticSunIntensity BRIGHTEN_INDOOR_SHADOWS : BrightenIndoorShadows @@ -323,6 +324,19 @@ MaterialDef PBR Terrain { ALBEDOMAP_10_SCALE : AlbedoMap_10_scale ALBEDOMAP_11_SCALE : AlbedoMap_11_scale + TRI_PLANAR_MAPPING_0 : UseTriPlanarMapping_0 + TRI_PLANAR_MAPPING_1 : UseTriPlanarMapping_1 + TRI_PLANAR_MAPPING_2 : UseTriPlanarMapping_2 + TRI_PLANAR_MAPPING_3 : UseTriPlanarMapping_3 + TRI_PLANAR_MAPPING_4 : UseTriPlanarMapping_4 + TRI_PLANAR_MAPPING_5 : UseTriPlanarMapping_5 + TRI_PLANAR_MAPPING_6 : UseTriPlanarMapping_6 + TRI_PLANAR_MAPPING_7 : UseTriPlanarMapping_7 + TRI_PLANAR_MAPPING_8 : UseTriPlanarMapping_8 + TRI_PLANAR_MAPPING_9 : UseTriPlanarMapping_9 + TRI_PLANAR_MAPPING_10 : UseTriPlanarMapping_10 + TRI_PLANAR_MAPPING_11 : UseTriPlanarMapping_11 + DEBUG_VALUES_MODE : DebugValuesMode } From fed39729cb605123dcbe93ab2ac6877cd1a53e93 Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Sun, 2 Mar 2025 05:39:56 -0500 Subject: [PATCH 11/26] Update AdvancedPBRTerrain.j3md --- .../Common/MatDefs/Terrain/AdvancedPBRTerrain.j3md | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.j3md b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.j3md index 90992865f7..6bb85dbd53 100644 --- a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.j3md +++ b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.j3md @@ -28,7 +28,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 @@ -198,13 +197,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 @@ -216,7 +208,6 @@ MaterialDef AdvancedPBRTerrain { //integrate BRDF map for indirect Lighting Texture2D IntegrateBRDF -LINEAR - //shadows Int FilterMode Boolean HardwareShadows @@ -283,7 +274,6 @@ MaterialDef AdvancedPBRTerrain { ViewProjectionMatrix ViewMatrix Time - } Defines { From 2a9d258b0761181715552873e259099c240c5655 Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Sun, 2 Mar 2025 05:41:00 -0500 Subject: [PATCH 12/26] Update PBRTerrain.j3md --- .../main/resources/Common/MatDefs/Terrain/PBRTerrain.j3md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/PBRTerrain.j3md b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/PBRTerrain.j3md index d70ac7eeb7..150dd9192d 100644 --- a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/PBRTerrain.j3md +++ b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/PBRTerrain.j3md @@ -269,8 +269,9 @@ MaterialDef PBR Terrain { SPECULAR_AA_SCREEN_SPACE_VARIANCE : SpecularAASigma SPECULAR_AA_THRESHOLD : SpecularAAKappa - USE_VERTEX_COLORS_AS_SUN_INTENSITY : UseVertexColorsAsSunIntensity - STATIC_SUN_INTENSITY : StaticSunIntensity + EXPOSUREMAP : SunLightExposureMap + USE_VERTEX_COLORS_AS_SUN_EXPOSURE : UseVertexColorsAsSunExposure + STATIC_SUN_EXPOSURE : StaticSunExposure BRIGHTEN_INDOOR_SHADOWS : BrightenIndoorShadows DISCARD_ALPHA : AlphaDiscardThreshold From d2967f99c276e8c61d37d224253a0c8b7c21f322 Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Sun, 2 Mar 2025 05:43:28 -0500 Subject: [PATCH 13/26] Update PBRTerrain.j3md --- .../src/main/resources/Common/MatDefs/Terrain/PBRTerrain.j3md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/PBRTerrain.j3md b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/PBRTerrain.j3md index 150dd9192d..9240a8cb3d 100644 --- a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/PBRTerrain.j3md +++ b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/PBRTerrain.j3md @@ -274,6 +274,8 @@ MaterialDef PBR Terrain { STATIC_SUN_EXPOSURE : StaticSunExposure BRIGHTEN_INDOOR_SHADOWS : BrightenIndoorShadows + USE_FIRST_LAYER_AS_TRANSPARENCY : UseFirstLayerAsTransparency + DISCARD_ALPHA : AlphaDiscardThreshold USE_FOG : UseFog From 9d0e74e1cdb2c9c8f268a8877ddaf3f9e95fb9cb Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Sun, 2 Mar 2025 22:36:37 -0500 Subject: [PATCH 14/26] Update AdvancedPBRTerrain.frag --- .../MatDefs/Terrain/AdvancedPBRTerrain.frag | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.frag b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.frag index 7dd7a79694..9cad93f886 100644 --- a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.frag +++ b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.frag @@ -35,8 +35,6 @@ void main(){ // Create a blank PBRSurface. PBRSurface surface = PBRLightingUtils_createPBRSurface(worldViewDir); - surface.alpha = 1.0; - surface.normal = surface.geometryNormal; //pre-calculate necessary values for tri-planar blending TriPlanarUtils_calculateBlending(surface.geometryNormal); @@ -87,13 +85,13 @@ void main(){ #endif #else #if defined(TRI_PLANAR_MAPPING) || defined(TRI_PLANAR_MAPPING_$i) - //triplanar texture reads: + //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_MetallicRoughnessAoEiTextureArray, terrainTextureLayer_$i); + PBRTerrainUtils_readTriPlanarMetallicRoughnessAoEiTexture(m_MetallicRoughnessMap_$i, m_AlbedoMap_$i_scale, terrainTextureLayer_$i); #endif #else //non tri-planar texture reads: @@ -104,8 +102,7 @@ void main(){ #ifdef METALLICROUGHNESSMAP_$i PBRTerrainUtils_readMetallicRoughnessAoEiTexture(m_MetallicRoughnessMap_$i, m_AlbedoMap_$i_scale, terrainTextureLayer_$i); #endif - #endif - + #endif #endif //CUSTOM LIB EXAMPLE: uses a custom alpha map to desaturate albedo color for a color-removal effect @@ -116,8 +113,7 @@ void main(){ //blends this layer PBRTerrainUtils_blendPBRTerrainLayer(surface, terrainTextureLayer_$i); - #endfor - + #endfor #ifdef DISCARD_ALPHA if(surface.alpha < m_AlphaDiscardThreshold){ @@ -155,9 +151,8 @@ 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 @@ -166,5 +161,4 @@ void main(){ #ifdef DEBUG_VALUES_MODE gl_FragColor = PBRLightingUtils_getColorOutputForDebugMode(m_DebugValuesMode, vec4(gl_FragColor.rgba), surface); #endif - } From 8a9253ba23147731c914b1445cd60f43f8bd3edf Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Sun, 2 Mar 2025 22:52:50 -0500 Subject: [PATCH 15/26] Update PBRTerrain.j3md --- .../src/main/resources/Common/MatDefs/Terrain/PBRTerrain.j3md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/PBRTerrain.j3md b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/PBRTerrain.j3md index 9240a8cb3d..c41366bc42 100644 --- a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/PBRTerrain.j3md +++ b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/PBRTerrain.j3md @@ -13,6 +13,7 @@ MaterialDef PBR Terrain { Boolean UseFirstLayerAsTransparency + Boolean UseTriplanarAfflictionMapping Int AfflictionSplatScale : 8 Float AfflictionRoughnessValue : 1.0 @@ -258,6 +259,7 @@ MaterialDef PBR Terrain { TILELOCATION : TileLocation AFFLICTIONTEXTURE : AfflictionAlphaMap + USE_TRIPLANAR_AFFLICTION_MAPPING : UseTriplanarAfflictionMapping AFFLICTIONALBEDOMAP: SplatAlbedoMap AFFLICTIONNORMALMAP : SplatNormalMap AFFLICTIONROUGHNESSMETALLICMAP : SplatRoughnessMetallicMap From 232289d72145db72170365a908cf0b571f4e467e Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Sun, 2 Mar 2025 23:00:58 -0500 Subject: [PATCH 16/26] Update PBRTerrainUtils.glsllib --- .../MatDefs/Terrain/Modular/PBRTerrainUtils.glsllib | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/Modular/PBRTerrainUtils.glsllib b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/Modular/PBRTerrainUtils.glsllib index 90e8eb5c5e..8cd634bef7 100644 --- a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/Modular/PBRTerrainUtils.glsllib +++ b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/Modular/PBRTerrainUtils.glsllib @@ -152,17 +152,17 @@ // Triplanar Albedo: void PBRTerrainUtils_readTriPlanarAlbedoTexture(in sampler2D tex, in float scale, inout PBRTerrainTextureLayer layer){ - vec4 packedAlbedoVec = getTriPlanarBlend(lPosition, tex, scale); + vec4 packedAlbedoVec = getTriPlanarBlend(wPosition, tex, scale); updateLayerFromPackedAlbedoMap(packedAlbedoVec, layer); } // Triplanar normal: void PBRTerrainUtils_readTriPlanarNormalTexture(in sampler2D tex, in float scale, inout PBRTerrainTextureLayer layer){ - vec4 packedNormalParallaxVec = getTriPlanarNormalBlend(lPosition, tex, scale); + vec4 packedNormalParallaxVec = getTriPlanarNormalBlend(wPosition, tex, scale); updateLayerFromPackedNormalParallaxVec(packedNormalParallaxVec, layer); } // TriPlanar metallicRoughnessAoEi: void PBRTerrainUtils_readTriPlanarMetallicRoughnessAoEiTexture(in sampler2D tex, in float scale, inout PBRTerrainTextureLayer layer){ - vec4 packedMRAoEi = getTriPlanarBlend(lPosition, tex, scale); + vec4 packedMRAoEi = getTriPlanarBlend(wPosition, tex, scale); updateLayerFromPackedMRAoEiVec(packedMRAoEi, layer); } //________________________________ @@ -203,10 +203,8 @@ } //_______________________________ - //blend layer function: - void PBRTerrainUtils_blendPBRTerrainLayer(inout PBRSurface surface, inout PBRTerrainTextureLayer layer){ - - //mixes this layer's pbr vars over top of the current surface values based on the layer's blendValue + //blend layer function. This mixes each layer's pbr vars over top of the current surface values based on the layer's blendValue + void PBRTerrainUtils_blendPBRTerrainLayer(inout PBRSurface surface, inout PBRTerrainTextureLayer layer){ surface.albedo = mix(surface.albedo, layer.albedo.rgb, layer.blendValue); surface.normal = normalize(mix(surface.normal.rgb, layer.normal, layer.blendValue)); surface.metallic = mix(surface.metallic, layer.metallic, layer.blendValue); From 14fc28d56d9b0fc3a4d9af7ef0f1b114e1cb66d9 Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Sun, 2 Mar 2025 23:03:47 -0500 Subject: [PATCH 17/26] Update PBRTerrainUtils.glsllib accidentally reverted triplanar to using wPosition instead of lPosition. probably doesn't matter, both should work (although high wPosition values could result in lack of float precision so its best to go with local instead of world) --- .../Common/MatDefs/Terrain/Modular/PBRTerrainUtils.glsllib | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/Modular/PBRTerrainUtils.glsllib b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/Modular/PBRTerrainUtils.glsllib index 8cd634bef7..07c23e83da 100644 --- a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/Modular/PBRTerrainUtils.glsllib +++ b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/Modular/PBRTerrainUtils.glsllib @@ -152,17 +152,17 @@ // Triplanar Albedo: void PBRTerrainUtils_readTriPlanarAlbedoTexture(in sampler2D tex, in float scale, inout PBRTerrainTextureLayer layer){ - vec4 packedAlbedoVec = getTriPlanarBlend(wPosition, tex, scale); + vec4 packedAlbedoVec = getTriPlanarBlend(lPosition, tex, scale); updateLayerFromPackedAlbedoMap(packedAlbedoVec, layer); } // Triplanar normal: void PBRTerrainUtils_readTriPlanarNormalTexture(in sampler2D tex, in float scale, inout PBRTerrainTextureLayer layer){ - vec4 packedNormalParallaxVec = getTriPlanarNormalBlend(wPosition, tex, scale); + vec4 packedNormalParallaxVec = getTriPlanarNormalBlend(lPosition, tex, scale); updateLayerFromPackedNormalParallaxVec(packedNormalParallaxVec, layer); } // TriPlanar metallicRoughnessAoEi: void PBRTerrainUtils_readTriPlanarMetallicRoughnessAoEiTexture(in sampler2D tex, in float scale, inout PBRTerrainTextureLayer layer){ - vec4 packedMRAoEi = getTriPlanarBlend(wPosition, tex, scale); + vec4 packedMRAoEi = getTriPlanarBlend(lPosition, tex, scale); updateLayerFromPackedMRAoEiVec(packedMRAoEi, layer); } //________________________________ From d60231183c7238e100adb04242c4b271f2dd1f7d Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Sun, 2 Mar 2025 23:18:05 -0500 Subject: [PATCH 18/26] Update PBRTerrainUtils.glsllib --- .../Common/MatDefs/Terrain/Modular/PBRTerrainUtils.glsllib | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/Modular/PBRTerrainUtils.glsllib b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/Modular/PBRTerrainUtils.glsllib index 60ba27f1c8..2b4e1fef48 100644 --- a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/Modular/PBRTerrainUtils.glsllib +++ b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/Modular/PBRTerrainUtils.glsllib @@ -23,7 +23,6 @@ uniform float m_AlbedoMap_$i_scale; uniform vec4 m_EmissiveColor_$i; - #ifdef USE_TEXTURE_ARRAYS uniform int m_AlbedoMap_$i; #ifdef NORMALMAP_$i @@ -214,4 +213,4 @@ } #endif -#endif \ No newline at end of file +#endif From 50ece7c6db0affd349b5c130a5d9c5f007cf466b Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Mon, 3 Mar 2025 04:57:30 -0500 Subject: [PATCH 19/26] Add NORMAL_TYPE to PBRTerrainUtils.glsllib --- .../MatDefs/Terrain/Modular/PBRTerrainUtils.glsllib | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/Modular/PBRTerrainUtils.glsllib b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/Modular/PBRTerrainUtils.glsllib index 2b4e1fef48..9e77e87d79 100644 --- a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/Modular/PBRTerrainUtils.glsllib +++ b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/Modular/PBRTerrainUtils.glsllib @@ -7,6 +7,10 @@ #import "Common/ShaderLib/TriPlanarUtils.glsllib" #ifdef ENABLE_PBRTerrainUtils_readPBRTerrainLayers + + #ifndef NORMAL_TYPE + #define NORMAL_TYPE 1.0 + #endif #ifdef USE_TEXTURE_ARRAYS //texture arrays: @@ -23,6 +27,7 @@ uniform float m_AlbedoMap_$i_scale; uniform vec4 m_EmissiveColor_$i; + #ifdef USE_TEXTURE_ARRAYS uniform int m_AlbedoMap_$i; #ifdef NORMALMAP_$i @@ -139,6 +144,7 @@ // normal: void PBRTerrainUtils_readNormalTexture(in sampler2D tex, in float scale, inout PBRTerrainTextureLayer layer){ vec4 packedNormalParallaxVec = texture2D(tex, texCoord * scale); + packedNormalParallaxVec.xyz *= normalize(vec3(2.0, NORMAL_TYPE * 2.0, 2.0) - vec3(1.0, NORMAL_TYPE * 1.0, 1.0)); updateLayerFromPackedNormalParallaxVec(packedNormalParallaxVec, layer); } // metallicRoughnessAoEi: @@ -157,6 +163,7 @@ // Triplanar normal: void PBRTerrainUtils_readTriPlanarNormalTexture(in sampler2D tex, in float scale, inout PBRTerrainTextureLayer layer){ vec4 packedNormalParallaxVec = getTriPlanarNormalBlend(lPosition, tex, scale); + packedNormalParallaxVec.xyz *= normalize(vec3(2.0, NORMAL_TYPE * 2.0, 2.0) - vec3(1.0, NORMAL_TYPE * 1.0, 1.0)); updateLayerFromPackedNormalParallaxVec(packedNormalParallaxVec, layer); } // TriPlanar metallicRoughnessAoEi: @@ -175,6 +182,7 @@ // Normal TextureArray: void PBRTerrainUtils_readNormalTexArray(in int indexInTexArray, in float scale, in sampler2DArray texArray, inout PBRTerrainTextureLayer layer){ vec4 packedNormalParallaxVec = texture2DArray(texArray, vec3(texCoord * scale, indexInTexArray)); + packedNormalParallaxVec.xyz *= normalize(vec3(2.0, NORMAL_TYPE * 2.0, 2.0) - vec3(1.0, NORMAL_TYPE * 1.0, 1.0)); updateLayerFromPackedNormalParallaxVec(packedNormalParallaxVec, layer); } // metallicRoughnessAoEi TextureArray: @@ -193,6 +201,7 @@ // Triplanar normal TextureArray: void PBRTerrainUtils_readTriPlanarNormalTexArray(in int indexInTexArray, in float scale, in sampler2DArray texArray, inout PBRTerrainTextureLayer layer){ vec4 packedNormalParallaxVec = getTriPlanarNormalBlendFromTexArray(lPosition, indexInTexArray, scale, texArray); + packedNormalParallaxVec.xyz *= normalize(vec3(2.0, NORMAL_TYPE * 2.0, 2.0) - vec3(1.0, NORMAL_TYPE * 1.0, 1.0)); updateLayerFromPackedNormalParallaxVec(packedNormalParallaxVec, layer); } // TriPlanar metallicRoughnessAoEi TextureArray: From 22853700e3a277625d0651e9f638ebe41cb5ad6c Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Mon, 3 Mar 2025 06:19:09 -0500 Subject: [PATCH 20/26] Update PBRTerrainUtils.glsllib --- .../Common/MatDefs/Terrain/Modular/PBRTerrainUtils.glsllib | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/Modular/PBRTerrainUtils.glsllib b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/Modular/PBRTerrainUtils.glsllib index 9e77e87d79..49f790aa28 100644 --- a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/Modular/PBRTerrainUtils.glsllib +++ b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/Modular/PBRTerrainUtils.glsllib @@ -9,7 +9,7 @@ #ifdef ENABLE_PBRTerrainUtils_readPBRTerrainLayers #ifndef NORMAL_TYPE - #define NORMAL_TYPE 1.0 + #define NORMAL_TYPE -1.0 #endif #ifdef USE_TEXTURE_ARRAYS @@ -163,7 +163,6 @@ // Triplanar normal: void PBRTerrainUtils_readTriPlanarNormalTexture(in sampler2D tex, in float scale, inout PBRTerrainTextureLayer layer){ vec4 packedNormalParallaxVec = getTriPlanarNormalBlend(lPosition, tex, scale); - packedNormalParallaxVec.xyz *= normalize(vec3(2.0, NORMAL_TYPE * 2.0, 2.0) - vec3(1.0, NORMAL_TYPE * 1.0, 1.0)); updateLayerFromPackedNormalParallaxVec(packedNormalParallaxVec, layer); } // TriPlanar metallicRoughnessAoEi: @@ -201,7 +200,6 @@ // Triplanar normal TextureArray: void PBRTerrainUtils_readTriPlanarNormalTexArray(in int indexInTexArray, in float scale, in sampler2DArray texArray, inout PBRTerrainTextureLayer layer){ vec4 packedNormalParallaxVec = getTriPlanarNormalBlendFromTexArray(lPosition, indexInTexArray, scale, texArray); - packedNormalParallaxVec.xyz *= normalize(vec3(2.0, NORMAL_TYPE * 2.0, 2.0) - vec3(1.0, NORMAL_TYPE * 1.0, 1.0)); updateLayerFromPackedNormalParallaxVec(packedNormalParallaxVec, layer); } // TriPlanar metallicRoughnessAoEi TextureArray: From 885f8f75f2c75146370d3bf199fffbca6685bb2d Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Mon, 3 Mar 2025 06:22:46 -0500 Subject: [PATCH 21/26] NORMAL_TYPE support for TriPlanarUtils.glsllib --- .../resources/Common/ShaderLib/TriPlanarUtils.glsllib | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/jme3-core/src/main/resources/Common/ShaderLib/TriPlanarUtils.glsllib b/jme3-core/src/main/resources/Common/ShaderLib/TriPlanarUtils.glsllib index 7b79a4181b..4929bb8332 100644 --- a/jme3-core/src/main/resources/Common/ShaderLib/TriPlanarUtils.glsllib +++ b/jme3-core/src/main/resources/Common/ShaderLib/TriPlanarUtils.glsllib @@ -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){ @@ -45,6 +49,7 @@ // blend the results of the 3 planar projections. vec4 tex = normalize(col1 * triBlending.x + col2 * triBlending.y + col3 * triBlending.z); + tex.y *= NORMAL_TYPE; return tex; } @@ -60,7 +65,8 @@ col3.xyz = col3.xyz * vec3(2.0) - vec3(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); + tex.y *= NORMAL_TYPE; return tex; } From f3c79f7ef49f9f91d3badf090c1ef4bc33ddd655 Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Mon, 3 Mar 2025 06:45:12 -0500 Subject: [PATCH 22/26] add NORMAL_TYPE define to AdvancedPBRTerrain.j3md --- .../resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.j3md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.j3md b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.j3md index 6bb85dbd53..2098bd77f3 100644 --- a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.j3md +++ b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.j3md @@ -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. @@ -289,6 +292,8 @@ MaterialDef AdvancedPBRTerrain { STATIC_SUN_EXPOSURE : StaticSunExposure BRIGHTEN_INDOOR_SHADOWS : BrightenIndoorShadows + NORMAL_TYPE: NormalType + USE_FIRST_LAYER_AS_TRANSPARENCY : UseFirstLayerAsTransparency SPECULAR_AA : UseSpecularAA From 7ebab5fbd847b5a4f8696463c26ec2a9b77cd3de Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Mon, 3 Mar 2025 06:46:17 -0500 Subject: [PATCH 23/26] add NORMAL_TYPE define to PBRTerrain.j3md --- .../main/resources/Common/MatDefs/Terrain/PBRTerrain.j3md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/PBRTerrain.j3md b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/PBRTerrain.j3md index c41366bc42..b948b85138 100644 --- a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/PBRTerrain.j3md +++ b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/PBRTerrain.j3md @@ -26,6 +26,9 @@ MaterialDef PBR Terrain { Texture2D SplatRoughnessMetallicMap -LINEAR Texture2D SplatEmissiveMap -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. @@ -276,6 +279,8 @@ MaterialDef PBR Terrain { STATIC_SUN_EXPOSURE : StaticSunExposure BRIGHTEN_INDOOR_SHADOWS : BrightenIndoorShadows + NORMAL_TYPE: NormalType + USE_FIRST_LAYER_AS_TRANSPARENCY : UseFirstLayerAsTransparency DISCARD_ALPHA : AlphaDiscardThreshold From 8f1a0c8880eb9c408b24ffe7484226b19775b277 Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Mon, 3 Mar 2025 07:13:30 -0500 Subject: [PATCH 24/26] Add emissive vars to PBRTerrain.j3md --- .../Common/MatDefs/Terrain/PBRTerrain.j3md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/PBRTerrain.j3md b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/PBRTerrain.j3md index b948b85138..92e601c1c1 100644 --- a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/PBRTerrain.j3md +++ b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/PBRTerrain.j3md @@ -83,6 +83,19 @@ MaterialDef PBR Terrain { Float Metallic_10 : 0.0 Float Metallic_11 : 0.0 + Color EmissiveColor_0 : 0.0 0.0 0.0 0.0 + Color EmissiveColor_1 : 0.0 0.0 0.0 0.0 + Color EmissiveColor_2 : 0.0 0.0 0.0 0.0 + Color EmissiveColor_3 : 0.0 0.0 0.0 0.0 + Color EmissiveColor_4 : 0.0 0.0 0.0 0.0 + Color EmissiveColor_5 : 0.0 0.0 0.0 0.0 + Color EmissiveColor_6 : 0.0 0.0 0.0 0.0 + Color EmissiveColor_7 : 0.0 0.0 0.0 0.0 + Color EmissiveColor_8 : 0.0 0.0 0.0 0.0 + Color EmissiveColor_9 : 0.0 0.0 0.0 0.0 + Color EmissiveColor_10 : 0.0 0.0 0.0 0.0 + Color EmissiveColor_11 : 0.0 0.0 0.0 0.0 + Boolean UseTriPlanarMapping_0 Boolean UseTriPlanarMapping_1 Boolean UseTriPlanarMapping_2 From 24f6bb25a331466e9ab30de3edd0b5d947356b6e Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Tue, 4 Mar 2025 00:13:36 -0500 Subject: [PATCH 25/26] Update PBRTerrainUtils.glsllib --- .../Common/MatDefs/Terrain/Modular/PBRTerrainUtils.glsllib | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/Modular/PBRTerrainUtils.glsllib b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/Modular/PBRTerrainUtils.glsllib index 49f790aa28..55effd87b5 100644 --- a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/Modular/PBRTerrainUtils.glsllib +++ b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/Modular/PBRTerrainUtils.glsllib @@ -118,7 +118,7 @@ return terrainTextureLayer; } - //3 functinos to update layers from respective packed data vecs: + //3 functions to update layers from respective packed data vecs: void updateLayerFromPackedAlbedoMap(inout vec4 packedAlbedoVec, inout PBRTerrainTextureLayer layer){ layer.albedo = packedAlbedoVec; layer.alpha = packedAlbedoVec.a; @@ -144,7 +144,7 @@ // normal: void PBRTerrainUtils_readNormalTexture(in sampler2D tex, in float scale, inout PBRTerrainTextureLayer layer){ vec4 packedNormalParallaxVec = texture2D(tex, texCoord * scale); - packedNormalParallaxVec.xyz *= normalize(vec3(2.0, NORMAL_TYPE * 2.0, 2.0) - vec3(1.0, NORMAL_TYPE * 1.0, 1.0)); + packedNormalParallaxVec.xyz = normalize(packedNormalParallaxVec.xyz * vec3(2.0, NORMAL_TYPE * 2.0, 2.0) - vec3(1.0, NORMAL_TYPE * 1.0, 1.0)); updateLayerFromPackedNormalParallaxVec(packedNormalParallaxVec, layer); } // metallicRoughnessAoEi: @@ -181,7 +181,7 @@ // Normal TextureArray: void PBRTerrainUtils_readNormalTexArray(in int indexInTexArray, in float scale, in sampler2DArray texArray, inout PBRTerrainTextureLayer layer){ vec4 packedNormalParallaxVec = texture2DArray(texArray, vec3(texCoord * scale, indexInTexArray)); - packedNormalParallaxVec.xyz *= normalize(vec3(2.0, NORMAL_TYPE * 2.0, 2.0) - vec3(1.0, NORMAL_TYPE * 1.0, 1.0)); + packedNormalParallaxVec.xyz = normalize(packedNormalParallaxVec.xyz * vec3(2.0, NORMAL_TYPE * 2.0, 2.0) - vec3(1.0, NORMAL_TYPE * 1.0, 1.0)); updateLayerFromPackedNormalParallaxVec(packedNormalParallaxVec, layer); } // metallicRoughnessAoEi TextureArray: From 3c5eb5cf9cb4fbd7381b68b742da9521aacc6fb3 Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Tue, 4 Mar 2025 00:46:57 -0500 Subject: [PATCH 26/26] Update TriPlanarUtils.glsllib --- .../Common/ShaderLib/TriPlanarUtils.glsllib | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/jme3-core/src/main/resources/Common/ShaderLib/TriPlanarUtils.glsllib b/jme3-core/src/main/resources/Common/ShaderLib/TriPlanarUtils.glsllib index 4929bb8332..8134200ae3 100644 --- a/jme3-core/src/main/resources/Common/ShaderLib/TriPlanarUtils.glsllib +++ b/jme3-core/src/main/resources/Common/ShaderLib/TriPlanarUtils.glsllib @@ -43,30 +43,28 @@ 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); - tex.y *= NORMAL_TYPE; return tex; } // 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); - tex.y *= NORMAL_TYPE; + vec4 tex = normalize(col1 * triBlending.x + col2 * triBlending.y + col3 * triBlending.z); return tex; }