From 4879efb83698ca7de9430469bab549dbe1c725eb Mon Sep 17 00:00:00 2001 From: capdevon Date: Sat, 24 Feb 2024 17:19:55 +0100 Subject: [PATCH] PBRCharacter: update frag + vert --- src/main/resources/Shaders/PBRCharacters.frag | 91 ++++++++++++++----- src/main/resources/Shaders/PBRCharacters.vert | 17 ++++ 2 files changed, 84 insertions(+), 24 deletions(-) diff --git a/src/main/resources/Shaders/PBRCharacters.frag b/src/main/resources/Shaders/PBRCharacters.frag index 8c3e01f..933adf7 100644 --- a/src/main/resources/Shaders/PBRCharacters.frag +++ b/src/main/resources/Shaders/PBRCharacters.frag @@ -1,4 +1,40 @@ #import "Common/ShaderLib/GLSLCompat.glsllib" +//#import "ShaderLib/PBR.glsllib" +#import "Common/ShaderLib/PBR.glsllib" +#import "Common/ShaderLib/Instancing.glsllib" +#import "Common/ShaderLib/Parallax.glsllib" + + +#import "ShaderLib/NoiseLib.glsllib" + + +#import "Common/ShaderLib/Lighting.glsllib" + + + +varying vec4 Color; + +//declare PBR Lighting vars +uniform vec4 g_LightData[NB_LIGHTS]; +uniform vec3 g_CameraPosition; +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 varying vec2 texCoord; vec2 newTexCoord; @@ -15,32 +51,29 @@ varying vec3 wPosition; varying vec3 wNormal; varying vec4 wTangent; +varying vec4 modelPos; +varying vec3 scaledModelPos; +varying vec3 modelNorm; + #ifdef DEBUG_VALUES_MODE uniform int m_DebugValuesMode; #endif -// It is important that these 2 glsllibs are referenced AFTER the other variables above have been declared. -// The above variables are declared here (rather than in a glsllib) to reduce redundancy, since these variables are likely to be used by more than one glsllib. -// Only lighting variables are declared in PBRLighting.glsllib, and only basic PBR material params are declared in PBRLightingParamsReader.glsllib. -// This allows jme developers to create a fork of this shader and make their own changes before reading the base PBR parameters or before the final lighting calculation. -// For example, you can move texCoords based on g_Time before texReads for a simple moving water/lava effect, or blend values like albedo/roughness after the param reads -// but before final lighting calculations to do things like dynamic texture splatting. -#import "ShaderLib/BlendLayerEffects.glsllib" -vec4 albedo = vec4(1.0); +vec4 albedo = vec4(1.0, 1.0, 1.0, 1.0); float alpha = 1.0; -vec4 emissive = vec4(0.0); +vec4 emissive = vec4(0.0, 0.0, 0.0, 0.0); -vec3 ao = vec3(1.0); -vec3 lightMapColor = vec3(0.0); +vec3 ao = vec3(1.0, 1.0, 1.0); +vec3 lightMapColor = vec3(1.0, 1.0, 1.0); float indoorSunLightExposure = 1.0; //metallic pipeline vars: -float Metallic = 0.0; -float Roughness = 0.0; +float Metallic = 1.0; +float Roughness = 1.0; //spec gloss pipeline vars: vec4 specularColor; @@ -53,11 +86,24 @@ vec3 viewDir; mat3 tbnMat; vec3 vViewDir; + +// It is important that these 2 glsllibs are referenced AFTER the other variables above have been declared. +// The above variables are declared here (rather than in a glsllib) to reduce redundancy, since these variables are likely to be used by more than one glsllib. +// Only lighting variables are declared in PBRLighting.glsllib, and only basic PBR material params are declared in PBRLightingParamsReader.glsllib. +// This allows jme developers to create a fork of this shader and make their own changes before reading the base PBR parameters or before the final lighting calculation. +// For example, you can move texCoords based on g_Time before texReads for a simple moving water/lava effect, or blend values like albedo/roughness after the param reads +// but before final lighting calculations to do things like dynamic texture splatting. #import "ShaderLib/PBRLightingParamsReader.glsllib" #import "ShaderLib/PBRLighting.glsllib" +#import "ShaderLib/BlendLayerEffects.glsllib" + + + void main(){ + + norm = normalize(wNormal); normal = norm.xyz; viewDir = normalize(g_CameraPosition - wPosition); @@ -69,17 +115,16 @@ void main(){ vViewDir = viewDir * tbnMat; //base PBR params and tex reads: - readMatParamsAndTextures(); - // readMatParamsAndTextures(tbnMat, vViewDir, albedo, Metallic, Roughness, specularColor, glossiness, lightMapColor, ao, normal, emissive, alpha); + readMatParamsAndTextures(tbnMat, vViewDir, albedo, Metallic, Roughness, specularColor, glossiness, lightMapColor, ao, normal, emissive, alpha); - applyAllBlendEffects(albedo, normal, Roughness, Metallic, ao, emissive, glossiness, newTexCoord, wPosition, norm, tbnMat); + applyAllBlendEffects(albedo, normal, Roughness, Metallic, ao, emissive, glossiness, newTexCoord, scaledModelPos.xyz, modelNorm, tbnMat); // Lighting calculation: - // vec3 finalLightingValue = calculatePBRLighting(albedo, Metallic, Roughness, specularColor, glossiness, lightMapColor, ao, indoorSunLightExposure, normal, norm, viewDir); - vec3 finalLightingValue = calculatePBRLighting(); - - gl_FragColor.rgb += finalLightingValue; + vec3 finalLightingValue = calculatePBRLighting(albedo, Metallic, Roughness, specularColor, glossiness, lightMapColor, ao, indoorSunLightExposure, normal, norm, viewDir); + + gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); + gl_FragColor.rgb += finalLightingValue.rgb; //apply final emissive value after lighting gl_FragColor += emissive; //no need for #ifdef check because emissive will be 0,0,0,0 if emissive vars werent defined. @@ -106,7 +151,5 @@ void main(){ else if(m_DebugValuesMode == 5){ gl_FragColor.rgb = vec3(emissive.rgb); } - #endif - - // gl_FragColor.rgb = vec3(normal); -} + #endif +} \ No newline at end of file diff --git a/src/main/resources/Shaders/PBRCharacters.vert b/src/main/resources/Shaders/PBRCharacters.vert index 8250b24..b09c744 100644 --- a/src/main/resources/Shaders/PBRCharacters.vert +++ b/src/main/resources/Shaders/PBRCharacters.vert @@ -40,12 +40,29 @@ varying vec4 wTangent; uniform vec3 g_CameraPosition; #endif +varying vec3 scaledModelPos; +varying vec4 modelPos; +varying vec3 modelNorm; + void main(){ vec4 modelSpacePos = vec4(inPosition, 1.0); vec3 modelSpaceNorm = inNormal; vec3 modelSpaceTan = inTangent.xyz; + modelNorm = modelSpaceNorm; + modelPos = modelSpacePos; + + float xTot, zTot, yTot; + + xTot = length(g_WorldMatrix[0]); + yTot = length(g_WorldMatrix[1]); + zTot = length(g_WorldMatrix[2]); + + vec3 scaleVec = vec3(xTot,yTot,zTot); + + scaledModelPos = modelPos.xyz * scaleVec; + #ifdef USE_VERTEX_COLORS_AS_SUN_INTENSITY vertColors = inColor; #endif