Skip to content

Commit cf495a7

Browse files
author
Martin Valigursky
committed
Final refactor of standard shader generator - shader code moved to chunks
1 parent fee1bae commit cf495a7

File tree

10 files changed

+450
-524
lines changed

10 files changed

+450
-524
lines changed

examples/src/examples/graphics/normals-and-tangents.example.mjs

+1-7
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,6 @@ assetListLoader.load(() => {
6868
leftEntity.setLocalScale(0.8, 0.8, 0.8);
6969
app.root.addChild(leftEntity);
7070

71-
const rightEntity = assets.model.resource.instantiateRenderEntity();
72-
rightEntity.setLocalEulerAngles(0, 90, 0);
73-
rightEntity.setPosition(0, 0, -1);
74-
rightEntity.setLocalScale(-0.8, -0.8, -0.8);
75-
app.root.addChild(rightEntity);
76-
7771
// Create a camera with an orbit camera script
7872
const camera = new pc.Entity();
7973
camera.addComponent('camera', {
@@ -90,7 +84,7 @@ assetListLoader.load(() => {
9084
app.root.addChild(camera);
9185
camera.script.orbitCamera.pitch = 0;
9286
camera.script.orbitCamera.yaw = 90;
93-
camera.script.orbitCamera.distance = 4;
87+
camera.script.orbitCamera.distance = 3;
9488

9589
const directionalLight = new pc.Entity();
9690
directionalLight.addComponent('light', {

src/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ export { LitShaderOptions } from './scene/shader-lib/programs/lit-shader-options
229229
export { ProgramLibrary } from './scene/shader-lib/program-library.js';
230230
export { shaderChunks } from './scene/shader-lib/chunks/chunks.js';
231231
export { shaderChunksLightmapper } from './scene/shader-lib/chunks/chunks-lightmapper.js';
232-
export { ChunkBuilder } from './scene/shader-lib/chunk-builder.js'; // used by shed
233232
export { ChunkUtils } from './scene/shader-lib/chunk-utils.js';
234233

235234
// SCENE / SKY

src/scene/shader-lib/chunk-builder.js

-27
This file was deleted.

src/scene/shader-lib/chunks-wgsl/chunks-wgsl.js

+4
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ import sphericalPS from './common/frag/spherical.js';
172172
// import spotPS from './lit/frag/spot.js';
173173
// import startNineSlicedPS from './lit/frag/startNineSliced.js';
174174
// import startNineSlicedTiledPS from './lit/frag/startNineSlicedTiled.js';
175+
// import stdDeclarationPS from './standard/frag/stdDeclaration.js';
176+
// import stdFrontEndPS from './standard/frag/stdFrontEnd.js';
175177
// import tangentBinormalVS from './lit/vert/tangentBinormal.js';
176178
// import TBNPS from './lit/frag/TBN.js';
177179
// import thicknessPS from './standard/frag/thickness.js';
@@ -379,6 +381,8 @@ const shaderChunksWGSL = {
379381
// spotPS,
380382
// startNineSlicedPS,
381383
// startNineSlicedTiledPS,
384+
// stdDeclarationPS,
385+
// stdFrontEndPS,
382386
// tangentBinormalVS,
383387
// TBNPS,
384388
// thicknessPS,

src/scene/shader-lib/chunks/chunks.js

+4
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ import specularityFactorPS from './standard/frag/specularityFactor.js';
175175
import spotPS from './lit/frag/spot.js';
176176
import startNineSlicedPS from './lit/frag/startNineSliced.js';
177177
import startNineSlicedTiledPS from './lit/frag/startNineSlicedTiled.js';
178+
import stdDeclarationPS from './standard/frag/stdDeclaration.js';
179+
import stdFrontEndPS from './standard/frag/stdFrontEnd.js';
178180
import tangentBinormalVS from './lit/vert/tangentBinormal.js';
179181
import TBNPS from './lit/frag/TBN.js';
180182
import thicknessPS from './standard/frag/thickness.js';
@@ -384,6 +386,8 @@ const shaderChunks = {
384386
spotPS,
385387
startNineSlicedPS,
386388
startNineSlicedTiledPS,
389+
stdDeclarationPS,
390+
stdFrontEndPS,
387391
tangentBinormalVS,
388392
TBNPS,
389393
thicknessPS,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
// Declaration part of the standard shader. Declares the uniforms, textures and global variables used
2+
// by the fragment shader of the standard shader.
3+
export default /* glsl */`
4+
5+
// global texture bias for standard textures
6+
#if LIT_NONE_SLICE_MODE == TILED
7+
const float textureBias = -1000.0;
8+
#else
9+
uniform float textureBias;
10+
#endif
11+
12+
// globals
13+
float dAlpha = 1.0;
14+
15+
#if defined(LIT_ALPHA_TEST)
16+
#include "alphaTestPS"
17+
#endif
18+
19+
// dithering
20+
#if STD_OPACITY_DITHER != NONE
21+
#include "opacityDitherPS"
22+
#endif
23+
24+
#ifdef FORWARD_PASS // ----------------
25+
26+
// globals
27+
vec3 dAlbedo;
28+
vec3 dNormalW;
29+
vec3 dSpecularity = vec3(0.0);
30+
float dGlossiness = 0.0;
31+
32+
#ifdef LIT_REFRACTION
33+
float dTransmission;
34+
float dThickness;
35+
#endif
36+
37+
#ifdef LIT_SCENE_COLOR
38+
uniform sampler2D uSceneColorMap;
39+
#endif
40+
41+
#ifdef LIT_SCREEN_SIZE
42+
uniform vec4 uScreenSize;
43+
#endif
44+
45+
#ifdef LIT_TRANSFORMS
46+
uniform mat4 matrix_viewProjection;
47+
uniform mat4 matrix_model;
48+
#endif
49+
50+
// parallax
51+
#ifdef STD_HEIGHT_MAP
52+
vec2 dUvOffset;
53+
#ifdef STD_DIFFUSE_TEXTURE_ALLOCATE
54+
uniform sampler2D texture_heightMap;
55+
#endif
56+
#endif
57+
58+
// diffuse
59+
#ifdef STD_DIFFUSE_TEXTURE_ALLOCATE
60+
uniform sampler2D texture_diffuseMap;
61+
#endif
62+
63+
#ifdef STD_DIFFUSEDETAIL_TEXTURE_ALLOCATE
64+
uniform sampler2D texture_diffuseDetailMap;
65+
#endif
66+
67+
// normal
68+
#ifdef STD_NORMAL_TEXTURE_ALLOCATE
69+
uniform sampler2D texture_normalMap;
70+
#endif
71+
72+
#ifdef STD_NORMALDETAIL_TEXTURE_ALLOCATE
73+
uniform sampler2D texture_normalDetailMap;
74+
#endif
75+
76+
// refraction
77+
#ifdef STD_THICKNESS_TEXTURE_ALLOCATE
78+
uniform sampler2D texture_thicknessMap;
79+
#endif
80+
#ifdef STD_REFRACTION_TEXTURE_ALLOCATE
81+
uniform sampler2D texture_refractionMap;
82+
#endif
83+
84+
// iridescence
85+
#ifdef LIT_IRIDESCENCE
86+
float dIridescence;
87+
float dIridescenceThickness;
88+
89+
#ifdef STD_IRIDESCENCE_THICKNESS_TEXTURE_ALLOCATE
90+
uniform sampler2D texture_iridescenceThicknessMap;
91+
#endif
92+
#ifdef STD_IRIDESCENCE_TEXTURE_ALLOCATE
93+
uniform sampler2D texture_iridescenceMap;
94+
#endif
95+
#endif
96+
97+
#ifdef LIT_CLEARCOAT
98+
float ccSpecularity;
99+
float ccGlossiness;
100+
vec3 ccNormalW;
101+
#endif
102+
103+
// specularity & glossiness
104+
#ifdef LIT_SPECULAR_OR_REFLECTION
105+
106+
// sheen
107+
#ifdef LIT_SHEEN
108+
vec3 sSpecularity;
109+
float sGlossiness;
110+
111+
#ifdef STD_SHEEN_TEXTURE_ALLOCATE
112+
uniform sampler2D texture_sheenMap;
113+
#endif
114+
#ifdef STD_SHEENGLOSS_TEXTURE_ALLOCATE
115+
uniform sampler2D texture_sheenGlossMap;
116+
#endif
117+
#endif
118+
119+
// metalness
120+
#ifdef LIT_METALNESS
121+
float dMetalness;
122+
float dIor;
123+
124+
#ifdef STD_METALNESS_TEXTURE_ALLOCATE
125+
uniform sampler2D texture_metalnessMap;
126+
#endif
127+
#endif
128+
129+
// specularity factor
130+
#ifdef LIT_SPECULARITY_FACTOR
131+
float dSpecularityFactor;
132+
133+
#ifdef STD_SPECULARITYFACTOR_TEXTURE_ALLOCATE
134+
uniform sampler2D texture_specularityFactorMap;
135+
#endif
136+
#endif
137+
138+
// specular color
139+
#ifdef STD_SPECULAR_COLOR
140+
#ifdef STD_SPECULAR_TEXTURE_ALLOCATE
141+
uniform sampler2D texture_specularMap;
142+
#endif
143+
#endif
144+
145+
// gloss
146+
#ifdef STD_GLOSS_TEXTURE_ALLOCATE
147+
uniform sampler2D texture_glossMap;
148+
#endif
149+
#endif
150+
151+
// ao
152+
#ifdef STD_AO
153+
float dAo;
154+
#ifdef STD_AO_TEXTURE_ALLOCATE
155+
uniform sampler2D texture_aoMap;
156+
#endif
157+
#ifdef STD_AODETAIL_TEXTURE_ALLOCATE
158+
uniform sampler2D texture_aoDetailMap;
159+
#endif
160+
#endif
161+
162+
// emission
163+
vec3 dEmission;
164+
#ifdef STD_EMISSIVE_TEXTURE_ALLOCATE
165+
uniform sampler2D texture_emissiveMap;
166+
#endif
167+
168+
// clearcoat
169+
#ifdef LIT_CLEARCOAT
170+
#ifdef STD_CLEARCOAT_TEXTURE_ALLOCATE
171+
uniform sampler2D texture_clearCoatMap;
172+
#endif
173+
#ifdef STD_CLEARCOATGLOSS_TEXTURE_ALLOCATE
174+
uniform sampler2D texture_clearCoatGlossMap;
175+
#endif
176+
#ifdef STD_CLEARCOATNORMAL_TEXTURE_ALLOCATE
177+
uniform sampler2D texture_clearCoatNormalMap;
178+
#endif
179+
#endif
180+
181+
// lightmap
182+
#if defined(STD_LIGHTMAP) || defined(STD_LIGHT_VERTEX_COLOR)
183+
vec3 dLightmap;
184+
#ifdef STD_LIGHT_TEXTURE_ALLOCATE
185+
uniform sampler2D texture_lightMap;
186+
#endif
187+
#endif
188+
#endif
189+
190+
// front end outputs to lit shader
191+
#include "litShaderArgsPS"
192+
`;

0 commit comments

Comments
 (0)