@aura3d/rendering 1.5.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -2
- package/dist/ArchitecturalLighting.d.ts +35 -0
- package/dist/ArchitecturalLighting.d.ts.map +1 -0
- package/dist/ArchitecturalLighting.js +162 -0
- package/dist/ArchitecturalLighting.js.map +1 -0
- package/dist/ArchitecturalMaterialCatalog.d.ts +1 -1
- package/dist/ArchitecturalMaterialCatalog.d.ts.map +1 -1
- package/dist/ArchitecturalMaterialCatalog.js +1 -1
- package/dist/ArchitecturalMaterialCatalog.js.map +1 -1
- package/dist/ArchitecturalMeasurement.d.ts +27 -0
- package/dist/ArchitecturalMeasurement.d.ts.map +1 -0
- package/dist/ArchitecturalMeasurement.js +112 -0
- package/dist/ArchitecturalMeasurement.js.map +1 -0
- package/dist/CanonicalProductScene.d.ts +13 -0
- package/dist/CanonicalProductScene.d.ts.map +1 -0
- package/dist/CanonicalProductScene.js +78 -0
- package/dist/CanonicalProductScene.js.map +1 -0
- package/dist/CascadedShadowMaps.d.ts +1 -1
- package/dist/CascadedShadowMaps.d.ts.map +1 -1
- package/dist/CascadedShadowMaps.js +1 -1
- package/dist/CascadedShadowMaps.js.map +1 -1
- package/dist/DepthPass.d.ts +1 -1
- package/dist/DepthPass.d.ts.map +1 -1
- package/dist/DepthPass.js +2 -2
- package/dist/DepthPass.js.map +1 -1
- package/dist/EnvironmentBackgroundPass.d.ts +1 -1
- package/dist/EnvironmentBackgroundPass.d.ts.map +1 -1
- package/dist/EnvironmentBackgroundPass.js +2 -2
- package/dist/EnvironmentBackgroundPass.js.map +1 -1
- package/dist/EnvironmentPlatform.js +2 -2
- package/dist/EnvironmentPlatform.js.map +1 -1
- package/dist/ForwardPass.d.ts +1 -1
- package/dist/ForwardPass.d.ts.map +1 -1
- package/dist/ForwardPass.js +24 -10
- package/dist/ForwardPass.js.map +1 -1
- package/dist/Geometry.d.ts +2 -0
- package/dist/Geometry.d.ts.map +1 -1
- package/dist/Geometry.js +15 -0
- package/dist/Geometry.js.map +1 -1
- package/dist/InstancedPBRMaterial.js +1 -1
- package/dist/InstancedPBRMaterial.js.map +1 -1
- package/dist/InstancedUnlitMaterial.js +1 -1
- package/dist/InstancedUnlitMaterial.js.map +1 -1
- package/dist/Material.js +2 -2
- package/dist/Material.js.map +1 -1
- package/dist/MaterialBinding.js +4 -4
- package/dist/MaterialBinding.js.map +1 -1
- package/dist/MaterialInstance.js +2 -2
- package/dist/MaterialInstance.js.map +1 -1
- package/dist/MorphUnlitMaterial.js +1 -1
- package/dist/MorphUnlitMaterial.js.map +1 -1
- package/dist/NormalMappedPBRMaterial.js +1 -1
- package/dist/NormalMappedPBRMaterial.js.map +1 -1
- package/dist/OceanSurface.d.ts +62 -0
- package/dist/OceanSurface.d.ts.map +1 -0
- package/dist/OceanSurface.js +240 -0
- package/dist/OceanSurface.js.map +1 -0
- package/dist/PBRMaterial.d.ts.map +1 -1
- package/dist/PBRMaterial.js +3 -3
- package/dist/PBRMaterial.js.map +1 -1
- package/dist/PortableShaderMaterial.d.ts +60 -0
- package/dist/PortableShaderMaterial.d.ts.map +1 -0
- package/dist/PortableShaderMaterial.js +223 -0
- package/dist/PortableShaderMaterial.js.map +1 -0
- package/dist/PostProcessPass.d.ts.map +1 -1
- package/dist/PostProcessPass.js +30 -6
- package/dist/PostProcessPass.js.map +1 -1
- package/dist/ProceduralTexture.d.ts +27 -0
- package/dist/ProceduralTexture.d.ts.map +1 -0
- package/dist/ProceduralTexture.js +336 -0
- package/dist/ProceduralTexture.js.map +1 -0
- package/dist/ProductTurntable.d.ts +96 -0
- package/dist/ProductTurntable.d.ts.map +1 -0
- package/dist/ProductTurntable.js +639 -0
- package/dist/ProductTurntable.js.map +1 -0
- package/dist/RenderDevice.d.ts +30 -0
- package/dist/RenderDevice.d.ts.map +1 -1
- package/dist/RenderDevice.js.map +1 -1
- package/dist/Renderer.d.ts +3 -2
- package/dist/Renderer.d.ts.map +1 -1
- package/dist/Renderer.js +23 -9
- package/dist/Renderer.js.map +1 -1
- package/dist/RendererPostprocessPlan.js +4 -4
- package/dist/RendererPostprocessPlan.js.map +1 -1
- package/dist/ScreenSpaceLineMaterial.js +1 -1
- package/dist/ScreenSpaceLineMaterial.js.map +1 -1
- package/dist/ShaderChunks.d.ts.map +1 -1
- package/dist/ShaderChunks.js +81 -19
- package/dist/ShaderChunks.js.map +1 -1
- package/dist/ShaderLibrary.d.ts +2 -78
- package/dist/ShaderLibrary.d.ts.map +1 -1
- package/dist/ShaderLibrary.js +127 -793
- package/dist/ShaderLibrary.js.map +1 -1
- package/dist/ShaderLibraryCore.d.ts +100 -0
- package/dist/ShaderLibraryCore.d.ts.map +1 -0
- package/dist/ShaderLibraryCore.js +800 -0
- package/dist/ShaderLibraryCore.js.map +1 -0
- package/dist/ShaderModule.d.ts +1 -1
- package/dist/ShaderModule.d.ts.map +1 -1
- package/dist/ShaderModule.js +4 -2
- package/dist/ShaderModule.js.map +1 -1
- package/dist/ShadowPass.d.ts +1 -1
- package/dist/ShadowPass.d.ts.map +1 -1
- package/dist/ShadowPass.js +6 -4
- package/dist/ShadowPass.js.map +1 -1
- package/dist/SkinnedLitMaterial.js +1 -1
- package/dist/SkinnedLitMaterial.js.map +1 -1
- package/dist/SkinnedUnlitMaterial.js +1 -1
- package/dist/SkinnedUnlitMaterial.js.map +1 -1
- package/dist/SpaceEnvironment.d.ts +54 -0
- package/dist/SpaceEnvironment.d.ts.map +1 -0
- package/dist/SpaceEnvironment.js +116 -0
- package/dist/SpaceEnvironment.js.map +1 -0
- package/dist/TerrainHeightfield.d.ts +60 -0
- package/dist/TerrainHeightfield.d.ts.map +1 -0
- package/dist/TerrainHeightfield.js +239 -0
- package/dist/TerrainHeightfield.js.map +1 -0
- package/dist/TextureBinding.d.ts +14 -0
- package/dist/TextureBinding.d.ts.map +1 -1
- package/dist/TextureBinding.js +17 -0
- package/dist/TextureBinding.js.map +1 -1
- package/dist/TexturedPBRMaterial.js +1 -1
- package/dist/TexturedPBRMaterial.js.map +1 -1
- package/dist/TexturedUnlitMaterial.js +1 -1
- package/dist/TexturedUnlitMaterial.js.map +1 -1
- package/dist/UnlitMaterial.js +1 -1
- package/dist/UnlitMaterial.js.map +1 -1
- package/dist/VegetationFixtures.d.ts +1 -1
- package/dist/VegetationFixtures.d.ts.map +1 -1
- package/dist/VegetationFixtures.js +1 -1
- package/dist/VegetationFixtures.js.map +1 -1
- package/dist/VegetationScatter.d.ts +68 -0
- package/dist/VegetationScatter.d.ts.map +1 -0
- package/dist/VegetationScatter.js +241 -0
- package/dist/VegetationScatter.js.map +1 -0
- package/dist/VoxelWorld.d.ts +51 -0
- package/dist/VoxelWorld.d.ts.map +1 -0
- package/dist/VoxelWorld.js +183 -0
- package/dist/VoxelWorld.js.map +1 -0
- package/dist/Weather.d.ts +44 -0
- package/dist/Weather.d.ts.map +1 -0
- package/dist/Weather.js +140 -0
- package/dist/Weather.js.map +1 -0
- package/dist/WebGL2Device.d.ts +22 -0
- package/dist/WebGL2Device.d.ts.map +1 -1
- package/dist/WebGL2Device.js +134 -23
- package/dist/WebGL2Device.js.map +1 -1
- package/dist/WebGPUDevice.d.ts +19 -2
- package/dist/WebGPUDevice.d.ts.map +1 -1
- package/dist/WebGPUDevice.js +188 -9
- package/dist/WebGPUDevice.js.map +1 -1
- package/dist/index.d.ts +25 -32
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +35 -19
- package/dist/index.js.map +1 -1
- package/dist/lean/LeanProductRenderer.d.ts +29 -0
- package/dist/lean/LeanProductRenderer.d.ts.map +1 -0
- package/dist/lean/LeanProductRenderer.js +38 -0
- package/dist/lean/LeanProductRenderer.js.map +1 -0
- package/dist/lean/LeanProductionRenderer.d.ts +38 -0
- package/dist/lean/LeanProductionRenderer.d.ts.map +1 -0
- package/dist/lean/LeanProductionRenderer.js +88 -0
- package/dist/lean/LeanProductionRenderer.js.map +1 -0
- package/dist/lean-runtime.d.ts +18 -0
- package/dist/lean-runtime.d.ts.map +1 -0
- package/dist/lean-runtime.js +13 -0
- package/dist/lean-runtime.js.map +1 -0
- package/dist/postprocess/EffectComposer.d.ts.map +1 -1
- package/dist/postprocess/EffectComposer.js +1 -3
- package/dist/postprocess/EffectComposer.js.map +1 -1
- package/dist/production-runtime/PBRHDRPipeline.d.ts.map +1 -1
- package/dist/production-runtime/PBRHDRPipeline.js +5 -1
- package/dist/production-runtime/PBRHDRPipeline.js.map +1 -1
- package/dist/production-runtime/ProductionRendererTypes.d.ts +9 -0
- package/dist/production-runtime/ProductionRendererTypes.d.ts.map +1 -1
- package/dist/production-runtime/ProductionRendererTypes.js.map +1 -1
- package/dist/production-runtime/ProductionRuntimeRenderer.d.ts +5 -0
- package/dist/production-runtime/ProductionRuntimeRenderer.d.ts.map +1 -1
- package/dist/production-runtime/ProductionRuntimeRenderer.js +53 -5
- package/dist/production-runtime/ProductionRuntimeRenderer.js.map +1 -1
- package/dist/production-runtime/ProductionWebGL2Renderer.d.ts +10 -0
- package/dist/production-runtime/ProductionWebGL2Renderer.d.ts.map +1 -1
- package/dist/production-runtime/ProductionWebGL2Renderer.js +21 -2
- package/dist/production-runtime/ProductionWebGL2Renderer.js.map +1 -1
- package/dist/production-runtime/ProductionWebGPURenderer.d.ts.map +1 -1
- package/dist/production-runtime/ProductionWebGPURenderer.js +4 -1
- package/dist/production-runtime/ProductionWebGPURenderer.js.map +1 -1
- package/dist/webgpu-device-entry.d.ts +25 -0
- package/dist/webgpu-device-entry.d.ts.map +1 -0
- package/dist/webgpu-device-entry.js +24 -0
- package/dist/webgpu-device-entry.js.map +1 -0
- package/dist/webgpu.d.ts +25 -0
- package/dist/webgpu.d.ts.map +1 -0
- package/dist/webgpu.js +24 -0
- package/dist/webgpu.js.map +1 -0
- package/package.json +11 -3
package/dist/ShaderLibrary.js
CHANGED
|
@@ -1,691 +1,55 @@
|
|
|
1
|
-
import { ShaderPreprocessor } from "./ShaderPreprocessor.js";
|
|
2
|
-
import { DEFAULT_PBR_SHADER_MARKER, DEFAULT_PBR_SHADER_NAME } from "./PBRMaterial.js";
|
|
3
1
|
import { SHADER_CHUNKS, validateShaderChunks } from "./ShaderChunks.js";
|
|
4
2
|
import { registerAnimationToonShader } from "./animation/AnimationToonMaterial.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const fragment = this.preprocessor.preprocess(shader.fragment, preprocessOptions).source;
|
|
39
|
-
if (!vertex.includes(shader.marker) || !fragment.includes(shader.marker)) {
|
|
40
|
-
throw new Error(`Shader marker ${shader.marker} was not preserved for ${name}`);
|
|
41
|
-
}
|
|
42
|
-
return { label: name, marker: shader.marker, vertex, fragment };
|
|
43
|
-
}
|
|
44
|
-
compileVariant(name, variantName, options = {}) {
|
|
45
|
-
const shader = this.get(name);
|
|
46
|
-
const variant = shader.variants?.find((candidate) => candidate.name === variantName);
|
|
47
|
-
if (!variant) {
|
|
48
|
-
throw new Error(`Shader variant is not registered: ${name}:${variantName}`);
|
|
49
|
-
}
|
|
50
|
-
const compileOptions = {
|
|
51
|
-
...options,
|
|
52
|
-
defines: {
|
|
53
|
-
...(variant.defines ?? {}),
|
|
54
|
-
...(options.defines ?? {})
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
const cacheKey = variantCacheKey(name, variantName, compileOptions);
|
|
58
|
-
const cached = this.variantCache.get(cacheKey);
|
|
59
|
-
if (cached) {
|
|
60
|
-
return cached;
|
|
61
|
-
}
|
|
62
|
-
const compiled = this.compileSource(name, compileOptions);
|
|
63
|
-
const labeled = { ...compiled, label: `${name}:${variantName}` };
|
|
64
|
-
this.variantCache.set(cacheKey, labeled);
|
|
65
|
-
return labeled;
|
|
66
|
-
}
|
|
67
|
-
names() {
|
|
68
|
-
return [...this.shaders.keys()];
|
|
69
|
-
}
|
|
70
|
-
assertMarker(shader) {
|
|
71
|
-
if (!shader.marker.trim()) {
|
|
72
|
-
throw new Error(`Shader ${shader.name} must declare a non-empty source marker`);
|
|
73
|
-
}
|
|
74
|
-
if (!shader.vertex.includes(shader.marker) || !shader.fragment.includes(shader.marker)) {
|
|
75
|
-
throw new Error(`Shader ${shader.name} must include marker ${shader.marker} in both stages`);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
assertVariants(shader) {
|
|
79
|
-
const seen = new Set();
|
|
80
|
-
for (const variant of shader.variants ?? []) {
|
|
81
|
-
if (!variant.name.trim()) {
|
|
82
|
-
throw new Error(`Shader ${shader.name} has a variant with an empty name`);
|
|
83
|
-
}
|
|
84
|
-
if (seen.has(variant.name)) {
|
|
85
|
-
throw new Error(`Shader variant is already registered: ${shader.name}:${variant.name}`);
|
|
86
|
-
}
|
|
87
|
-
seen.add(variant.name);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
function variantCacheKey(name, variantName, options) {
|
|
92
|
-
return JSON.stringify({
|
|
93
|
-
name,
|
|
94
|
-
variantName,
|
|
95
|
-
defines: Object.entries(options.defines ?? {}).sort(([left], [right]) => left.localeCompare(right)),
|
|
96
|
-
includes: [...(options.includes ?? new Map()).entries()].sort(([left], [right]) => left.localeCompare(right))
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
export const DEFAULT_UNLIT_SHADER_NAME = "aura3d/unlit";
|
|
100
|
-
export const DEFAULT_UNLIT_SHADER_MARKER = "@aura3d-shader:unlit";
|
|
101
|
-
export const DEFAULT_INSTANCED_UNLIT_SHADER_NAME = "aura3d/instanced-unlit";
|
|
102
|
-
export const DEFAULT_INSTANCED_UNLIT_SHADER_MARKER = "@aura3d-shader:instanced-unlit";
|
|
103
|
-
export const DEFAULT_INSTANCED_PBR_SHADER_NAME = "aura3d/instanced-pbr";
|
|
104
|
-
export const DEFAULT_INSTANCED_PBR_SHADER_MARKER = "@aura3d-shader:instanced-pbr";
|
|
105
|
-
export const DEFAULT_TEXTURED_UNLIT_SHADER_NAME = "aura3d/textured-unlit";
|
|
106
|
-
export const DEFAULT_TEXTURED_UNLIT_SHADER_MARKER = "@aura3d-shader:textured-unlit";
|
|
107
|
-
export const DEFAULT_SKINNED_UNLIT_SHADER_NAME = "aura3d/skinned-unlit";
|
|
108
|
-
export const DEFAULT_SKINNED_UNLIT_SHADER_MARKER = "@aura3d-shader:skinned-unlit";
|
|
109
|
-
export const DEFAULT_SKINNED_LIT_SHADER_NAME = "aura3d/skinned-lit";
|
|
110
|
-
export const DEFAULT_SKINNED_LIT_SHADER_MARKER = "@aura3d-shader:skinned-lit";
|
|
111
|
-
/**
|
|
112
|
-
* Eight-influence skinned shaders. These read a second `JOINTS_1`/`WEIGHTS_1`
|
|
113
|
-
* attribute set and select between uniform-array and data-texture joint palettes at
|
|
114
|
-
* runtime through `u_jointPaletteMode`, so a single program serves both small rigs
|
|
115
|
-
* and rigs above the uniform-array joint limit.
|
|
116
|
-
*/
|
|
117
|
-
export const DEFAULT_SKINNED_UNLIT_EIGHT_INFLUENCE_SHADER_NAME = "aura3d/skinned-unlit-8";
|
|
118
|
-
export const DEFAULT_SKINNED_UNLIT_EIGHT_INFLUENCE_SHADER_MARKER = "@aura3d-shader:skinned-unlit-8";
|
|
119
|
-
export const DEFAULT_SKINNED_LIT_EIGHT_INFLUENCE_SHADER_NAME = "aura3d/skinned-lit-8";
|
|
120
|
-
export const DEFAULT_SKINNED_LIT_EIGHT_INFLUENCE_SHADER_MARKER = "@aura3d-shader:skinned-lit-8";
|
|
121
|
-
export const DEFAULT_MORPH_UNLIT_SHADER_NAME = "aura3d/morph-unlit";
|
|
122
|
-
export const DEFAULT_MORPH_UNLIT_SHADER_MARKER = "@aura3d-shader:morph-unlit";
|
|
123
|
-
export const DEFAULT_NORMAL_MAPPED_PBR_SHADER_NAME = "aura3d/pbr-normal-map";
|
|
124
|
-
export const DEFAULT_NORMAL_MAPPED_PBR_SHADER_MARKER = "@aura3d-shader:pbr-normal-map";
|
|
125
|
-
export const DEFAULT_TEXTURED_PBR_SHADER_NAME = "aura3d/pbr-textured";
|
|
126
|
-
export const DEFAULT_TEXTURED_PBR_SHADER_MARKER = "@aura3d-shader:pbr-textured";
|
|
127
|
-
export const DEFAULT_TEXTURED_PBR_CLEARCOAT_TEXTURES_VARIANT = "clearcoat-textures";
|
|
128
|
-
export const DEFAULT_TEXTURED_PBR_TRANSMISSION_VOLUME_TEXTURES_VARIANT = "transmission-volume-textures";
|
|
129
|
-
export const DEFAULT_TEXTURED_PBR_SPECULAR_SHEEN_ANISOTROPY_TEXTURES_VARIANT = "specular-sheen-anisotropy-textures";
|
|
130
|
-
export const DEFAULT_TEXTURED_PBR_IRIDESCENCE_TEXTURES_VARIANT = "iridescence-textures";
|
|
131
|
-
export const DEFAULT_TEXTURED_PBR_CLEARCOAT_TRANSMISSION_VOLUME_TEXTURES_VARIANT = "clearcoat-transmission-volume-textures";
|
|
132
|
-
export const DEFAULT_TEXTURED_PBR_CLEARCOAT_SPECULAR_TEXTURES_VARIANT = "clearcoat-specular-textures";
|
|
133
|
-
export const DEFAULT_TEXTURED_PBR_SPECULAR_SHEEN_ANISOTROPY_IRIDESCENCE_TEXTURES_VARIANT = "specular-sheen-anisotropy-iridescence-textures";
|
|
134
|
-
/**
|
|
135
|
-
* True screen-space fat lines, equivalent in intent to Three.js `Line2`/`LineMaterial`.
|
|
136
|
-
* Width is specified in pixels and stays constant across distance, FOV, viewport size,
|
|
137
|
-
* and device pixel ratio.
|
|
138
|
-
*/
|
|
139
|
-
export const DEFAULT_SCREEN_SPACE_LINE_SHADER_NAME = "aura3d/screen-space-line";
|
|
140
|
-
export const DEFAULT_SCREEN_SPACE_LINE_SHADER_MARKER = "@aura3d-shader:screen-space-line";
|
|
141
|
-
export const DEFAULT_DEPTH_SHADER_NAME = "aura3d/depth";
|
|
142
|
-
export const DEFAULT_DEPTH_SHADER_MARKER = "@aura3d-shader:depth";
|
|
143
|
-
export const DEFAULT_ENVIRONMENT_BACKGROUND_SHADER_NAME = "aura3d/environment-background";
|
|
144
|
-
export const DEFAULT_ENVIRONMENT_BACKGROUND_SHADER_MARKER = "@aura3d-shader:environment-background";
|
|
145
|
-
export function createDefaultShaderLibrary() {
|
|
146
|
-
const library = new ShaderLibrary();
|
|
147
|
-
validateShaderChunks();
|
|
148
|
-
for (const chunk of SHADER_CHUNKS) {
|
|
149
|
-
library.registerChunk(chunk.name, chunk.source);
|
|
150
|
-
}
|
|
151
|
-
library.register({
|
|
152
|
-
name: DEFAULT_UNLIT_SHADER_NAME,
|
|
153
|
-
marker: DEFAULT_UNLIT_SHADER_MARKER,
|
|
154
|
-
vertex: `#version 300 es
|
|
155
|
-
// ${DEFAULT_UNLIT_SHADER_MARKER}
|
|
156
|
-
precision highp float;
|
|
157
|
-
layout(location = 0) in vec3 a_position;
|
|
158
|
-
layout(location = 4) in vec4 a_color;
|
|
159
|
-
uniform mat4 u_modelViewProjection;
|
|
160
|
-
uniform float u_pointSize;
|
|
161
|
-
out vec4 v_vertexColor;
|
|
162
|
-
void main() {
|
|
163
|
-
v_vertexColor = a_color;
|
|
164
|
-
gl_PointSize = max(u_pointSize, 1.0);
|
|
165
|
-
gl_Position = u_modelViewProjection * vec4(a_position, 1.0);
|
|
166
|
-
}
|
|
167
|
-
`,
|
|
168
|
-
fragment: `#version 300 es
|
|
169
|
-
// ${DEFAULT_UNLIT_SHADER_MARKER}
|
|
170
|
-
precision highp float;
|
|
171
|
-
uniform vec4 u_baseColor;
|
|
172
|
-
uniform float u_alphaCutoff;
|
|
173
|
-
uniform float u_roundPoints;
|
|
174
|
-
in vec4 v_vertexColor;
|
|
175
|
-
out vec4 outColor;
|
|
176
|
-
void main() {
|
|
177
|
-
if (u_roundPoints > 0.5) {
|
|
178
|
-
vec2 pointUv = gl_PointCoord * 2.0 - 1.0;
|
|
179
|
-
float radius = dot(pointUv, pointUv);
|
|
180
|
-
if (radius > 1.0) discard;
|
|
181
|
-
}
|
|
182
|
-
vec4 base = u_baseColor * v_vertexColor;
|
|
183
|
-
if (base.a < u_alphaCutoff) discard;
|
|
184
|
-
outColor = base;
|
|
185
|
-
}
|
|
186
|
-
`
|
|
187
|
-
});
|
|
188
|
-
library.register({
|
|
189
|
-
name: DEFAULT_INSTANCED_UNLIT_SHADER_NAME,
|
|
190
|
-
marker: DEFAULT_INSTANCED_UNLIT_SHADER_MARKER,
|
|
191
|
-
vertex: `#version 300 es
|
|
192
|
-
// ${DEFAULT_INSTANCED_UNLIT_SHADER_MARKER}
|
|
193
|
-
precision highp float;
|
|
194
|
-
layout(location = 0) in vec3 a_position;
|
|
195
|
-
layout(location = 4) in vec4 a_color;
|
|
196
|
-
uniform mat4 u_modelViewProjection;
|
|
197
|
-
uniform mat4 u_instanceMatrices[64];
|
|
198
|
-
uniform float u_instanceCount;
|
|
199
|
-
uniform float u_instanceAttributeMode;
|
|
200
|
-
layout(location = 8) in vec4 a_instanceMatrix0;
|
|
201
|
-
layout(location = 9) in vec4 a_instanceMatrix1;
|
|
202
|
-
layout(location = 10) in vec4 a_instanceMatrix2;
|
|
203
|
-
layout(location = 11) in vec4 a_instanceMatrix3;
|
|
204
|
-
layout(location = 12) in vec4 a_instanceColor;
|
|
205
|
-
out vec4 v_vertexColor;
|
|
206
|
-
void main() {
|
|
207
|
-
int instanceIndex = clamp(gl_InstanceID, 0, max(int(u_instanceCount) - 1, 0));
|
|
208
|
-
mat4 attributeMatrix = mat4(a_instanceMatrix0, a_instanceMatrix1, a_instanceMatrix2, a_instanceMatrix3);
|
|
209
|
-
mat4 instanceMatrix = u_instanceAttributeMode > 0.5 ? attributeMatrix : u_instanceMatrices[instanceIndex];
|
|
210
|
-
v_vertexColor = a_color * a_instanceColor;
|
|
211
|
-
gl_Position = u_modelViewProjection * instanceMatrix * vec4(a_position, 1.0);
|
|
212
|
-
}
|
|
213
|
-
`,
|
|
214
|
-
fragment: `#version 300 es
|
|
215
|
-
// ${DEFAULT_INSTANCED_UNLIT_SHADER_MARKER}
|
|
216
|
-
precision highp float;
|
|
217
|
-
uniform vec4 u_baseColor;
|
|
218
|
-
uniform float u_alphaCutoff;
|
|
219
|
-
in vec4 v_vertexColor;
|
|
220
|
-
out vec4 outColor;
|
|
221
|
-
void main() {
|
|
222
|
-
vec4 base = u_baseColor * v_vertexColor;
|
|
223
|
-
if (base.a < u_alphaCutoff) discard;
|
|
224
|
-
outColor = base;
|
|
225
|
-
}
|
|
226
|
-
`
|
|
227
|
-
});
|
|
228
|
-
library.register({
|
|
229
|
-
name: DEFAULT_PBR_SHADER_NAME,
|
|
230
|
-
marker: DEFAULT_PBR_SHADER_MARKER,
|
|
231
|
-
vertex: `#version 300 es
|
|
232
|
-
// ${DEFAULT_PBR_SHADER_MARKER}
|
|
233
|
-
precision highp float;
|
|
234
|
-
layout(location = 0) in vec3 a_position;
|
|
235
|
-
layout(location = 1) in vec3 a_normal;
|
|
236
|
-
layout(location = 4) in vec4 a_color;
|
|
237
|
-
uniform mat4 u_modelViewProjection;
|
|
238
|
-
uniform mat4 u_modelMatrix;
|
|
239
|
-
uniform mat4 u_normalMatrix;
|
|
240
|
-
out vec3 v_normal;
|
|
241
|
-
out vec3 v_worldPosition;
|
|
242
|
-
out vec4 v_vertexColor;
|
|
243
|
-
void main() {
|
|
244
|
-
v_normal = mat3(u_normalMatrix) * a_normal;
|
|
245
|
-
v_worldPosition = (u_modelMatrix * vec4(a_position, 1.0)).xyz;
|
|
246
|
-
v_vertexColor = a_color;
|
|
247
|
-
gl_Position = u_modelViewProjection * vec4(a_position, 1.0);
|
|
248
|
-
}
|
|
249
|
-
`,
|
|
250
|
-
fragment: `#version 300 es
|
|
251
|
-
// ${DEFAULT_PBR_SHADER_MARKER}
|
|
252
|
-
precision highp float;
|
|
253
|
-
#include <lighting_common>
|
|
254
|
-
#include <pbr_common>
|
|
255
|
-
uniform vec4 u_baseColor;
|
|
256
|
-
uniform float u_alphaCutoff;
|
|
257
|
-
uniform float u_metallic;
|
|
258
|
-
uniform float u_roughness;
|
|
259
|
-
uniform vec3 u_environmentColor;
|
|
260
|
-
uniform float u_environmentIntensity;
|
|
261
|
-
uniform vec3 u_environmentSkyColor;
|
|
262
|
-
uniform vec3 u_environmentHorizonColor;
|
|
263
|
-
uniform vec3 u_environmentGroundColor;
|
|
264
|
-
uniform vec3 u_environmentSpecularColor;
|
|
265
|
-
uniform float u_environmentMapIntensity;
|
|
266
|
-
uniform float u_environmentSpecularIntensity;
|
|
267
|
-
uniform sampler2D u_environmentMapTexture;
|
|
268
|
-
uniform samplerCube u_environmentCubeMapTexture;
|
|
269
|
-
uniform float u_environmentCubeMapTextureEnabled;
|
|
270
|
-
uniform float u_environmentMapTextureEnabled;
|
|
271
|
-
uniform float u_environmentMapTextureIntensity;
|
|
272
|
-
uniform float u_environmentMapTextureSpecularIntensity;
|
|
273
|
-
uniform float u_environmentMapTextureRotation;
|
|
274
|
-
uniform float u_environmentMapTextureMipCount;
|
|
275
|
-
uniform float u_environmentMapTextureEncoding;
|
|
276
|
-
uniform sampler2D u_environmentBrdfLutTexture;
|
|
277
|
-
uniform float u_environmentBrdfLutEnabled;
|
|
278
|
-
uniform vec3 u_emissiveColor;
|
|
279
|
-
uniform float u_emissiveStrength;
|
|
280
|
-
uniform float u_clearcoatFactor;
|
|
281
|
-
uniform float u_clearcoatRoughnessFactor;
|
|
282
|
-
uniform float u_transmissionFactor;
|
|
283
|
-
uniform float u_diffuseTransmissionFactor;
|
|
284
|
-
uniform vec3 u_diffuseTransmissionColorFactor;
|
|
285
|
-
uniform float u_transmissionFallbackEnergy;
|
|
286
|
-
uniform float u_volumeThicknessFactor;
|
|
287
|
-
uniform float u_volumeAttenuationDistance;
|
|
288
|
-
uniform vec3 u_volumeAttenuationColor;
|
|
289
|
-
uniform float u_transmissionParallaxStrength;
|
|
290
|
-
uniform vec3 u_transmissionParallaxBoxMin;
|
|
291
|
-
uniform vec3 u_transmissionParallaxBoxMax;
|
|
292
|
-
uniform float u_transmissionBounceCount;
|
|
293
|
-
uniform float u_transmissionCausticStrength;
|
|
294
|
-
uniform float u_ior;
|
|
295
|
-
uniform float u_specularFactor;
|
|
296
|
-
uniform vec3 u_specularColorFactor;
|
|
297
|
-
uniform vec3 u_sheenColorFactor;
|
|
298
|
-
uniform float u_sheenRoughnessFactor;
|
|
299
|
-
uniform float u_anisotropyStrength;
|
|
300
|
-
uniform float u_anisotropyRotation;
|
|
301
|
-
uniform float u_iridescenceFactor;
|
|
302
|
-
uniform float u_iridescenceIor;
|
|
303
|
-
uniform float u_iridescenceThicknessMinimum;
|
|
304
|
-
uniform float u_iridescenceThicknessMaximum;
|
|
305
|
-
uniform float u_dispersion;
|
|
306
|
-
uniform float u_lightCount;
|
|
307
|
-
uniform vec4 u_lightData[96];
|
|
308
|
-
uniform float u_clusteredLightEnabled;
|
|
309
|
-
uniform vec2 u_clusterGridSize;
|
|
310
|
-
uniform vec2 u_clusterViewportSize;
|
|
311
|
-
uniform sampler2D u_clusterLightData;
|
|
312
|
-
uniform sampler2D u_clusterLightIndices;
|
|
313
|
-
uniform sampler2D u_shadowMapTexture;
|
|
314
|
-
uniform float u_shadowMapEnabled;
|
|
315
|
-
uniform mat4 u_shadowMapMatrix;
|
|
316
|
-
uniform float u_shadowMapStrength;
|
|
317
|
-
uniform float u_shadowMapBias;
|
|
318
|
-
uniform float u_shadowMapSlopeBias;
|
|
319
|
-
uniform vec2 u_shadowMapTexelSize;
|
|
320
|
-
uniform float u_shadowPcfSampleCount;
|
|
321
|
-
uniform vec4 u_shadowPcfSamples[32];
|
|
322
|
-
uniform sampler2D u_pointShadowMapTexture;
|
|
323
|
-
uniform float u_pointShadowMapEnabled;
|
|
324
|
-
uniform vec3 u_pointShadowLightPosition;
|
|
325
|
-
uniform float u_pointShadowRange;
|
|
326
|
-
uniform mat4 u_pointShadowFaceMatrices[6];
|
|
327
|
-
uniform vec4 u_pointShadowFaceRects[6];
|
|
328
|
-
uniform float u_pointShadowStrength;
|
|
329
|
-
uniform float u_pointShadowBias;
|
|
330
|
-
uniform float u_pointShadowSlopeBias;
|
|
331
|
-
uniform vec2 u_pointShadowTexelSize;
|
|
332
|
-
uniform float u_pointShadowPcfSampleCount;
|
|
333
|
-
uniform vec4 u_pointShadowPcfSamples[32];
|
|
334
|
-
uniform float u_outputColorSpace;
|
|
335
|
-
uniform vec3 u_cameraPosition;
|
|
336
|
-
uniform float u_environmentFogEnabled;
|
|
337
|
-
uniform float u_environmentFogMode;
|
|
338
|
-
uniform vec3 u_environmentFogColor;
|
|
339
|
-
uniform float u_environmentFogNear;
|
|
340
|
-
uniform float u_environmentFogFar;
|
|
341
|
-
uniform float u_environmentFogDensity;
|
|
342
|
-
uniform float u_environmentFogHeightFalloff;
|
|
343
|
-
uniform float u_environmentFogHeightReference;
|
|
344
|
-
uniform float u_environmentFogMaxOpacity;
|
|
345
|
-
in vec3 v_normal;
|
|
346
|
-
in vec3 v_worldPosition;
|
|
347
|
-
in vec4 v_vertexColor;
|
|
348
|
-
out vec4 outColor;
|
|
349
|
-
#include <environment_fog_common>
|
|
350
|
-
vec2 a3dEnvironmentEquirectUv(vec3 direction, float rotation) {
|
|
351
|
-
vec3 d = normalize(direction);
|
|
352
|
-
float u = atan(d.z, d.x) / 6.28318530718 + 0.5 + rotation;
|
|
353
|
-
float v = acos(clamp(d.y, -1.0, 1.0)) / 3.14159265359;
|
|
354
|
-
return vec2(fract(u), clamp(v, 0.0, 1.0));
|
|
355
|
-
}
|
|
356
|
-
vec3 a3dEnvironmentCubeDirection(vec3 direction, float rotation) {
|
|
357
|
-
float angle = rotation * 6.28318530718;
|
|
358
|
-
float c = cos(angle);
|
|
359
|
-
float s = sin(angle);
|
|
360
|
-
vec3 d = normalize(direction);
|
|
361
|
-
return normalize(vec3(c * d.x - s * d.z, d.y, s * d.x + c * d.z));
|
|
362
|
-
}
|
|
363
|
-
vec3 a3dPbrDecodeEnvironmentSrgb(vec3 encodedColor) {
|
|
364
|
-
return max(encodedColor, vec3(0.0));
|
|
365
|
-
}
|
|
366
|
-
vec3 a3dPbrDecodeEnvironmentRgbe(vec4 encodedSample) {
|
|
367
|
-
float exponent = encodedSample.a * 255.0;
|
|
368
|
-
float scale = exponent <= 0.0 ? 0.0 : exp2(exponent - 128.0) * (255.0 / 256.0);
|
|
369
|
-
return max(encodedSample.rgb * scale, vec3(0.0));
|
|
370
|
-
}
|
|
371
|
-
vec3 a3dPbrDecodeEnvironmentSample(vec4 encodedSample) {
|
|
372
|
-
if (u_environmentMapTextureEncoding > 1.5) return max(encodedSample.rgb, vec3(0.0));
|
|
373
|
-
if (u_environmentMapTextureEncoding > 0.5) return a3dPbrDecodeEnvironmentRgbe(encodedSample);
|
|
374
|
-
return a3dPbrDecodeEnvironmentSrgb(encodedSample.rgb);
|
|
375
|
-
}
|
|
376
|
-
vec3 a3dPbrBoundHdrTransmissionRadiance(vec3 radiance) {
|
|
377
|
-
vec3 nonNegative = max(radiance, vec3(0.0));
|
|
378
|
-
return nonNegative / (vec3(1.0) + max(nonNegative - vec3(1.0), vec3(0.0)));
|
|
379
|
-
}
|
|
380
|
-
vec3 a3dPbrBoundHdrSpecularRadiance(vec3 radiance) {
|
|
381
|
-
vec3 nonNegative = max(radiance, vec3(0.0));
|
|
382
|
-
vec3 softKnee = nonNegative / (vec3(1.0) + max(nonNegative - vec3(1.0), vec3(0.0)) * 0.58);
|
|
383
|
-
float maxChannel = max(max(softKnee.r, softKnee.g), softKnee.b);
|
|
384
|
-
return maxChannel > 1.65 ? softKnee * (1.65 / maxChannel) : softKnee;
|
|
385
|
-
}
|
|
386
|
-
vec3 a3dPbrClampSampledSpecularEdgeEnergy(vec3 radiance, float nDotV, float roughness) {
|
|
387
|
-
float faceOn = smoothstep(0.12, 0.55, clamp(nDotV, 0.0, 1.0));
|
|
388
|
-
float roughEnergy = mix(0.6, 1.0, clamp(roughness, 0.0, 1.0));
|
|
389
|
-
float edgeCap = mix(0.12, 1.2, faceOn) * roughEnergy;
|
|
390
|
-
float edgeScale = mix(0.14, 0.92, faceOn);
|
|
391
|
-
vec3 bounded = min(radiance * edgeScale, vec3(edgeCap));
|
|
392
|
-
return max(bounded, vec3(0.0));
|
|
393
|
-
}
|
|
394
|
-
vec4 a3dPbrEnvironmentSampleRaw(vec3 direction, float lod) {
|
|
395
|
-
vec4 equirectSample = textureLod(u_environmentMapTexture, a3dEnvironmentEquirectUv(direction, u_environmentMapTextureRotation), lod);
|
|
396
|
-
vec4 cubeSample = textureLod(u_environmentCubeMapTexture, a3dEnvironmentCubeDirection(direction, u_environmentMapTextureRotation), lod);
|
|
397
|
-
return mix(equirectSample, cubeSample, step(0.5, u_environmentCubeMapTextureEnabled));
|
|
398
|
-
}
|
|
399
|
-
vec3 a3dPbrBoxProjectedDirection(vec3 worldPosition, vec3 direction, vec3 boxMin, vec3 boxMax) {
|
|
400
|
-
vec3 safeDirection = normalize(direction);
|
|
401
|
-
vec3 invDirection = 1.0 / max(abs(safeDirection), vec3(0.0001)) * sign(safeDirection);
|
|
402
|
-
vec3 firstPlane = mix(boxMin, boxMax, step(vec3(0.0), safeDirection));
|
|
403
|
-
vec3 distances = (firstPlane - worldPosition) * invDirection;
|
|
404
|
-
float travel = min(min(
|
|
405
|
-
distances.x > 0.0 ? distances.x : 100000.0,
|
|
406
|
-
distances.y > 0.0 ? distances.y : 100000.0
|
|
407
|
-
), distances.z > 0.0 ? distances.z : 100000.0);
|
|
408
|
-
vec3 hitPosition = worldPosition + safeDirection * travel;
|
|
409
|
-
vec3 boxCenter = (boxMin + boxMax) * 0.5;
|
|
410
|
-
return normalize(hitPosition - boxCenter);
|
|
411
|
-
}
|
|
412
|
-
float a3dForwardShadowFactor(vec3 worldPosition, vec3 normal, vec3 lightDirection) {
|
|
413
|
-
if (u_shadowMapEnabled < 0.5) return 1.0;
|
|
414
|
-
vec4 lightPosition = u_shadowMapMatrix * vec4(worldPosition, 1.0);
|
|
415
|
-
vec3 projected = lightPosition.xyz / max(lightPosition.w, 0.0001);
|
|
416
|
-
vec2 uv = projected.xy * 0.5 + 0.5;
|
|
417
|
-
if (uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0) return 1.0;
|
|
418
|
-
vec3 receiverNormal = normalize(normal);
|
|
419
|
-
vec3 receiverLightDirection = lightDirection / max(length(lightDirection), 0.0001);
|
|
420
|
-
float normalDotLight = clamp(abs(dot(receiverNormal, receiverLightDirection)), 0.0, 1.0);
|
|
421
|
-
// Slope-scaled depth bias must be evaluated per PCF sample, not once for the kernel
|
|
422
|
-
// centre. A sample offset N texels away on a receiver sloped relative to the light sees a
|
|
423
|
-
// depth difference proportional to N, so a centre-only bias under-compensates every outer
|
|
424
|
-
// tap and the receiver shadows itself. Scaling by each sample's own texel distance keeps
|
|
425
|
-
// wide kernels acne-free without inflating the constant bias into peter-panning.
|
|
426
|
-
// The depth gradient across one shadow texel is tan(angle between receiver normal and
|
|
427
|
-
// light), not (1 - N.L). The linear form collapses toward zero far faster than the real
|
|
428
|
-
// gradient grows, so it under-biases exactly the grazing angles that need the most
|
|
429
|
-
// compensation. Clamped so a near-perpendicular receiver cannot demand unbounded bias.
|
|
430
|
-
float slopeTangent = min(sqrt(max(1.0 - normalDotLight * normalDotLight, 0.0)) / max(normalDotLight, 0.05), 8.0);
|
|
431
|
-
float slopeTexelBias = slopeTangent * u_shadowMapSlopeBias * max(u_shadowMapTexelSize.x, u_shadowMapTexelSize.y);
|
|
432
|
-
float projectedDepth = projected.z * 0.5 + 0.5;
|
|
433
|
-
float shadowed = 0.0;
|
|
434
|
-
float totalWeight = 0.0;
|
|
435
|
-
int sampleCount = clamp(int(u_shadowPcfSampleCount), 1, 32);
|
|
436
|
-
for (int i = 0; i < 32; ++i) {
|
|
437
|
-
if (i >= sampleCount) break;
|
|
438
|
-
vec4 sampleData = u_shadowPcfSamples[i];
|
|
439
|
-
float weight = max(sampleData.z, 0.0);
|
|
440
|
-
vec2 offset = sampleData.xy * u_shadowMapTexelSize;
|
|
441
|
-
float storedDepth = texture(u_shadowMapTexture, uv + offset).r;
|
|
442
|
-
float sampleTexelDistance = max(1.0, length(sampleData.xy));
|
|
443
|
-
float receiverDepth = projectedDepth - u_shadowMapBias - slopeTexelBias * sampleTexelDistance;
|
|
444
|
-
shadowed += (receiverDepth > storedDepth ? 1.0 : 0.0) * weight;
|
|
445
|
-
totalWeight += weight;
|
|
446
|
-
}
|
|
447
|
-
float occlusion = totalWeight > 0.0 ? shadowed / totalWeight : 0.0;
|
|
448
|
-
return mix(1.0, 1.0 - occlusion, clamp(u_shadowMapStrength, 0.0, 1.0));
|
|
449
|
-
}
|
|
450
|
-
float a3dPointShadowFaceIndex(vec3 direction) {
|
|
451
|
-
vec3 absoluteDirection = abs(direction);
|
|
452
|
-
if (absoluteDirection.x >= absoluteDirection.y && absoluteDirection.x >= absoluteDirection.z) return direction.x >= 0.0 ? 0.0 : 1.0;
|
|
453
|
-
if (absoluteDirection.y >= absoluteDirection.x && absoluteDirection.y >= absoluteDirection.z) return direction.y >= 0.0 ? 2.0 : 3.0;
|
|
454
|
-
return direction.z >= 0.0 ? 4.0 : 5.0;
|
|
455
|
-
}
|
|
456
|
-
float a3dPointShadowFactor(vec3 worldPosition, vec3 normal, vec3 lightDirection) {
|
|
457
|
-
if (u_pointShadowMapEnabled < 0.5) return 1.0;
|
|
458
|
-
vec3 lightToFragment = worldPosition - u_pointShadowLightPosition;
|
|
459
|
-
float distanceToLight = length(lightToFragment);
|
|
460
|
-
if (distanceToLight > u_pointShadowRange) return 1.0;
|
|
461
|
-
int faceIndex = int(a3dPointShadowFaceIndex(lightToFragment));
|
|
462
|
-
vec4 lightPosition = u_pointShadowFaceMatrices[faceIndex] * vec4(worldPosition, 1.0);
|
|
463
|
-
vec3 projected = lightPosition.xyz / max(lightPosition.w, 0.0001);
|
|
464
|
-
vec2 localUv = projected.xy * 0.5 + 0.5;
|
|
465
|
-
if (localUv.x < 0.0 || localUv.x > 1.0 || localUv.y < 0.0 || localUv.y > 1.0) return 1.0;
|
|
466
|
-
vec4 rect = u_pointShadowFaceRects[faceIndex];
|
|
467
|
-
vec2 uv = rect.xy + localUv * rect.zw;
|
|
468
|
-
vec3 receiverNormal = normalize(normal);
|
|
469
|
-
vec3 receiverLightDirection = lightDirection / max(length(lightDirection), 0.0001);
|
|
470
|
-
float normalDotLight = clamp(abs(dot(receiverNormal, receiverLightDirection)), 0.0, 1.0);
|
|
471
|
-
// Slope-scaled depth bias must be evaluated per PCF sample, not once for the kernel
|
|
472
|
-
// centre. A sample offset N texels away on a receiver sloped relative to the light sees a
|
|
473
|
-
// depth difference proportional to N, so a centre-only bias under-compensates every outer
|
|
474
|
-
// tap and the receiver shadows itself. Scaling by each sample's own texel distance keeps
|
|
475
|
-
// wide kernels acne-free without inflating the constant bias into peter-panning.
|
|
476
|
-
// The depth gradient across one shadow texel is tan(angle between receiver normal and
|
|
477
|
-
// light), not (1 - N.L). The linear form collapses toward zero far faster than the real
|
|
478
|
-
// gradient grows, so it under-biases exactly the grazing angles that need the most
|
|
479
|
-
// compensation. Clamped so a near-perpendicular receiver cannot demand unbounded bias.
|
|
480
|
-
float slopeTangent = min(sqrt(max(1.0 - normalDotLight * normalDotLight, 0.0)) / max(normalDotLight, 0.05), 8.0);
|
|
481
|
-
float slopeTexelBias = slopeTangent * u_pointShadowSlopeBias * max(u_pointShadowTexelSize.x, u_pointShadowTexelSize.y);
|
|
482
|
-
float projectedDepth = projected.z * 0.5 + 0.5;
|
|
483
|
-
float shadowed = 0.0;
|
|
484
|
-
float totalWeight = 0.0;
|
|
485
|
-
int sampleCount = clamp(int(u_pointShadowPcfSampleCount), 1, 32);
|
|
486
|
-
for (int i = 0; i < 32; ++i) {
|
|
487
|
-
if (i >= sampleCount) break;
|
|
488
|
-
vec4 sampleData = u_pointShadowPcfSamples[i];
|
|
489
|
-
float weight = max(sampleData.z, 0.0);
|
|
490
|
-
vec2 offset = sampleData.xy * u_pointShadowTexelSize;
|
|
491
|
-
float storedDepth = texture(u_pointShadowMapTexture, uv + offset).r;
|
|
492
|
-
float sampleTexelDistance = max(1.0, length(sampleData.xy));
|
|
493
|
-
float receiverDepth = projectedDepth - u_pointShadowBias - slopeTexelBias * sampleTexelDistance;
|
|
494
|
-
shadowed += (receiverDepth > storedDepth ? 1.0 : 0.0) * weight;
|
|
495
|
-
totalWeight += weight;
|
|
496
|
-
}
|
|
497
|
-
float occlusion = totalWeight > 0.0 ? shadowed / totalWeight : 0.0;
|
|
498
|
-
return mix(1.0, 1.0 - occlusion, clamp(u_pointShadowStrength, 0.0, 1.0));
|
|
499
|
-
}
|
|
500
|
-
vec3 a3dPbrEncodeOutput(vec3 linearColor) {
|
|
501
|
-
vec3 color = max(linearColor, vec3(0.0));
|
|
502
|
-
vec3 filmic = clamp((color * (2.51 * color + 0.03)) / (color * (2.43 * color + 0.59) + 0.14), vec3(0.0), vec3(1.0));
|
|
503
|
-
vec3 srgb = pow(filmic, vec3(1.0 / 2.2));
|
|
504
|
-
return mix(color, srgb, step(0.5, u_outputColorSpace));
|
|
3
|
+
import { ShaderLibrary, registerLeanUnlitShader, registerLeanPbrShader, registerLeanDepthShader, registerLeanEnvironmentBackgroundShader, DEFAULT_DEPTH_SHADER_MARKER, DEFAULT_DEPTH_SHADER_NAME, DEFAULT_ENVIRONMENT_BACKGROUND_SHADER_MARKER, DEFAULT_ENVIRONMENT_BACKGROUND_SHADER_NAME, DEFAULT_INSTANCED_PBR_SHADER_MARKER, DEFAULT_INSTANCED_PBR_SHADER_NAME, DEFAULT_INSTANCED_UNLIT_SHADER_MARKER, DEFAULT_INSTANCED_UNLIT_SHADER_NAME, DEFAULT_MORPH_UNLIT_SHADER_MARKER, DEFAULT_MORPH_UNLIT_SHADER_NAME, DEFAULT_NORMAL_MAPPED_PBR_SHADER_MARKER, DEFAULT_NORMAL_MAPPED_PBR_SHADER_NAME, DEFAULT_PBR_SHADER_MARKER, DEFAULT_PBR_SHADER_NAME, DEFAULT_SCREEN_SPACE_LINE_SHADER_MARKER, DEFAULT_SCREEN_SPACE_LINE_SHADER_NAME, DEFAULT_SKINNED_LIT_EIGHT_INFLUENCE_SHADER_MARKER, DEFAULT_SKINNED_LIT_EIGHT_INFLUENCE_SHADER_NAME, DEFAULT_SKINNED_LIT_SHADER_MARKER, DEFAULT_SKINNED_LIT_SHADER_NAME, DEFAULT_SKINNED_UNLIT_EIGHT_INFLUENCE_SHADER_MARKER, DEFAULT_SKINNED_UNLIT_EIGHT_INFLUENCE_SHADER_NAME, DEFAULT_SKINNED_UNLIT_SHADER_MARKER, DEFAULT_SKINNED_UNLIT_SHADER_NAME, DEFAULT_TEXTURED_PBR_CLEARCOAT_SPECULAR_TEXTURES_VARIANT, DEFAULT_TEXTURED_PBR_CLEARCOAT_TEXTURES_VARIANT, DEFAULT_TEXTURED_PBR_CLEARCOAT_TRANSMISSION_VOLUME_TEXTURES_VARIANT, DEFAULT_TEXTURED_PBR_IRIDESCENCE_TEXTURES_VARIANT, DEFAULT_TEXTURED_PBR_SHADER_MARKER, DEFAULT_TEXTURED_PBR_SHADER_NAME, DEFAULT_TEXTURED_PBR_SPECULAR_SHEEN_ANISOTROPY_IRIDESCENCE_TEXTURES_VARIANT, DEFAULT_TEXTURED_PBR_SPECULAR_SHEEN_ANISOTROPY_TEXTURES_VARIANT, DEFAULT_TEXTURED_PBR_TRANSMISSION_VOLUME_TEXTURES_VARIANT, DEFAULT_TEXTURED_UNLIT_SHADER_MARKER, DEFAULT_TEXTURED_UNLIT_SHADER_NAME, DEFAULT_UNLIT_SHADER_MARKER, DEFAULT_UNLIT_SHADER_NAME, } from "./ShaderLibraryCore.js";
|
|
4
|
+
export * from "./ShaderLibraryCore.js";
|
|
5
|
+
export function createDefaultShaderLibrary() {
|
|
6
|
+
const library = new ShaderLibrary();
|
|
7
|
+
validateShaderChunks();
|
|
8
|
+
for (const chunk of SHADER_CHUNKS) {
|
|
9
|
+
library.registerChunk(chunk.name, chunk.source);
|
|
10
|
+
}
|
|
11
|
+
registerLeanUnlitShader(library);
|
|
12
|
+
library.register({
|
|
13
|
+
name: DEFAULT_INSTANCED_UNLIT_SHADER_NAME,
|
|
14
|
+
marker: DEFAULT_INSTANCED_UNLIT_SHADER_MARKER,
|
|
15
|
+
vertex: `#version 300 es
|
|
16
|
+
// ${DEFAULT_INSTANCED_UNLIT_SHADER_MARKER}
|
|
17
|
+
precision highp float;
|
|
18
|
+
layout(location = 0) in vec3 a_position;
|
|
19
|
+
layout(location = 4) in vec4 a_color;
|
|
20
|
+
uniform mat4 u_modelViewProjection;
|
|
21
|
+
uniform mat4 u_instanceMatrices[64];
|
|
22
|
+
uniform float u_instanceCount;
|
|
23
|
+
uniform float u_instanceAttributeMode;
|
|
24
|
+
layout(location = 8) in vec4 a_instanceMatrix0;
|
|
25
|
+
layout(location = 9) in vec4 a_instanceMatrix1;
|
|
26
|
+
layout(location = 10) in vec4 a_instanceMatrix2;
|
|
27
|
+
layout(location = 11) in vec4 a_instanceMatrix3;
|
|
28
|
+
layout(location = 12) in vec4 a_instanceColor;
|
|
29
|
+
out vec4 v_vertexColor;
|
|
30
|
+
void main() {
|
|
31
|
+
int instanceIndex = clamp(gl_InstanceID, 0, max(int(u_instanceCount) - 1, 0));
|
|
32
|
+
mat4 attributeMatrix = mat4(a_instanceMatrix0, a_instanceMatrix1, a_instanceMatrix2, a_instanceMatrix3);
|
|
33
|
+
mat4 instanceMatrix = u_instanceAttributeMode > 0.5 ? attributeMatrix : u_instanceMatrices[instanceIndex];
|
|
34
|
+
v_vertexColor = a_color * a_instanceColor;
|
|
35
|
+
gl_Position = u_modelViewProjection * instanceMatrix * vec4(a_position, 1.0);
|
|
505
36
|
}
|
|
37
|
+
`,
|
|
38
|
+
fragment: `#version 300 es
|
|
39
|
+
// ${DEFAULT_INSTANCED_UNLIT_SHADER_MARKER}
|
|
40
|
+
precision highp float;
|
|
41
|
+
uniform vec4 u_baseColor;
|
|
42
|
+
uniform float u_alphaCutoff;
|
|
43
|
+
in vec4 v_vertexColor;
|
|
44
|
+
out vec4 outColor;
|
|
506
45
|
void main() {
|
|
507
|
-
|
|
508
|
-
if (
|
|
509
|
-
|
|
510
|
-
vec3 materialBase = a3dApplyAdvancedPbrLobes(
|
|
511
|
-
u_baseColor.rgb * v_vertexColor.rgb,
|
|
512
|
-
u_clearcoatFactor,
|
|
513
|
-
u_clearcoatRoughnessFactor,
|
|
514
|
-
u_transmissionFactor,
|
|
515
|
-
u_diffuseTransmissionFactor,
|
|
516
|
-
u_diffuseTransmissionColorFactor,
|
|
517
|
-
u_transmissionFallbackEnergy,
|
|
518
|
-
u_volumeThicknessFactor,
|
|
519
|
-
u_volumeAttenuationDistance,
|
|
520
|
-
u_volumeAttenuationColor,
|
|
521
|
-
u_ior,
|
|
522
|
-
u_specularFactor,
|
|
523
|
-
u_specularColorFactor,
|
|
524
|
-
u_sheenColorFactor,
|
|
525
|
-
u_sheenRoughnessFactor,
|
|
526
|
-
u_anisotropyStrength,
|
|
527
|
-
u_anisotropyRotation,
|
|
528
|
-
u_iridescenceFactor,
|
|
529
|
-
u_iridescenceIor,
|
|
530
|
-
u_iridescenceThicknessMinimum,
|
|
531
|
-
u_iridescenceThicknessMaximum,
|
|
532
|
-
u_dispersion
|
|
533
|
-
);
|
|
534
|
-
float environmentHemi = mix(0.35, 1.0, clamp(normal.y * 0.5 + 0.5, 0.0, 1.0));
|
|
535
|
-
vec3 ambientEnvironment = u_environmentColor * u_environmentIntensity * environmentHemi;
|
|
536
|
-
float proceduralEnvironmentWeight = step(0.0001, u_environmentMapIntensity);
|
|
537
|
-
float skyBlend = clamp(normal.y * 0.5 + 0.5, 0.0, 1.0);
|
|
538
|
-
float horizonBlend = 1.0 - abs(normal.y);
|
|
539
|
-
vec3 proceduralDiffuse = mix(u_environmentGroundColor, u_environmentSkyColor, skyBlend);
|
|
540
|
-
proceduralDiffuse = mix(proceduralDiffuse, u_environmentHorizonColor, clamp(horizonBlend, 0.0, 1.0) * 0.55);
|
|
541
|
-
// The ambient term must be added to the procedural contribution, not replaced by it. A mix
|
|
542
|
-
// here discarded u_environmentColor * u_environmentIntensity entirely whenever a procedural
|
|
543
|
-
// map was present, which is the normal case: raising ambient intensity from 0.18 to 3.0 on
|
|
544
|
-
// the product-turntable kit produced a byte-identical frame. Ambient and a sky gradient are
|
|
545
|
-
// separate physical contributions, so they sum.
|
|
546
|
-
vec3 environmentDiffuse = ambientEnvironment + proceduralDiffuse * u_environmentMapIntensity * proceduralEnvironmentWeight;
|
|
547
|
-
float sampledEnvironmentWeight = step(0.0001, u_environmentMapTextureEnabled * u_environmentMapTextureIntensity);
|
|
548
|
-
float diffuseEnvironmentLod = max(u_environmentMapTextureMipCount - 1.0, 0.0);
|
|
549
|
-
vec3 sampledDiffuse = a3dPbrDecodeEnvironmentSample(a3dPbrEnvironmentSampleRaw(normal, diffuseEnvironmentLod));
|
|
550
|
-
environmentDiffuse = mix(environmentDiffuse, ambientEnvironment + sampledDiffuse * u_environmentMapTextureIntensity, sampledEnvironmentWeight);
|
|
551
|
-
vec3 reflectionDirection = reflect(-viewDirection, normal);
|
|
552
|
-
float roughness = clamp(u_roughness, 0.0, 1.0);
|
|
553
|
-
float reflectionBand = pow(clamp(reflectionDirection.y * 0.5 + 0.5, 0.0, 1.0), mix(18.0, 2.0, roughness));
|
|
554
|
-
float roughEnvironmentFloor = mix(0.04, 0.38, roughness);
|
|
555
|
-
float proceduralSpecularResponse = max(reflectionBand, roughEnvironmentFloor);
|
|
556
|
-
vec3 proceduralSpecular = u_environmentSpecularColor * u_environmentSpecularIntensity * proceduralSpecularResponse * proceduralEnvironmentWeight;
|
|
557
|
-
float environmentLod = roughness * max(u_environmentMapTextureMipCount - 1.0, 0.0);
|
|
558
|
-
vec3 sampledSpecular = a3dPbrBoundHdrSpecularRadiance(a3dPbrDecodeEnvironmentSample(a3dPbrEnvironmentSampleRaw(reflectionDirection, environmentLod)));
|
|
559
|
-
float nDotV = clamp(dot(normal, viewDirection), 0.0, 1.0);
|
|
560
|
-
vec2 brdfLut = texture(u_environmentBrdfLutTexture, vec2(nDotV, roughness)).rg;
|
|
561
|
-
sampledSpecular = a3dPbrClampSampledSpecularEdgeEnergy(sampledSpecular, nDotV, roughness);
|
|
562
|
-
sampledSpecular *= u_environmentMapTextureSpecularIntensity * sampledEnvironmentWeight * mix(1.1, 0.85, roughness);
|
|
563
|
-
vec3 shaded = a3dPbrEnvironmentLightSplitSum(
|
|
564
|
-
normal,
|
|
565
|
-
viewDirection,
|
|
566
|
-
environmentDiffuse,
|
|
567
|
-
proceduralSpecular + sampledSpecular,
|
|
568
|
-
mix(vec2(1.0, 0.0), brdfLut, step(0.0001, u_environmentBrdfLutEnabled)),
|
|
569
|
-
materialBase,
|
|
570
|
-
u_metallic,
|
|
571
|
-
u_roughness,
|
|
572
|
-
u_specularFactor,
|
|
573
|
-
u_specularColorFactor
|
|
574
|
-
) + u_emissiveColor * u_emissiveStrength;
|
|
575
|
-
shaded += a3dPbrExtensionEnvironmentLight(
|
|
576
|
-
normal,
|
|
577
|
-
viewDirection,
|
|
578
|
-
proceduralSpecular + sampledSpecular,
|
|
579
|
-
u_clearcoatFactor,
|
|
580
|
-
u_clearcoatRoughnessFactor,
|
|
581
|
-
u_sheenColorFactor,
|
|
582
|
-
u_sheenRoughnessFactor,
|
|
583
|
-
u_anisotropyStrength,
|
|
584
|
-
u_anisotropyRotation,
|
|
585
|
-
u_iridescenceFactor,
|
|
586
|
-
u_iridescenceIor,
|
|
587
|
-
u_iridescenceThicknessMinimum,
|
|
588
|
-
u_iridescenceThicknessMaximum
|
|
589
|
-
);
|
|
590
|
-
float transmissionAmount = clamp(max(u_transmissionFactor, u_diffuseTransmissionFactor), 0.0, 1.0);
|
|
591
|
-
if (transmissionAmount > 0.0001 && sampledEnvironmentWeight > 0.0001) {
|
|
592
|
-
vec3 refractionDirection = refract(-viewDirection, normal, 1.0 / max(u_ior, 1.0));
|
|
593
|
-
refractionDirection = length(refractionDirection) > 0.0001 ? normalize(refractionDirection) : -reflectionDirection;
|
|
594
|
-
float parallaxStrength = clamp(u_transmissionParallaxStrength, 0.0, 1.0);
|
|
595
|
-
if (parallaxStrength > 0.0001) {
|
|
596
|
-
vec3 parallaxDirection = a3dPbrBoxProjectedDirection(v_worldPosition, refractionDirection, u_transmissionParallaxBoxMin, u_transmissionParallaxBoxMax);
|
|
597
|
-
refractionDirection = normalize(mix(refractionDirection, parallaxDirection, parallaxStrength));
|
|
598
|
-
}
|
|
599
|
-
float bounceCount = clamp(u_transmissionBounceCount, 0.0, 4.0);
|
|
600
|
-
float refractionLod = clamp(roughness + u_volumeThicknessFactor * 0.12 + bounceCount * 0.04 * parallaxStrength, 0.0, 1.0) * max(u_environmentMapTextureMipCount - 1.0, 0.0);
|
|
601
|
-
vec3 refractedEnvironment = a3dPbrBoundHdrTransmissionRadiance(a3dPbrDecodeEnvironmentSample(a3dPbrEnvironmentSampleRaw(refractionDirection, refractionLod)));
|
|
602
|
-
float volumeTravel = clamp((max(u_volumeThicknessFactor, 0.0) * (1.0 + bounceCount * 0.18 * parallaxStrength)) / max(u_volumeAttenuationDistance, 0.0001), 0.0, 16.0);
|
|
603
|
-
vec3 volumeTint = pow(clamp(u_volumeAttenuationColor, vec3(0.0001), vec3(1.0)), vec3(volumeTravel));
|
|
604
|
-
float causticEnergy = u_transmissionCausticStrength * parallaxStrength * transmissionAmount * pow(1.0 - roughness, 2.0) / (1.0 + bounceCount * 0.35);
|
|
605
|
-
float roughVolumeIorLift = mix(1.0, 1.45, clamp((u_ior - 1.0) / 1.5, 0.0, 1.0) * smoothstep(0.35, 0.95, roughness + u_volumeThicknessFactor * 0.2));
|
|
606
|
-
float fallbackEnvironmentTransmissionEnergy = mix(1.0, clamp(u_transmissionFallbackEnergy, 0.0, 1.0), transmissionAmount);
|
|
607
|
-
vec3 refractionRadiance = (refractedEnvironment + vec3(causticEnergy)) * volumeTint * u_environmentMapTextureIntensity * transmissionAmount * fallbackEnvironmentTransmissionEnergy * mix(0.9, 0.55, roughness) * roughVolumeIorLift;
|
|
608
|
-
shaded = mix(shaded, shaded * 0.72 + refractionRadiance, transmissionAmount * mix(0.08, 0.58, fallbackEnvironmentTransmissionEnergy));
|
|
609
|
-
}
|
|
610
|
-
ivec2 clusterTile = clamp(ivec2(floor(gl_FragCoord.xy / max(u_clusterViewportSize / u_clusterGridSize, vec2(1.0)))), ivec2(0), ivec2(u_clusterGridSize) - ivec2(1));
|
|
611
|
-
int clusterIndex = clusterTile.y * int(u_clusterGridSize.x) + clusterTile.x;
|
|
612
|
-
int count = u_clusteredLightEnabled > 0.5 ? min(int(texelFetch(u_clusterLightIndices, ivec2(0, clusterIndex), 0).g), 64) : min(int(u_lightCount), 16);
|
|
613
|
-
for (int i = 0; i < 64; ++i) {
|
|
614
|
-
if (i >= count) break;
|
|
615
|
-
int lightIndex = u_clusteredLightEnabled > 0.5 ? int(texelFetch(u_clusterLightIndices, ivec2(i, clusterIndex), 0).r) : i;
|
|
616
|
-
int baseIndex = lightIndex * 6;
|
|
617
|
-
vec4 colorIntensity = u_clusteredLightEnabled > 0.5 ? texelFetch(u_clusterLightData, ivec2(0, lightIndex), 0) : u_lightData[baseIndex];
|
|
618
|
-
vec4 positionRange = u_clusteredLightEnabled > 0.5 ? texelFetch(u_clusterLightData, ivec2(1, lightIndex), 0) : u_lightData[baseIndex + 1];
|
|
619
|
-
vec4 directionKind = u_clusteredLightEnabled > 0.5 ? texelFetch(u_clusterLightData, ivec2(2, lightIndex), 0) : u_lightData[baseIndex + 2];
|
|
620
|
-
vec4 spotShadowLayer = u_clusteredLightEnabled > 0.5 ? texelFetch(u_clusterLightData, ivec2(3, lightIndex), 0) : u_lightData[baseIndex + 3];
|
|
621
|
-
vec4 areaRight = u_clusteredLightEnabled > 0.5 ? texelFetch(u_clusterLightData, ivec2(4, lightIndex), 0) : u_lightData[baseIndex + 4];
|
|
622
|
-
vec4 areaUp = u_clusteredLightEnabled > 0.5 ? texelFetch(u_clusterLightData, ivec2(5, lightIndex), 0) : u_lightData[baseIndex + 5];
|
|
623
|
-
float kind = directionKind.w;
|
|
624
|
-
if (kind > 2.5) {
|
|
625
|
-
shaded += a3dPbrRectAreaLight(
|
|
626
|
-
v_worldPosition, positionRange.xyz, directionKind.xyz, areaRight.xyz, areaUp.xyz,
|
|
627
|
-
spotShadowLayer.x, spotShadowLayer.y, positionRange.w,
|
|
628
|
-
normal, viewDirection, colorIntensity.rgb, colorIntensity.a,
|
|
629
|
-
materialBase, u_metallic, u_roughness, u_specularFactor, u_specularColorFactor
|
|
630
|
-
);
|
|
631
|
-
continue;
|
|
632
|
-
}
|
|
633
|
-
vec3 lightDirection = -directionKind.xyz;
|
|
634
|
-
float attenuation = 1.0;
|
|
635
|
-
if (kind > 0.5) {
|
|
636
|
-
vec3 toLight = positionRange.xyz - v_worldPosition;
|
|
637
|
-
float distanceToLight = length(toLight);
|
|
638
|
-
lightDirection = distanceToLight > 0.0001 ? toLight / distanceToLight : -directionKind.xyz;
|
|
639
|
-
float range = max(positionRange.w, 0.0001);
|
|
640
|
-
float rangeFalloff = clamp(1.0 - pow(distanceToLight / range, 4.0), 0.0, 1.0);
|
|
641
|
-
rangeFalloff *= rangeFalloff;
|
|
642
|
-
attenuation = rangeFalloff / max(distanceToLight * distanceToLight, 1.0);
|
|
643
|
-
}
|
|
644
|
-
if (kind > 1.5) {
|
|
645
|
-
vec3 lightToFragment = normalize(v_worldPosition - positionRange.xyz);
|
|
646
|
-
float cone = dot(normalize(directionKind.xyz), lightToFragment);
|
|
647
|
-
float outer = cos(spotShadowLayer.x);
|
|
648
|
-
float inner = cos(spotShadowLayer.x * max(1.0 - spotShadowLayer.y, 0.001));
|
|
649
|
-
attenuation *= smoothstep(outer, inner, cone);
|
|
650
|
-
}
|
|
651
|
-
float directLightIntensity = colorIntensity.a * attenuation * mix(1.0, kind > 0.5 && kind < 1.5 ? a3dPointShadowFactor(v_worldPosition, normal, lightDirection) : a3dForwardShadowFactor(v_worldPosition, normal, lightDirection), step(0.5, spotShadowLayer.z));
|
|
652
|
-
shaded += a3dPbrDirectLight(
|
|
653
|
-
normal,
|
|
654
|
-
viewDirection,
|
|
655
|
-
lightDirection,
|
|
656
|
-
colorIntensity.rgb,
|
|
657
|
-
directLightIntensity,
|
|
658
|
-
materialBase,
|
|
659
|
-
u_metallic,
|
|
660
|
-
u_roughness,
|
|
661
|
-
u_specularFactor,
|
|
662
|
-
u_specularColorFactor
|
|
663
|
-
);
|
|
664
|
-
shaded += a3dPbrExtensionDirectLight(
|
|
665
|
-
normal,
|
|
666
|
-
viewDirection,
|
|
667
|
-
lightDirection,
|
|
668
|
-
colorIntensity.rgb,
|
|
669
|
-
directLightIntensity,
|
|
670
|
-
u_clearcoatFactor,
|
|
671
|
-
u_clearcoatRoughnessFactor,
|
|
672
|
-
u_sheenColorFactor,
|
|
673
|
-
u_sheenRoughnessFactor,
|
|
674
|
-
u_anisotropyStrength,
|
|
675
|
-
u_anisotropyRotation,
|
|
676
|
-
u_iridescenceFactor,
|
|
677
|
-
u_iridescenceIor,
|
|
678
|
-
u_iridescenceThicknessMinimum,
|
|
679
|
-
u_iridescenceThicknessMaximum
|
|
680
|
-
);
|
|
681
|
-
}
|
|
682
|
-
float alpha = u_baseColor.a * v_vertexColor.a;
|
|
683
|
-
if (alpha < u_alphaCutoff) discard;
|
|
684
|
-
vec3 fogged = a3dApplyEnvironmentFog(max(shaded, vec3(0.0)), v_worldPosition);
|
|
685
|
-
outColor = vec4(a3dPbrEncodeOutput(fogged), alpha);
|
|
46
|
+
vec4 base = u_baseColor * v_vertexColor;
|
|
47
|
+
if (base.a < u_alphaCutoff) discard;
|
|
48
|
+
outColor = base;
|
|
686
49
|
}
|
|
687
50
|
`
|
|
688
51
|
});
|
|
52
|
+
registerLeanPbrShader(library);
|
|
689
53
|
library.register({
|
|
690
54
|
name: DEFAULT_INSTANCED_PBR_SHADER_NAME,
|
|
691
55
|
marker: DEFAULT_INSTANCED_PBR_SHADER_MARKER,
|
|
@@ -2955,7 +2319,12 @@ vec3 a3dTexturedPbrEnvironmentSpecularInput(vec3 normal, vec3 viewDirection, flo
|
|
|
2955
2319
|
float nDotV = clamp(dot(normal, viewDirection), 0.0, 1.0);
|
|
2956
2320
|
float faceOnSpecularGate = smoothstep(0.1, 0.42, nDotV);
|
|
2957
2321
|
float reflectionBand = pow(clamp(reflectionDirection.y * 0.5 + 0.5, 0.0, 1.0), mix(18.0, 2.0, clampedRoughness));
|
|
2958
|
-
|
|
2322
|
+
// Keep the procedural environment from becoming a uniform white veil on
|
|
2323
|
+
// saturated textured base colors. A high roughness floor spread neutral
|
|
2324
|
+
// specular over every fragment, while image-based lighting and Three.js keep
|
|
2325
|
+
// the strongest neutral energy in reflection bands and glancing highlights.
|
|
2326
|
+
// The lower floor preserves ambient readability without erasing texture chroma.
|
|
2327
|
+
float roughEnvironmentFloor = mix(0.012, 0.16, clampedRoughness);
|
|
2959
2328
|
float proceduralSpecularResponse = max(reflectionBand, roughEnvironmentFloor);
|
|
2960
2329
|
float horizonStripe = pow(clamp(1.0 - abs(reflectionDirection.y), 0.0, 1.0), mix(14.0, 3.0, clampedRoughness));
|
|
2961
2330
|
float sideStripe = pow(clamp(abs(reflectionDirection.x), 0.0, 1.0), mix(10.0, 3.0, clampedRoughness)) * smoothstep(0.0, 0.72, 1.0 - abs(reflectionDirection.y));
|
|
@@ -2974,14 +2343,50 @@ vec3 a3dTexturedPbrEnvironmentSpecularInput(vec3 normal, vec3 viewDirection, flo
|
|
|
2974
2343
|
float sampledSpecularScale = materialEnvironmentSpecularScale * mix(0.18, 1.0, faceOnSpecularGate);
|
|
2975
2344
|
return proceduralSpecular * proceduralSpecularScale + sampledSpecular * sampledSpecularScale;
|
|
2976
2345
|
}
|
|
2977
|
-
vec3 a3dTexturedPbrIridescenceColor(float minimumThickness, float maximumThickness, float iridescenceIor) {
|
|
2346
|
+
vec3 a3dTexturedPbrIridescenceColor(float minimumThickness, float maximumThickness, float iridescenceIor, float nDotV) {
|
|
2978
2347
|
float thickness = clamp((minimumThickness + maximumThickness) * 0.5, 0.0, 1200.0);
|
|
2979
|
-
float
|
|
2348
|
+
float opticalThicknessPhase = clamp((thickness - 100.0) / 1100.0, 0.0, 1.0) * 6.2831853;
|
|
2980
2349
|
float iorShift = clamp((iridescenceIor - 1.0) / 2.0, 0.0, 1.0) * 0.65;
|
|
2981
|
-
|
|
2350
|
+
float viewPhase = pow(1.0 - clamp(nDotV, 0.0, 1.0), 1.25) * (3.2 + iridescenceIor * 1.4);
|
|
2351
|
+
float phase = opticalThicknessPhase + iorShift + viewPhase;
|
|
2352
|
+
return clamp(0.5 + 0.5 * cos(phase + vec3(0.0, 2.0943951, 4.1887902)), vec3(0.0), vec3(1.0));
|
|
2353
|
+
}
|
|
2354
|
+
float a3dTexturedPbrCharlieSheen(float nDotH, float sheenRoughness) {
|
|
2355
|
+
float alpha = max(0.07, sheenRoughness * sheenRoughness);
|
|
2356
|
+
float inverseAlpha = 1.0 / alpha;
|
|
2357
|
+
float sin2h = max(1.0 - nDotH * nDotH, 0.0078125);
|
|
2358
|
+
return (2.0 + inverseAlpha) * pow(sin2h, inverseAlpha * 0.5) / (2.0 * A3D_PI);
|
|
2359
|
+
}
|
|
2360
|
+
float a3dTexturedPbrAnisotropicDistribution(
|
|
2361
|
+
vec3 normal,
|
|
2362
|
+
vec3 halfVector,
|
|
2363
|
+
vec4 tangentFrame,
|
|
2364
|
+
float roughness,
|
|
2365
|
+
float anisotropy,
|
|
2366
|
+
float rotation
|
|
2367
|
+
) {
|
|
2368
|
+
vec3 N = normalize(normal);
|
|
2369
|
+
vec3 authoredTangent = normalize(tangentFrame.xyz);
|
|
2370
|
+
vec3 authoredBitangent = normalize(cross(N, authoredTangent)) * (tangentFrame.w < 0.0 ? -1.0 : 1.0);
|
|
2371
|
+
float c = cos(rotation);
|
|
2372
|
+
float s = sin(rotation);
|
|
2373
|
+
vec3 T = normalize(authoredTangent * c + authoredBitangent * s);
|
|
2374
|
+
vec3 B = normalize(authoredBitangent * c - authoredTangent * s);
|
|
2375
|
+
float alpha = max(0.035, roughness * roughness);
|
|
2376
|
+
float aspect = sqrt(max(0.08, 1.0 - clamp(anisotropy, 0.0, 0.98) * 0.92));
|
|
2377
|
+
float alphaT = max(0.012, alpha / aspect);
|
|
2378
|
+
float alphaB = max(0.012, alpha * aspect);
|
|
2379
|
+
float tDotH = dot(T, halfVector);
|
|
2380
|
+
float bDotH = dot(B, halfVector);
|
|
2381
|
+
float nDotH = max(dot(N, halfVector), 0.0);
|
|
2382
|
+
float denominator = tDotH * tDotH / (alphaT * alphaT)
|
|
2383
|
+
+ bDotH * bDotH / (alphaB * alphaB)
|
|
2384
|
+
+ nDotH * nDotH;
|
|
2385
|
+
return 1.0 / max(A3D_PI * alphaT * alphaB * denominator * denominator, A3D_EPSILON);
|
|
2982
2386
|
}
|
|
2983
2387
|
vec3 a3dTexturedPbrExtensionDirectLight(
|
|
2984
2388
|
vec3 normal,
|
|
2389
|
+
vec4 tangentFrame,
|
|
2985
2390
|
vec3 viewDirection,
|
|
2986
2391
|
vec3 lightDirection,
|
|
2987
2392
|
vec3 lightColor,
|
|
@@ -3010,17 +2415,21 @@ vec3 a3dTexturedPbrExtensionDirectLight(
|
|
|
3010
2415
|
float clearcoatD = a3dDistributionGGX(nDotH, clearcoatRough);
|
|
3011
2416
|
float clearcoatG = a3dGeometrySmithGGXCorrelated(nDotV, nDotL, clearcoatRough);
|
|
3012
2417
|
vec3 clearcoatLobe = clearcoatF * clearcoatD * clearcoatG * clamp(clearcoat, 0.0, 1.0) * 0.12;
|
|
3013
|
-
float
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
2418
|
+
float sheenDistribution = a3dTexturedPbrCharlieSheen(nDotH, sheenRoughness);
|
|
2419
|
+
float sheenVisibility = 1.0 / max(4.0 * (nDotV + nDotL - nDotV * nDotL), A3D_EPSILON);
|
|
2420
|
+
float sheenGrazing = pow(1.0 - nDotV, 12.0);
|
|
2421
|
+
vec3 sheenLobe = clamp(sheenColor, vec3(0.0), vec3(1.0))
|
|
2422
|
+
* (sheenDistribution * sheenVisibility * 0.012 + sheenGrazing * 0.18);
|
|
2423
|
+
float anisotropicDistribution = a3dTexturedPbrAnisotropicDistribution(N, H, tangentFrame, clearcoatRough, anisotropy, anisotropyRotation);
|
|
2424
|
+
float anisotropyShape = anisotropicDistribution / (anisotropicDistribution + 3.0);
|
|
2425
|
+
vec3 anisotropyLobe = vec3(clamp(anisotropy, 0.0, 1.0) * anisotropyShape * 0.72);
|
|
2426
|
+
vec3 iridescenceColor = a3dTexturedPbrIridescenceColor(iridescenceThicknessMinimum, iridescenceThicknessMaximum, iridescenceIor, nDotV);
|
|
3019
2427
|
vec3 iridescenceLobe = iridescenceColor * clamp(iridescence, 0.0, 1.0) * clearcoatF * pow(a3dSaturate(1.0 - nDotV), 2.0) * 0.12;
|
|
3020
2428
|
return (clearcoatLobe + sheenLobe + anisotropyLobe + iridescenceLobe) * lightColor * lightIntensity * nDotL;
|
|
3021
2429
|
}
|
|
3022
2430
|
vec3 a3dTexturedPbrExtensionEnvironmentLight(
|
|
3023
2431
|
vec3 normal,
|
|
2432
|
+
vec4 tangentFrame,
|
|
3024
2433
|
vec3 viewDirection,
|
|
3025
2434
|
vec3 specularRadiance,
|
|
3026
2435
|
float clearcoat,
|
|
@@ -3039,10 +2448,17 @@ vec3 a3dTexturedPbrExtensionEnvironmentLight(
|
|
|
3039
2448
|
float faceOn = smoothstep(0.18, 0.68, nDotV);
|
|
3040
2449
|
vec3 boundedSpecularRadiance = min(specularRadiance * mix(0.1, 0.82, faceOn), vec3(mix(0.08, 0.95, faceOn)));
|
|
3041
2450
|
vec3 clearcoatLobe = boundedSpecularRadiance * clearcoatF * clamp(clearcoat, 0.0, 1.0) * 0.045;
|
|
3042
|
-
vec3 sheenLobe = clamp(sheenColor, vec3(0.0), vec3(1.0))
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
vec3
|
|
2451
|
+
vec3 sheenLobe = clamp(sheenColor, vec3(0.0), vec3(1.0))
|
|
2452
|
+
* pow(a3dSaturate(1.0 - nDotV), 8.0)
|
|
2453
|
+
* mix(1.4, 0.75, clamp(sheenRoughness, 0.0, 1.0));
|
|
2454
|
+
vec3 N = normalize(normal);
|
|
2455
|
+
vec3 V = normalize(viewDirection);
|
|
2456
|
+
vec3 environmentDirection = normalize(vec3(0.42, 0.78, 0.46));
|
|
2457
|
+
vec3 environmentHalf = normalize(V + environmentDirection);
|
|
2458
|
+
float anisotropicDistribution = a3dTexturedPbrAnisotropicDistribution(N, environmentHalf, tangentFrame, clearcoatRoughness, anisotropy, anisotropyRotation);
|
|
2459
|
+
float anisotropyShape = anisotropicDistribution / (anisotropicDistribution + 3.0);
|
|
2460
|
+
vec3 anisotropyLobe = boundedSpecularRadiance * clamp(anisotropy, 0.0, 1.0) * anisotropyShape * 0.72;
|
|
2461
|
+
vec3 iridescenceColor = a3dTexturedPbrIridescenceColor(iridescenceThicknessMinimum, iridescenceThicknessMaximum, iridescenceIor, nDotV);
|
|
3046
2462
|
vec3 iridescenceLobe = boundedSpecularRadiance * iridescenceColor * clamp(iridescence, 0.0, 1.0) * pow(a3dSaturate(1.0 - nDotV), 2.0) * 0.09;
|
|
3047
2463
|
return clearcoatLobe + sheenLobe + anisotropyLobe + iridescenceLobe;
|
|
3048
2464
|
}
|
|
@@ -3229,8 +2645,9 @@ void main() {
|
|
|
3229
2645
|
roughness,
|
|
3230
2646
|
specular,
|
|
3231
2647
|
specularColor
|
|
3232
|
-
) + a3dTexturedPbrExtensionEnvironmentLight(
|
|
2648
|
+
) * mix(1.0, 0.18, anisotropy) + a3dTexturedPbrExtensionEnvironmentLight(
|
|
3233
2649
|
clearcoatNormalDirection,
|
|
2650
|
+
v_tangent,
|
|
3234
2651
|
viewDirection,
|
|
3235
2652
|
extensionEnvironmentSpecular,
|
|
3236
2653
|
clearcoat,
|
|
@@ -3275,7 +2692,15 @@ void main() {
|
|
|
3275
2692
|
vec2 backdropOffset = normalize(texturedRefractionDirection.xy + vec2(0.0001)) * u_transmissionBackdropRefractionScale * mix(1.25, 0.55, roughness) * clamp(u_ior - 1.0, 0.0, 2.5);
|
|
3276
2693
|
float backdropLod = clamp((roughness + volumeThickness * 0.08) * max(u_transmissionBackdropMipCount - 1.0, 0.0), 0.0, max(u_transmissionBackdropMipCount - 1.0, 0.0));
|
|
3277
2694
|
vec3 backdropRadiance = a3dTexturedPbrDecodeSrgb(textureLod(u_transmissionBackdropTexture, clamp(backdropUv + backdropOffset, vec2(0.001), vec2(0.999)), backdropLod).rgb);
|
|
3278
|
-
|
|
2695
|
+
// Scene-color refraction travels through the same participating volume as
|
|
2696
|
+
// environment refraction. Omitting texturedVolumeTint here made thickness,
|
|
2697
|
+
// attenuationDistance, and attenuationColor byte-identical whenever the
|
|
2698
|
+
// renderer-owned backdrop path was active.
|
|
2699
|
+
texturedRefractionRadiance = mix(
|
|
2700
|
+
texturedRefractionRadiance,
|
|
2701
|
+
backdropRadiance * texturedVolumeTint * texturedTransmissionAmount * mix(1.0, 1.22, texturedBackdropWeight),
|
|
2702
|
+
texturedBackdropWeight
|
|
2703
|
+
);
|
|
3279
2704
|
}
|
|
3280
2705
|
#endif
|
|
3281
2706
|
shaded = mix(shaded, shaded * 0.72 + texturedRefractionRadiance, texturedTransmissionAmount * mix(0.08, 0.58, texturedFallbackEnvironmentTransmissionEnergy));
|
|
@@ -3344,9 +2769,11 @@ void main() {
|
|
|
3344
2769
|
float directExtensionNdotV = clamp(dot(clearcoatNormalDirection, viewDirection), 0.0, 1.0);
|
|
3345
2770
|
float directExtensionGrazingGate = mix(0.18, 1.0, smoothstep(0.12, 0.58, directExtensionNdotV));
|
|
3346
2771
|
float directExtensionSpecularScale = sqrt(clamp(u_materialEnvironmentSpecularScale, 0.0, 1.0)) * directExtensionGrazingGate;
|
|
3347
|
-
shaded += a3dPbrDirectLight(mappedNormal, viewDirection, lightDirection, colorIntensity.rgb, directLightIntensity, base, metallic, roughness, specular, specularColor)
|
|
2772
|
+
shaded += a3dPbrDirectLight(mappedNormal, viewDirection, lightDirection, colorIntensity.rgb, directLightIntensity, base, metallic, roughness, specular, specularColor)
|
|
2773
|
+
* mix(1.0, 0.18, anisotropy);
|
|
3348
2774
|
shaded += a3dTexturedPbrExtensionDirectLight(
|
|
3349
2775
|
clearcoatNormalDirection,
|
|
2776
|
+
v_tangent,
|
|
3350
2777
|
viewDirection,
|
|
3351
2778
|
lightDirection,
|
|
3352
2779
|
colorIntensity.rgb,
|
|
@@ -3370,80 +2797,7 @@ void main() {
|
|
|
3370
2797
|
}
|
|
3371
2798
|
`
|
|
3372
2799
|
});
|
|
3373
|
-
library
|
|
3374
|
-
name: DEFAULT_ENVIRONMENT_BACKGROUND_SHADER_NAME,
|
|
3375
|
-
marker: DEFAULT_ENVIRONMENT_BACKGROUND_SHADER_MARKER,
|
|
3376
|
-
vertex: `#version 300 es
|
|
3377
|
-
// ${DEFAULT_ENVIRONMENT_BACKGROUND_SHADER_MARKER}
|
|
3378
|
-
precision highp float;
|
|
3379
|
-
layout(location = 0) in vec3 a_position;
|
|
3380
|
-
out vec2 v_backgroundNdc;
|
|
3381
|
-
void main() {
|
|
3382
|
-
v_backgroundNdc = a_position.xy;
|
|
3383
|
-
gl_Position = vec4(a_position.xy, 1.0, 1.0);
|
|
3384
|
-
}
|
|
3385
|
-
`,
|
|
3386
|
-
fragment: `#version 300 es
|
|
3387
|
-
// ${DEFAULT_ENVIRONMENT_BACKGROUND_SHADER_MARKER}
|
|
3388
|
-
precision highp float;
|
|
3389
|
-
uniform sampler2D u_environmentBackgroundTexture;
|
|
3390
|
-
uniform samplerCube u_environmentBackgroundCubeTexture;
|
|
3391
|
-
uniform float u_environmentBackgroundProjection;
|
|
3392
|
-
uniform float u_environmentBackgroundRotation;
|
|
3393
|
-
uniform float u_environmentBackgroundIntensity;
|
|
3394
|
-
uniform float u_environmentBackgroundEncoding;
|
|
3395
|
-
uniform float u_outputColorSpace;
|
|
3396
|
-
uniform mat4 u_environmentBackgroundInverseViewProjection;
|
|
3397
|
-
in vec2 v_backgroundNdc;
|
|
3398
|
-
out vec4 outColor;
|
|
3399
|
-
vec2 a3dBackgroundEquirectUv(vec3 direction) {
|
|
3400
|
-
vec3 d = normalize(direction);
|
|
3401
|
-
float u = atan(d.z, d.x) / 6.28318530718 + 0.5;
|
|
3402
|
-
float v = acos(clamp(d.y, -1.0, 1.0)) / 3.14159265359;
|
|
3403
|
-
return vec2(fract(u), clamp(v, 0.0, 1.0));
|
|
3404
|
-
}
|
|
3405
|
-
vec3 a3dRotateBackgroundDirection(vec3 direction, float rotation) {
|
|
3406
|
-
float angle = rotation * 6.28318530718;
|
|
3407
|
-
float c = cos(angle);
|
|
3408
|
-
float s = sin(angle);
|
|
3409
|
-
vec3 d = normalize(direction);
|
|
3410
|
-
return normalize(vec3(c * d.x - s * d.z, d.y, s * d.x + c * d.z));
|
|
3411
|
-
}
|
|
3412
|
-
vec3 a3dBackgroundDirectionFromNdc(vec2 ndc) {
|
|
3413
|
-
vec4 nearPoint = u_environmentBackgroundInverseViewProjection * vec4(ndc, -1.0, 1.0);
|
|
3414
|
-
vec4 farPoint = u_environmentBackgroundInverseViewProjection * vec4(ndc, 1.0, 1.0);
|
|
3415
|
-
vec3 nearWorld = nearPoint.xyz / max(nearPoint.w, 0.00001);
|
|
3416
|
-
vec3 farWorld = farPoint.xyz / max(farPoint.w, 0.00001);
|
|
3417
|
-
return normalize(farWorld - nearWorld);
|
|
3418
|
-
}
|
|
3419
|
-
vec3 a3dBackgroundDecodeRgbe(vec4 encodedSample) {
|
|
3420
|
-
float exponent = encodedSample.a * 255.0;
|
|
3421
|
-
float scale = exponent <= 0.0 ? 0.0 : exp2(exponent - 128.0) * (255.0 / 256.0);
|
|
3422
|
-
return max(encodedSample.rgb * scale, vec3(0.0));
|
|
3423
|
-
}
|
|
3424
|
-
vec3 a3dBackgroundDecode(vec4 encodedSample) {
|
|
3425
|
-
if (u_environmentBackgroundEncoding > 1.5) return a3dBackgroundDecodeRgbe(encodedSample);
|
|
3426
|
-
return max(encodedSample.rgb, vec3(0.0));
|
|
3427
|
-
}
|
|
3428
|
-
vec3 a3dBackgroundEncodeOutput(vec3 linearColor) {
|
|
3429
|
-
vec3 color = max(linearColor, vec3(0.0));
|
|
3430
|
-
vec3 filmic = clamp((color * (2.51 * color + 0.03)) / (color * (2.43 * color + 0.59) + 0.14), vec3(0.0), vec3(1.0));
|
|
3431
|
-
vec3 srgb = pow(filmic, vec3(1.0 / 2.2));
|
|
3432
|
-
return mix(color, srgb, step(0.5, u_outputColorSpace));
|
|
3433
|
-
}
|
|
3434
|
-
void main() {
|
|
3435
|
-
vec3 direction = a3dRotateBackgroundDirection(a3dBackgroundDirectionFromNdc(v_backgroundNdc), u_environmentBackgroundRotation);
|
|
3436
|
-
vec4 encodedSample = vec4(0.0, 0.0, 0.0, 1.0);
|
|
3437
|
-
if (u_environmentBackgroundProjection > 1.5) {
|
|
3438
|
-
encodedSample = texture(u_environmentBackgroundCubeTexture, direction);
|
|
3439
|
-
} else {
|
|
3440
|
-
encodedSample = texture(u_environmentBackgroundTexture, a3dBackgroundEquirectUv(direction));
|
|
3441
|
-
}
|
|
3442
|
-
vec3 color = a3dBackgroundDecode(encodedSample) * max(u_environmentBackgroundIntensity, 0.0);
|
|
3443
|
-
outColor = vec4(a3dBackgroundEncodeOutput(color), 1.0);
|
|
3444
|
-
}
|
|
3445
|
-
`
|
|
3446
|
-
});
|
|
2800
|
+
registerLeanEnvironmentBackgroundShader(library);
|
|
3447
2801
|
library.register({
|
|
3448
2802
|
name: DEFAULT_SCREEN_SPACE_LINE_SHADER_NAME,
|
|
3449
2803
|
marker: DEFAULT_SCREEN_SPACE_LINE_SHADER_MARKER,
|
|
@@ -3547,27 +2901,7 @@ void main() {
|
|
|
3547
2901
|
}
|
|
3548
2902
|
`
|
|
3549
2903
|
});
|
|
3550
|
-
library
|
|
3551
|
-
name: DEFAULT_DEPTH_SHADER_NAME,
|
|
3552
|
-
marker: DEFAULT_DEPTH_SHADER_MARKER,
|
|
3553
|
-
vertex: `#version 300 es
|
|
3554
|
-
// ${DEFAULT_DEPTH_SHADER_MARKER}
|
|
3555
|
-
precision highp float;
|
|
3556
|
-
layout(location = 0) in vec3 a_position;
|
|
3557
|
-
uniform mat4 u_modelViewProjection;
|
|
3558
|
-
void main() {
|
|
3559
|
-
gl_Position = u_modelViewProjection * vec4(a_position, 1.0);
|
|
3560
|
-
}
|
|
3561
|
-
`,
|
|
3562
|
-
fragment: `#version 300 es
|
|
3563
|
-
// ${DEFAULT_DEPTH_SHADER_MARKER}
|
|
3564
|
-
precision highp float;
|
|
3565
|
-
out vec4 outColor;
|
|
3566
|
-
void main() {
|
|
3567
|
-
outColor = vec4(vec3(gl_FragCoord.z), 1.0);
|
|
3568
|
-
}
|
|
3569
|
-
`
|
|
3570
|
-
});
|
|
2904
|
+
registerLeanDepthShader(library);
|
|
3571
2905
|
// Register the animation/cel toon program (banded N·L ramp + Fresnel rim).
|
|
3572
2906
|
// This is a real GLSL program compiled through the same library path as the
|
|
3573
2907
|
// built-in shaders; AnimationToonMaterial targets it via ANIMATION_TOON_SHADER_NAME.
|