Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion src/scene/materials/lit-material-options-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class LitMaterialOptionsBuilder {

static updateMaterialOptions(litOptions, material) {
litOptions.separateAmbient = false; // store ambient light color in separate variable, instead of adding it to diffuse directly
litOptions.customFragmentShader = null;
litOptions.pixelSnap = material.pixelSnap;

litOptions.ambientSH = material.ambientSH;
Expand Down
1 change: 0 additions & 1 deletion src/scene/materials/standard-material-options-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ class StandardMaterialOptionsBuilder {

// LIT OPTIONS
options.litOptions.separateAmbient = false; // store ambient light color in separate variable, instead of adding it to diffuse directly
options.litOptions.customFragmentShader = stdMat.customFragmentShader;
options.litOptions.pixelSnap = stdMat.pixelSnap;

options.litOptions.ambientSH = !!stdMat.ambientSH;
Expand Down
12 changes: 12 additions & 0 deletions src/scene/shader-lib/chunks-wgsl/chunks-wgsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import litForwardDeclarationPS from './lit/frag/pass-forward/litForwardDeclarati
import litForwardMainPS from './lit/frag/pass-forward/litForwardMain.js';
import litForwardPostCodePS from './lit/frag/pass-forward/litForwardPostCode.js';
import litForwardPreCodePS from './lit/frag/pass-forward/litForwardPreCode.js';
import litMainPS from './lit/frag/litMain.js';
import litMainVS from './lit/vert/litMain.js';
import litOtherMainPS from './lit/frag/pass-other/litOtherMain.js';
import litShaderArgsPS from './standard/frag/litShaderArgs.js';
Expand Down Expand Up @@ -253,6 +254,8 @@ const shaderChunksWGSL = {
floatAsUintPS,
fogPS,
fresnelSchlickPS,
frontendCodePS: '', // empty chunk, supplied by the shader generator
frontendDeclPS: '', // empty chunk, supplied by the shader generator
fullscreenQuadVS,
gammaPS,
glossPS,
Expand Down Expand Up @@ -293,11 +296,20 @@ const shaderChunksWGSL = {
litForwardMainPS,
litForwardPostCodePS,
litForwardPreCodePS,
litMainPS,
litMainVS,
litOtherMainPS,
litShaderArgsPS,
litShaderCorePS,
litShadowMainPS,
litUserDeclarationPS: '', // empty chunk allowing user to add custom code
litUserDeclarationVS: '', // empty chunk allowing user to add custom code
litUserCodePS: '', // empty chunk allowing user to add custom code
litUserCodeVS: '', // empty chunk allowing user to add custom code
litUserMainStartPS: '', // empty chunk allowing user to add custom code
litUserMainStartVS: '', // empty chunk allowing user to add custom code
litUserMainEndPS: '', // empty chunk allowing user to add custom code
litUserMainEndVS: '', // empty chunk allowing user to add custom code
ltcPS,
metalnessPS,
metalnessModulatePS,
Expand Down
32 changes: 32 additions & 0 deletions src/scene/shader-lib/chunks-wgsl/lit/frag/litMain.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// main shader of the lit fragment shader
export default /* wgsl */`

#include "varyingsPS"
#include "litUserDeclarationPS"
#include "frontendDeclPS"

#if defined(PICK_PASS) || definde(PREPASS_PASS)

#include "frontendCodePS"
#include "litUserCodePS"
#include "litOtherMainPS"

#elif defined(SHADOW_PASS)

#include "frontendCodePS"
#include "litUserCodePS"
#include "litShadowMainPS"

#else // FORWARD_PASS

#include "litForwardDeclarationPS"
#include "litForwardPreCodePS"
#include "frontendCodePS"
#include "litForwardPostCodePS"
#include "litForwardBackendPS"
#include "litUserCodePS"
#include "litForwardMainPS"

#endif

`;
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export default /* wgsl */`
@fragment
fn fragmentMain(input: FragmentInput) -> FragmentOutput {

#include "litUserMainStartPS"

dReflection = vec4f(0.0);

#ifdef LIT_CLEARCOAT
Expand Down Expand Up @@ -45,6 +47,8 @@ fn fragmentMain(input: FragmentInput) -> FragmentOutput {

var output: FragmentOutput = evaluateBackend();

#include "litUserMainEndPS"

return output;
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export default /* wgsl */`

@fragment
fn fragmentMain(input: FragmentInput) -> FragmentOutput {

#include "litUserMainStartPS"

var output: FragmentOutput;

evaluateFrontend();
Expand All @@ -23,6 +26,8 @@ fn fragmentMain(input: FragmentInput) -> FragmentOutput {
output.color = float2vec4(vLinearDepth);
#endif

#include "litUserMainEndPS"

return output;
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ export default /* wgsl */`

@fragment
fn fragmentMain(input: FragmentInput) -> FragmentOutput {

#include "litUserMainStartPS"

var output: FragmentOutput;

evaluateFrontend();
Expand Down Expand Up @@ -57,6 +60,8 @@ fn fragmentMain(input: FragmentInput) -> FragmentOutput {
#endif
#endif

#include "litUserMainEndPS"

return output;
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,5 @@ fn addRefraction(
#endif
);
dDiffuseLight = mix(dDiffuseLight, refraction * transmittance * fresnel, transmission);
}`;
}
`;
12 changes: 12 additions & 0 deletions src/scene/shader-lib/chunks-wgsl/lit/vert/litMain.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// main shader of the lit vertex shader
export default /* wgsl */`

#include "varyingsVS"

#include "litUserDeclarationVS"

#ifdef VERTEX_COLOR
attribute vertex_color: vec4f;
#endif
Expand Down Expand Up @@ -59,8 +64,13 @@ var<private> dModelMatrix: mat4x4f;
#include "msdfVS"
#endif

#include "litUserCodeVS"

@vertex
fn vertexMain(input : VertexInput) -> VertexOutput {

#include "litUserMainStartVS"

var output : VertexOutput;
output.position = getPosition();
output.vPositionW = getWorldPosition();
Expand Down Expand Up @@ -116,6 +126,8 @@ fn vertexMain(input : VertexInput) -> VertexOutput {
output.vTiledUv = dTiledUvGlobal;
#endif

#include "litUserMainEndVS"

return output;
}
`;
14 changes: 14 additions & 0 deletions src/scene/shader-lib/chunks/chunks.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ import litForwardDeclarationPS from './lit/frag/pass-forward/litForwardDeclarati
import litForwardMainPS from './lit/frag/pass-forward/litForwardMain.js';
import litForwardPostCodePS from './lit/frag/pass-forward/litForwardPostCode.js';
import litForwardPreCodePS from './lit/frag/pass-forward/litForwardPreCode.js';
import litMainPS from './lit/frag/litMain.js';
import litMainVS from './lit/vert/litMain.js';
import litOtherMainPS from './lit/frag/pass-other/litOtherMain.js';
import litShaderArgsPS from './standard/frag/litShaderArgs.js';
Expand Down Expand Up @@ -258,6 +259,8 @@ const shaderChunks = {
floatAsUintPS,
fogPS,
fresnelSchlickPS,
frontendCodePS: '', // empty chunk, supplied by the shader generator
frontendDeclPS: '', // empty chunk, supplied by the shader generator
fullscreenQuadVS,
gammaPS,
gles3PS,
Expand Down Expand Up @@ -303,11 +306,20 @@ const shaderChunks = {
litForwardMainPS,
litForwardPostCodePS,
litForwardPreCodePS,
litMainPS,
litMainVS,
litOtherMainPS,
litShaderArgsPS,
litShaderCorePS,
litShadowMainPS,
litUserDeclarationPS: '', // empty chunk allowing user to add custom code
litUserDeclarationVS: '', // empty chunk allowing user to add custom code
litUserCodePS: '', // empty chunk allowing user to add custom code
litUserCodeVS: '', // empty chunk allowing user to add custom code
litUserMainStartPS: '', // empty chunk allowing user to add custom code
litUserMainStartVS: '', // empty chunk allowing user to add custom code
litUserMainEndPS: '', // empty chunk allowing user to add custom code
litUserMainEndVS: '', // empty chunk allowing user to add custom code
ltcPS,
metalnessPS,
metalnessModulatePS,
Expand Down Expand Up @@ -423,6 +435,8 @@ const shaderChunks = {
uvTransformVS,
uvTransformUniformsPS,
viewDirPS,
varyingsPS: '', // empty chunk, supplied by the shader generator
varyingsVS: '', // empty chunk, supplied by the shader generator
webgpuPS,
webgpuVS
};
Expand Down
32 changes: 32 additions & 0 deletions src/scene/shader-lib/chunks/lit/frag/litMain.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// main shader of the lit fragment shader
export default /* glsl */`

#include "varyingsPS"
#include "litUserDeclarationPS"
#include "frontendDeclPS"

#if defined(PICK_PASS) || definde(PREPASS_PASS)

#include "frontendCodePS"
#include "litUserCodePS"
#include "litOtherMainPS"

#elif defined(SHADOW_PASS)

#include "frontendCodePS"
#include "litUserCodePS"
#include "litShadowMainPS"

#else // FORWARD_PASS

#include "litForwardDeclarationPS"
#include "litForwardPreCodePS"
#include "frontendCodePS"
#include "litForwardPostCodePS"
#include "litForwardBackendPS"
#include "litUserCodePS"
#include "litForwardMainPS"

#endif

`;
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
export default /* glsl */`

void main(void) {

#include "litUserMainStartPS"

dReflection = vec4(0);

#ifdef LIT_CLEARCOAT
Expand Down Expand Up @@ -42,5 +45,7 @@ void main(void) {
#include "debugProcessFrontendPS"

evaluateBackend();

#include "litUserMainEndPS"
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export default /* glsl */`
#endif

void main(void) {

#include "litUserMainStartPS"

evaluateFrontend();

#ifdef PICK_PASS
Expand All @@ -19,5 +22,7 @@ void main(void) {
#ifdef PREPASS_PASS
gl_FragColor = float2vec4(vLinearDepth);
#endif

#include "litUserMainEndPS"
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export default /* glsl */`
#endif

void main(void) {

#include "litUserMainStartPS"

evaluateFrontend();

// using non-standard depth, i.e gl_FragCoord.z
Expand Down Expand Up @@ -53,5 +56,7 @@ void main(void) {
gl_FragColor = vec4(1.0);
#endif
#endif

#include "litUserMainEndPS"
}
`;
12 changes: 12 additions & 0 deletions src/scene/shader-lib/chunks/lit/vert/litMain.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// main shader of the lit vertex shader
export default /* glsl */`

#include "varyingsVS"

#include "litUserDeclarationVS"

#ifdef VERTEX_COLOR
attribute vec4 vertex_color;
#endif
Expand Down Expand Up @@ -56,7 +61,12 @@ mat4 dModelMatrix;
#include "msdfVS"
#endif

#include "litUserCodeVS"

void main(void) {

#include "litUserMainStartVS"

gl_Position = getPosition();
vPositionW = getWorldPosition();

Expand Down Expand Up @@ -100,5 +110,7 @@ void main(void) {
#ifdef MSDF
unpackMsdfParams();
#endif

#include "litUserMainEndVS"
}
`;
7 changes: 0 additions & 7 deletions src/scene/shader-lib/programs/lit-shader-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,6 @@ class LitShaderOptions {

diffuseMapEnabled = false;

/**
* Replaced the whole fragment shader with this string.
*
* @type {string}
*/
customFragmentShader = null;

pixelSnap = false;

/**
Expand Down
Loading