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

Modularize PBRLighting.frag #2191

Merged
merged 27 commits into from
Jan 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
67cdede
Modularize PBRLighting
yaRnMcDonuts Feb 2, 2024
9470129
uploade both .glslibs
yaRnMcDonuts Feb 2, 2024
fd30ef4
Update PBRLighting.frag
yaRnMcDonuts Feb 3, 2024
dfa150f
Update PBRLighting.glsllib
yaRnMcDonuts Feb 3, 2024
801d3d6
Update PBRLightingParamReads.glsllib
yaRnMcDonuts Feb 3, 2024
da43265
Update PBRLighting.vert
yaRnMcDonuts Feb 3, 2024
458e3bd
Update PBRLighting.j3md
yaRnMcDonuts Feb 3, 2024
0215675
Update PBRLightingParamReads.glsllib
yaRnMcDonuts Feb 4, 2024
6d29bbb
Update and rename PBRLightingParamReads.glsllib to PBRLightingParamsR…
yaRnMcDonuts Feb 5, 2024
436e7da
Update path for shader lib imports
yaRnMcDonuts Feb 5, 2024
05f61b2
Fix typos in documentation
yaRnMcDonuts Feb 5, 2024
cb3f8a1
Update PBRLighting.frag
yaRnMcDonuts Feb 5, 2024
1ae4b34
Update PBRLighting.j3md
yaRnMcDonuts Feb 5, 2024
6bb4f6a
remove 2 more unused vars
yaRnMcDonuts Feb 7, 2024
191f8cb
Update PBRLighting.frag
yaRnMcDonuts Feb 8, 2024
65bd8e7
Update PBRLightingParamsReader.glsllib
yaRnMcDonuts Feb 8, 2024
0eaceb5
Update PBRLighting.frag
yaRnMcDonuts Feb 14, 2024
e3db2a3
Struct pre-preprocessor directive
riccardobl Mar 7, 2024
f0fbf7a
Modular PBR
riccardobl Mar 7, 2024
35532e0
Revert "Modularize PBRLighting"
riccardobl Mar 8, 2024
0ee174f
Merge branch 'modularpbr2' into patch-3
riccardobl Mar 8, 2024
a606ac1
fixes
riccardobl Mar 8, 2024
585e1ec
use modular pbr
riccardobl Mar 8, 2024
56c1ed0
Update GLSLCompat.glsllib
yaRnMcDonuts Oct 26, 2024
96328ae
Update GLSLCompat.glsllib
yaRnMcDonuts Oct 26, 2024
771592c
Update GLSLCompat.glsllib
yaRnMcDonuts Oct 26, 2024
92d4563
Merge branch 'master' into patch-3
yaRnMcDonuts Oct 28, 2024
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
@@ -0,0 +1,73 @@
#import "Common/ShaderLib/GLSLCompat.glsllib"

// enable apis and import PBRLightingUtils
#define ENABLE_PBRLightingUtils_getWorldPosition 1
#define ENABLE_PBRLightingUtils_getWorldNormal 1
#define ENABLE_PBRLightingUtils_getWorldTangent 1
#define ENABLE_PBRLightingUtils_getTexCoord 1
#define ENABLE_PBRLightingUtils_readPBRSurface 1
#define ENABLE_PBRLightingUtils_computeDirectLightContribution 1
#define ENABLE_PBRLightingUtils_computeProbesContribution 1

#import "Common/ShaderLib/module/pbrlighting/PBRLightingUtils.glsllib"

#ifdef DEBUG_VALUES_MODE
uniform int m_DebugValuesMode;
#endif

uniform vec4 g_LightData[NB_LIGHTS];
uniform vec3 g_CameraPosition;

