Skip to content

Commit

Permalink
PBRCharacter: update frag + vert
Browse files Browse the repository at this point in the history
  • Loading branch information
capdevon committed Feb 24, 2024
1 parent d01eba8 commit 4879efb
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 24 deletions.
91 changes: 67 additions & 24 deletions src/main/resources/Shaders/PBRCharacters.frag
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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.
Expand All @@ -106,7 +151,5 @@ void main(){
else if(m_DebugValuesMode == 5){
gl_FragColor.rgb = vec3(emissive.rgb);
}
#endif

// gl_FragColor.rgb = vec3(normal);
}
#endif
}
17 changes: 17 additions & 0 deletions src/main/resources/Shaders/PBRCharacters.vert
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4879efb

Please sign in to comment.