void main(){
vec3 wpos = PBRLightingUtils_getWorldPosition();
vec3 worldViewDir = normalize(g_CameraPosition - wpos);

// Load surface data
PBRSurface surface=PBRLightingUtils_readPBRSurface(worldViewDir);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add spaces around =


// Calculate direct lights
for(int i = 0;i < NB_LIGHTS; i+=3){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add spacing: for (int i = 0; i < NB_LIGHTS; i += 3) {

vec4 lightData0 = g_LightData[i];
vec4 lightData1 = g_LightData[i+1];
vec4 lightData2 = g_LightData[i+2];
PBRLightingUtils_computeDirectLightContribution(
lightData0, lightData1, lightData2,
surface
);
}


// Calculate env probes
PBRLightingUtils_computeProbesContribution(surface);

// Put it all together
gl_FragColor.rgb = vec3(0.0);
gl_FragColor.rgb += surface.bakedLightContribution;
gl_FragColor.rgb += surface.directLightContribution;
gl_FragColor.rgb += surface.envLightContribution;
gl_FragColor.rgb += surface.emission;
gl_FragColor.a = surface.alpha;


// outputs the final value of the selected layer as a color for debug purposes.
#ifdef DEBUG_VALUES_MODE
if(m_DebugValuesMode == 0){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add spaces: if (m_DebugValuesMode == n) { for each if statement.

gl_FragColor.rgb = vec3(surface.albedo);
}
else if(m_DebugValuesMode == 1){
gl_FragColor.rgb = vec3(surface.normal);
}
else if(m_DebugValuesMode == 2){
gl_FragColor.rgb = vec3(surface.roughness);
}
else if(m_DebugValuesMode == 3){
gl_FragColor.rgb = vec3(surface.metallic);
}
else if(m_DebugValuesMode == 4){
gl_FragColor.rgb = surface.ao.rgb;
}
else if(m_DebugValuesMode == 5){
gl_FragColor.rgb = vec3(surface.emission.rgb);
}
#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this debug block be moved to a glsllib?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately I do not think this code can be moved. I recall trying moving that code in the past, but it appeared that any references to "gl_FragColor" need to be in the main .frag file

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'll take your word for it. It isn't important anyway.

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,321 @@
MaterialDef PBR Lighting {

MaterialParameters {
Int BoundDrawBuffer

// Alpha threshold for fragment discarding
Float AlphaDiscardThreshold (AlphaTestFallOff)

//metallicity of the material
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See about removing redundant comments to make the parameters more neat and easier to read.

Float Metallic : 1.0
//Roughness of the material
Float Roughness : 1.0
// Base material color
Color BaseColor : 1.0 1.0 1.0 1.0
// The emissive color of the object
Color Emissive
// the emissive power
Float EmissivePower : 3.0
// the emissive intensity
Float EmissiveIntensity : 2.0

// BaseColor map
Texture2D BaseColorMap

// Metallic map
Texture2D MetallicMap -LINEAR

// Roughness Map
Texture2D RoughnessMap -LINEAR

//Metallic and Roughness are packed respectively in the b and g channel of a single map
// r: AO (if AoPackedInMRMap is true)
// g: Roughness
// b: Metallic
Texture2D MetallicRoughnessMap -LINEAR

// Texture of the emissive parts of the material
Texture2D EmissiveMap

// Normal map
Texture2D NormalMap -LINEAR
// The scalar parameter applied to each normal vector of the normal map
Float NormalScale

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

// 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

// Parallax/height map
Texture2D ParallaxMap -LINEAR

// 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.
Float SpecularAASigma
// clamping threshold,Use the slider to set a maximum value for the offset that HDRP subtracts from the smoothness value to reduce artifacts.
Float SpecularAAKappa

//Set to true if parallax map is stored in the alpha channel of the normal map
Boolean PackedNormalParallax

//Sets the relief height for parallax mapping
Float ParallaxHeight : 0.05

//Set to true to activate Steep Parallax mapping
Boolean SteepParallax

//Horizon fade
Boolean HorizonFade

// Set to Use Lightmap
Texture2D LightMap

// A scalar multiplier controlling the amount of occlusion applied.
// A value of `0.0` means no occlusion. A value of `1.0` means full occlusion.
Float AoStrength

// Set to use TexCoord2 for the lightmap sampling
Boolean SeparateTexCoord
// the light map is a grayscale ao map, only the r channel will be read.
Boolean LightMapAsAOMap
Boolean AoPackedInMRMap
//shadows
Int FilterMode
Boolean HardwareShadows

Texture2D ShadowMap0
Texture2D ShadowMap1
Texture2D ShadowMap2
Texture2D ShadowMap3
//pointLights
Texture2D ShadowMap4
Texture2D ShadowMap5

Float ShadowIntensity
Vector4 Splits
Vector2 FadeInfo

Matrix4 LightViewProjectionMatrix0
Matrix4 LightViewProjectionMatrix1
Matrix4 LightViewProjectionMatrix2
Matrix4 LightViewProjectionMatrix3
//pointLight
Matrix4 LightViewProjectionMatrix4
Matrix4 LightViewProjectionMatrix5
Vector3 LightPos
Vector3 LightDir

Float PCFEdge
Float ShadowMapSize

// For hardware skinning
Int NumberOfBones
Matrix4Array BoneMatrices

// For Morph animation
FloatArray MorphWeights
Int NumberOfMorphTargets
Int NumberOfTargetsBuffers

// For instancing
Boolean UseInstancing

// For Vertex Color
Boolean UseVertexColor

Boolean BackfaceShadows : false

Boolean UseVertexColorsAsSunIntensity
Float StaticSunIntensity
Boolean BrightenIndoorShadows

Int DebugValuesMode
// debugs the final value of the selected layer as a color output:
// Layers:
// 0 - albedo (unshaded)
// 1 - normals
// 2 - roughness
// 3 - metallic
// 4 - ao
// 5 - emissive
}

Technique {
LightMode SinglePassAndImageBased

VertexShader GLSL300 GLSL150 GLSL110: Common/MatDefs/Light/modular/PBRLighting.vert
FragmentShader GLSL300 GLSL150 GLSL110: Common/MatDefs/Light/modular/PBRLighting.frag

WorldParameters {
WorldViewProjectionMatrix
CameraPosition
WorldMatrix
WorldNormalMatrix
ViewProjectionMatrix
ViewMatrix
}

Defines {
BOUND_DRAW_BUFFER: BoundDrawBuffer
BASECOLORMAP : BaseColorMap
NORMALMAP : NormalMap
NORMALSCALE : NormalScale
METALLICMAP : MetallicMap
ROUGHNESSMAP : RoughnessMap
EMISSIVEMAP : EmissiveMap
EMISSIVE : Emissive
SPECGLOSSPIPELINE : UseSpecGloss
PARALLAXMAP : ParallaxMap
NORMALMAP_PARALLAX : PackedNormalParallax
STEEP_PARALLAX : SteepParallax
LIGHTMAP : LightMap
SEPARATE_TEXCOORD : SeparateTexCoord
DISCARD_ALPHA : AlphaDiscardThreshold
NUM_BONES : NumberOfBones
INSTANCING : UseInstancing
USE_PACKED_MR: MetallicRoughnessMap
USE_PACKED_SG: SpecularGlossinessMap
SPECULARMAP : SpecularMap
SPECULAR_AA : UseSpecularAA
SPECULAR_AA_SCREEN_SPACE_VARIANCE : SpecularAASigma
SPECULAR_AA_THRESHOLD : SpecularAAKappa
GLOSSINESSMAP : GlossinessMap
NORMAL_TYPE: NormalType
VERTEX_COLOR : UseVertexColor
AO_MAP: LightMapAsAOMap
AO_PACKED_IN_MR_MAP : AoPackedInMRMap
AO_STRENGTH : AoStrength
NUM_MORPH_TARGETS: NumberOfMorphTargets
NUM_TARGETS_BUFFERS: NumberOfTargetsBuffers
HORIZON_FADE: HorizonFade
USE_VERTEX_COLORS_AS_SUN_INTENSITY : UseVertexColorsAsSunIntensity
STATIC_SUN_INTENSITY : StaticSunIntensity
BRIGHTEN_INDOOR_SHADOWS : BrightenIndoorShadows
DEBUG_VALUES_MODE : DebugValuesMode
}
}


Technique PreShadow {

VertexShader GLSL300 GLSL150 GLSL100: Common/MatDefs/Shadow/PreShadow.vert
FragmentShader GLSL300 GLSL150 GLSL100: Common/MatDefs/Shadow/PreShadowPBR.frag

WorldParameters {
WorldViewProjectionMatrix
WorldViewMatrix
ViewProjectionMatrix
ViewMatrix
}

Defines {
BOUND_DRAW_BUFFER: BoundDrawBuffer
DISCARD_ALPHA : AlphaDiscardThreshold
NUM_BONES : NumberOfBones
INSTANCING : UseInstancing
NUM_MORPH_TARGETS: NumberOfMorphTargets
NUM_TARGETS_BUFFERS: NumberOfTargetsBuffers
}

ForcedRenderState {
FaceCull Off
DepthTest On
DepthWrite On
PolyOffset 5 3
ColorWrite Off
}

}


Technique PostShadow {
VertexShader GLSL310 GLSL300 GLSL150 GLSL100: Common/MatDefs/Shadow/PostShadow.vert
FragmentShader GLSL310 GLSL300 GLSL150 GLSL100: Common/MatDefs/Shadow/PostShadowPBR.frag

WorldParameters {
WorldViewProjectionMatrix
WorldMatrix
ViewProjectionMatrix
ViewMatrix
}

Defines {
BOUND_DRAW_BUFFER: BoundDrawBuffer
HARDWARE_SHADOWS : HardwareShadows
FILTER_MODE : FilterMode
PCFEDGE : PCFEdge
DISCARD_ALPHA : AlphaDiscardThreshold
SHADOWMAP_SIZE : ShadowMapSize
FADE : FadeInfo
PSSM : Splits
POINTLIGHT : LightViewProjectionMatrix5
NUM_BONES : NumberOfBones
INSTANCING : UseInstancing
BACKFACE_SHADOWS: BackfaceShadows
NUM_MORPH_TARGETS: NumberOfMorphTargets
NUM_TARGETS_BUFFERS: NumberOfTargetsBuffers
}

ForcedRenderState {
Blend Modulate
DepthWrite Off
PolyOffset -0.1 0
}
}

Technique PreNormalPass {

VertexShader GLSL300 GLSL150 GLSL100 : Common/MatDefs/SSAO/normal.vert
FragmentShader GLSL300 GLSL150 GLSL100 : Common/MatDefs/SSAO/normal.frag

WorldParameters {
WorldViewProjectionMatrix
WorldViewMatrix
NormalMatrix
ViewProjectionMatrix
ViewMatrix
}

Defines {
BOUND_DRAW_BUFFER: BoundDrawBuffer
BASECOLORMAP_ALPHA : BaseColorMap
NUM_BONES : NumberOfBones
INSTANCING : UseInstancing
NUM_MORPH_TARGETS: NumberOfMorphTargets
NUM_TARGETS_BUFFERS: NumberOfTargetsBuffers
}

}

Technique Glow {

VertexShader GLSL300 GLSL150 GLSL100: Common/MatDefs/Misc/Unshaded.vert
FragmentShader GLSL300 GLSL150 GLSL100: Common/MatDefs/Light/PBRGlow.frag

WorldParameters {
WorldViewProjectionMatrix
ViewProjectionMatrix
ViewMatrix
}

Defines {
HAS_EMISSIVEMAP : EmissiveMap
HAS_EMISSIVECOLOR : Emissive
BOUND_DRAW_BUFFER: BoundDrawBuffer
NEED_TEXCOORD1
NUM_BONES : NumberOfBones
INSTANCING : UseInstancing
NUM_MORPH_TARGETS: NumberOfMorphTargets
NUM_TARGETS_BUFFERS: NumberOfTargetsBuffers
}
}

}
Loading