@flighthq/scene3d-gl 0.2.1-next.840.857425c
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/dist/anisotropyPbrGlMeshMaterialRenderer.d.ts +4 -0
- package/dist/anisotropyPbrGlMeshMaterialRenderer.d.ts.map +1 -0
- package/dist/anisotropyPbrGlMeshMaterialRenderer.js +45 -0
- package/dist/anisotropyPbrGlMeshMaterialRenderer.js.map +1 -0
- package/dist/blinnPhongGlMeshMaterialRenderer.d.ts +4 -0
- package/dist/blinnPhongGlMeshMaterialRenderer.d.ts.map +1 -0
- package/dist/blinnPhongGlMeshMaterialRenderer.js +102 -0
- package/dist/blinnPhongGlMeshMaterialRenderer.js.map +1 -0
- package/dist/clearcoatPbrGlMeshMaterialRenderer.d.ts +4 -0
- package/dist/clearcoatPbrGlMeshMaterialRenderer.d.ts.map +1 -0
- package/dist/clearcoatPbrGlMeshMaterialRenderer.js +45 -0
- package/dist/clearcoatPbrGlMeshMaterialRenderer.js.map +1 -0
- package/dist/customShaderGlMeshMaterialRenderer.d.ts +6 -0
- package/dist/customShaderGlMeshMaterialRenderer.d.ts.map +1 -0
- package/dist/customShaderGlMeshMaterialRenderer.js +136 -0
- package/dist/customShaderGlMeshMaterialRenderer.js.map +1 -0
- package/dist/depthGlMeshMaterialRenderer.d.ts +4 -0
- package/dist/depthGlMeshMaterialRenderer.d.ts.map +1 -0
- package/dist/depthGlMeshMaterialRenderer.js +36 -0
- package/dist/depthGlMeshMaterialRenderer.js.map +1 -0
- package/dist/drawGlScene3D.d.ts +3 -0
- package/dist/drawGlScene3D.d.ts.map +1 -0
- package/dist/drawGlScene3D.js +251 -0
- package/dist/drawGlScene3D.js.map +1 -0
- package/dist/emissiveGlMeshMaterialRenderer.d.ts +4 -0
- package/dist/emissiveGlMeshMaterialRenderer.d.ts.map +1 -0
- package/dist/emissiveGlMeshMaterialRenderer.js +49 -0
- package/dist/emissiveGlMeshMaterialRenderer.js.map +1 -0
- package/dist/enableGlScene3DColorSpaceGuards.d.ts +4 -0
- package/dist/enableGlScene3DColorSpaceGuards.d.ts.map +1 -0
- package/dist/enableGlScene3DColorSpaceGuards.js +22 -0
- package/dist/enableGlScene3DColorSpaceGuards.js.map +1 -0
- package/dist/enableGlScene3DCustomShaderGuards.d.ts +4 -0
- package/dist/enableGlScene3DCustomShaderGuards.d.ts.map +1 -0
- package/dist/enableGlScene3DCustomShaderGuards.js +71 -0
- package/dist/enableGlScene3DCustomShaderGuards.js.map +1 -0
- package/dist/enableGlScene3DDeformGuards.d.ts +4 -0
- package/dist/enableGlScene3DDeformGuards.d.ts.map +1 -0
- package/dist/enableGlScene3DDeformGuards.js +42 -0
- package/dist/enableGlScene3DDeformGuards.js.map +1 -0
- package/dist/enableGlScene3DForwardLightSelectionGuards.d.ts +4 -0
- package/dist/enableGlScene3DForwardLightSelectionGuards.d.ts.map +1 -0
- package/dist/enableGlScene3DForwardLightSelectionGuards.js +21 -0
- package/dist/enableGlScene3DForwardLightSelectionGuards.js.map +1 -0
- package/dist/explainGlScene3DForwardLightSelection.d.ts +3 -0
- package/dist/explainGlScene3DForwardLightSelection.d.ts.map +1 -0
- package/dist/explainGlScene3DForwardLightSelection.js +19 -0
- package/dist/explainGlScene3DForwardLightSelection.js.map +1 -0
- package/dist/glClassicPrelude.d.ts +9 -0
- package/dist/glClassicPrelude.d.ts.map +1 -0
- package/dist/glClassicPrelude.js +288 -0
- package/dist/glClassicPrelude.js.map +1 -0
- package/dist/glDebugPrelude.d.ts +9 -0
- package/dist/glDebugPrelude.d.ts.map +1 -0
- package/dist/glDebugPrelude.js +143 -0
- package/dist/glDebugPrelude.js.map +1 -0
- package/dist/glEnvironmentCube.d.ts +5 -0
- package/dist/glEnvironmentCube.d.ts.map +1 -0
- package/dist/glEnvironmentCube.js +65 -0
- package/dist/glEnvironmentCube.js.map +1 -0
- package/dist/glEnvironmentIblBake.d.ts +4 -0
- package/dist/glEnvironmentIblBake.d.ts.map +1 -0
- package/dist/glEnvironmentIblBake.js +365 -0
- package/dist/glEnvironmentIblBake.js.map +1 -0
- package/dist/glEnvironmentSkybox.d.ts +3 -0
- package/dist/glEnvironmentSkybox.d.ts.map +1 -0
- package/dist/glEnvironmentSkybox.js +95 -0
- package/dist/glEnvironmentSkybox.js.map +1 -0
- package/dist/glLitProgram.d.ts +5 -0
- package/dist/glLitProgram.d.ts.map +1 -0
- package/dist/glLitProgram.js +211 -0
- package/dist/glLitProgram.js.map +1 -0
- package/dist/glMatcapPrelude.d.ts +8 -0
- package/dist/glMatcapPrelude.d.ts.map +1 -0
- package/dist/glMatcapPrelude.js +118 -0
- package/dist/glMatcapPrelude.js.map +1 -0
- package/dist/glMeshMaterialRegistry.d.ts +5 -0
- package/dist/glMeshMaterialRegistry.d.ts.map +1 -0
- package/dist/glMeshMaterialRegistry.js +29 -0
- package/dist/glMeshMaterialRegistry.js.map +1 -0
- package/dist/glMeshProgram.d.ts +14 -0
- package/dist/glMeshProgram.d.ts.map +1 -0
- package/dist/glMeshProgram.js +193 -0
- package/dist/glMeshProgram.js.map +1 -0
- package/dist/glMeshUpload.d.ts +4 -0
- package/dist/glMeshUpload.d.ts.map +1 -0
- package/dist/glMeshUpload.js +190 -0
- package/dist/glMeshUpload.js.map +1 -0
- package/dist/glParticleEmitter3D.d.ts +4 -0
- package/dist/glParticleEmitter3D.d.ts.map +1 -0
- package/dist/glParticleEmitter3D.js +342 -0
- package/dist/glParticleEmitter3D.js.map +1 -0
- package/dist/glPbrPrelude.d.ts +8 -0
- package/dist/glPbrPrelude.d.ts.map +1 -0
- package/dist/glPbrPrelude.js +569 -0
- package/dist/glPbrPrelude.js.map +1 -0
- package/dist/glPbrProgramCache.d.ts +4 -0
- package/dist/glPbrProgramCache.d.ts.map +1 -0
- package/dist/glPbrProgramCache.js +63 -0
- package/dist/glPbrProgramCache.js.map +1 -0
- package/dist/glPbrStandardBlock.d.ts +13 -0
- package/dist/glPbrStandardBlock.d.ts.map +1 -0
- package/dist/glPbrStandardBlock.js +107 -0
- package/dist/glPbrStandardBlock.js.map +1 -0
- package/dist/glScene3DRuntime.d.ts +5 -0
- package/dist/glScene3DRuntime.d.ts.map +1 -0
- package/dist/glScene3DRuntime.js +99 -0
- package/dist/glScene3DRuntime.js.map +1 -0
- package/dist/glScene3DTestHelper.d.ts +20 -0
- package/dist/glScene3DTestHelper.d.ts.map +1 -0
- package/dist/glScene3DTestHelper.js +178 -0
- package/dist/glScene3DTestHelper.js.map +1 -0
- package/dist/glScene3DTime.d.ts +4 -0
- package/dist/glScene3DTime.d.ts.map +1 -0
- package/dist/glScene3DTime.js +18 -0
- package/dist/glScene3DTime.js.map +1 -0
- package/dist/glShadedBuiltInModifiers.d.ts +11 -0
- package/dist/glShadedBuiltInModifiers.d.ts.map +1 -0
- package/dist/glShadedBuiltInModifiers.js +386 -0
- package/dist/glShadedBuiltInModifiers.js.map +1 -0
- package/dist/glShadedModifierSnippet.d.ts +4 -0
- package/dist/glShadedModifierSnippet.d.ts.map +1 -0
- package/dist/glShadedModifierSnippet.js +24 -0
- package/dist/glShadedModifierSnippet.js.map +1 -0
- package/dist/glShadedPrelude.d.ts +5 -0
- package/dist/glShadedPrelude.d.ts.map +1 -0
- package/dist/glShadedPrelude.js +393 -0
- package/dist/glShadedPrelude.js.map +1 -0
- package/dist/glShadowMap.d.ts +3 -0
- package/dist/glShadowMap.d.ts.map +1 -0
- package/dist/glShadowMap.js +150 -0
- package/dist/glShadowMap.js.map +1 -0
- package/dist/glToonPrelude.d.ts +7 -0
- package/dist/glToonPrelude.d.ts.map +1 -0
- package/dist/glToonPrelude.js +172 -0
- package/dist/glToonPrelude.js.map +1 -0
- package/dist/glUnlitPrelude.d.ts +9 -0
- package/dist/glUnlitPrelude.d.ts.map +1 -0
- package/dist/glUnlitPrelude.js +160 -0
- package/dist/glUnlitPrelude.js.map +1 -0
- package/dist/glWireframePrelude.d.ts +6 -0
- package/dist/glWireframePrelude.d.ts.map +1 -0
- package/dist/glWireframePrelude.js +56 -0
- package/dist/glWireframePrelude.js.map +1 -0
- package/dist/glWireframeUpload.d.ts +4 -0
- package/dist/glWireframeUpload.d.ts.map +1 -0
- package/dist/glWireframeUpload.js +85 -0
- package/dist/glWireframeUpload.js.map +1 -0
- package/dist/index.d.ts +56 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +56 -0
- package/dist/index.js.map +1 -0
- package/dist/iridescencePbrGlMeshMaterialRenderer.d.ts +4 -0
- package/dist/iridescencePbrGlMeshMaterialRenderer.d.ts.map +1 -0
- package/dist/iridescencePbrGlMeshMaterialRenderer.js +54 -0
- package/dist/iridescencePbrGlMeshMaterialRenderer.js.map +1 -0
- package/dist/lambertGlMeshMaterialRenderer.d.ts +4 -0
- package/dist/lambertGlMeshMaterialRenderer.d.ts.map +1 -0
- package/dist/lambertGlMeshMaterialRenderer.js +70 -0
- package/dist/lambertGlMeshMaterialRenderer.js.map +1 -0
- package/dist/matcapGlMeshMaterialRenderer.d.ts +4 -0
- package/dist/matcapGlMeshMaterialRenderer.d.ts.map +1 -0
- package/dist/matcapGlMeshMaterialRenderer.js +49 -0
- package/dist/matcapGlMeshMaterialRenderer.js.map +1 -0
- package/dist/normalGlMeshMaterialRenderer.d.ts +4 -0
- package/dist/normalGlMeshMaterialRenderer.d.ts.map +1 -0
- package/dist/normalGlMeshMaterialRenderer.js +39 -0
- package/dist/normalGlMeshMaterialRenderer.js.map +1 -0
- package/dist/phongGlMeshMaterialRenderer.d.ts +4 -0
- package/dist/phongGlMeshMaterialRenderer.d.ts.map +1 -0
- package/dist/phongGlMeshMaterialRenderer.js +90 -0
- package/dist/phongGlMeshMaterialRenderer.js.map +1 -0
- package/dist/prepareGlScene3DForwardLights.d.ts +3 -0
- package/dist/prepareGlScene3DForwardLights.d.ts.map +1 -0
- package/dist/prepareGlScene3DForwardLights.js +117 -0
- package/dist/prepareGlScene3DForwardLights.js.map +1 -0
- package/dist/presentGlScene3D.d.ts +3 -0
- package/dist/presentGlScene3D.d.ts.map +1 -0
- package/dist/presentGlScene3D.js +21 -0
- package/dist/presentGlScene3D.js.map +1 -0
- package/dist/registerStandardPbrGlMaterial.d.ts +3 -0
- package/dist/registerStandardPbrGlMaterial.d.ts.map +1 -0
- package/dist/registerStandardPbrGlMaterial.js +11 -0
- package/dist/registerStandardPbrGlMaterial.js.map +1 -0
- package/dist/shadedGlMeshMaterialRenderer.d.ts +4 -0
- package/dist/shadedGlMeshMaterialRenderer.d.ts.map +1 -0
- package/dist/shadedGlMeshMaterialRenderer.js +135 -0
- package/dist/shadedGlMeshMaterialRenderer.js.map +1 -0
- package/dist/sheenPbrGlMeshMaterialRenderer.d.ts +4 -0
- package/dist/sheenPbrGlMeshMaterialRenderer.d.ts.map +1 -0
- package/dist/sheenPbrGlMeshMaterialRenderer.js +54 -0
- package/dist/sheenPbrGlMeshMaterialRenderer.js.map +1 -0
- package/dist/specularGlossinessPbrGlMeshMaterialRenderer.d.ts +4 -0
- package/dist/specularGlossinessPbrGlMeshMaterialRenderer.d.ts.map +1 -0
- package/dist/specularGlossinessPbrGlMeshMaterialRenderer.js +121 -0
- package/dist/specularGlossinessPbrGlMeshMaterialRenderer.js.map +1 -0
- package/dist/specularPbrGlMeshMaterialRenderer.d.ts +4 -0
- package/dist/specularPbrGlMeshMaterialRenderer.d.ts.map +1 -0
- package/dist/specularPbrGlMeshMaterialRenderer.js +55 -0
- package/dist/specularPbrGlMeshMaterialRenderer.js.map +1 -0
- package/dist/standardPbrGlMeshMaterialRenderer.d.ts +3 -0
- package/dist/standardPbrGlMeshMaterialRenderer.d.ts.map +1 -0
- package/dist/standardPbrGlMeshMaterialRenderer.js +35 -0
- package/dist/standardPbrGlMeshMaterialRenderer.js.map +1 -0
- package/dist/subsurfacePbrGlMeshMaterialRenderer.d.ts +4 -0
- package/dist/subsurfacePbrGlMeshMaterialRenderer.d.ts.map +1 -0
- package/dist/subsurfacePbrGlMeshMaterialRenderer.js +57 -0
- package/dist/subsurfacePbrGlMeshMaterialRenderer.js.map +1 -0
- package/dist/toonGlMeshMaterialRenderer.d.ts +4 -0
- package/dist/toonGlMeshMaterialRenderer.d.ts.map +1 -0
- package/dist/toonGlMeshMaterialRenderer.js +81 -0
- package/dist/toonGlMeshMaterialRenderer.js.map +1 -0
- package/dist/transmissionVolumePbrGlMeshMaterialRenderer.d.ts +4 -0
- package/dist/transmissionVolumePbrGlMeshMaterialRenderer.d.ts.map +1 -0
- package/dist/transmissionVolumePbrGlMeshMaterialRenderer.js +62 -0
- package/dist/transmissionVolumePbrGlMeshMaterialRenderer.js.map +1 -0
- package/dist/unlitGlMeshMaterialRenderer.d.ts +4 -0
- package/dist/unlitGlMeshMaterialRenderer.d.ts.map +1 -0
- package/dist/unlitGlMeshMaterialRenderer.js +61 -0
- package/dist/unlitGlMeshMaterialRenderer.js.map +1 -0
- package/dist/vertexColorGlMeshMaterialRenderer.d.ts +4 -0
- package/dist/vertexColorGlMeshMaterialRenderer.d.ts.map +1 -0
- package/dist/vertexColorGlMeshMaterialRenderer.js +54 -0
- package/dist/vertexColorGlMeshMaterialRenderer.js.map +1 -0
- package/dist/wireframeGlMeshMaterialRenderer.d.ts +4 -0
- package/dist/wireframeGlMeshMaterialRenderer.d.ts.map +1 -0
- package/dist/wireframeGlMeshMaterialRenderer.js +50 -0
- package/dist/wireframeGlMeshMaterialRenderer.js.map +1 -0
- package/package.json +58 -0
- package/src/anisotropyPbrGlMeshMaterialRenderer.test.ts +86 -0
- package/src/blinnPhongGlMeshMaterialRenderer.test.ts +94 -0
- package/src/clearcoatPbrGlMeshMaterialRenderer.test.ts +81 -0
- package/src/customShaderGlMeshMaterialRenderer.test.ts +169 -0
- package/src/depthGlMeshMaterialRenderer.test.ts +69 -0
- package/src/drawGlScene3D.test.ts +304 -0
- package/src/emissiveGlMeshMaterialRenderer.test.ts +60 -0
- package/src/enableGlScene3DColorSpaceGuards.test.ts +63 -0
- package/src/enableGlScene3DCustomShaderGuards.test.ts +85 -0
- package/src/enableGlScene3DDeformGuards.test.ts +98 -0
- package/src/enableGlScene3DForwardLightSelectionGuards.test.ts +84 -0
- package/src/explainGlScene3DForwardLightSelection.test.ts +32 -0
- package/src/glClassicPrelude.test.ts +214 -0
- package/src/glDebugPrelude.test.ts +94 -0
- package/src/glEnvironmentCube.test.ts +71 -0
- package/src/glEnvironmentIblBake.test.ts +31 -0
- package/src/glEnvironmentSkybox.test.ts +24 -0
- package/src/glLitProgram.test.ts +181 -0
- package/src/glMatcapPrelude.test.ts +74 -0
- package/src/glMeshMaterialRegistry.test.ts +52 -0
- package/src/glMeshProgram.test.ts +406 -0
- package/src/glMeshUpload.test.ts +311 -0
- package/src/glParticleEmitter3D.test.ts +280 -0
- package/src/glPbrPrelude.test.ts +178 -0
- package/src/glPbrProgramCache.test.ts +116 -0
- package/src/glPbrStandardBlock.test.ts +85 -0
- package/src/glScene3DRuntime.test.ts +108 -0
- package/src/glScene3DTime.test.ts +31 -0
- package/src/glShadedBuiltInModifiers.test.ts +377 -0
- package/src/glShadedModifierSnippet.test.ts +46 -0
- package/src/glShadedPrelude.test.ts +177 -0
- package/src/glShadowMap.test.ts +219 -0
- package/src/glToonPrelude.test.ts +118 -0
- package/src/glUnlitPrelude.test.ts +156 -0
- package/src/glWireframePrelude.test.ts +46 -0
- package/src/glWireframeUpload.test.ts +50 -0
- package/src/iridescencePbrGlMeshMaterialRenderer.test.ts +86 -0
- package/src/lambertGlMeshMaterialRenderer.test.ts +92 -0
- package/src/matcapGlMeshMaterialRenderer.test.ts +70 -0
- package/src/normalGlMeshMaterialRenderer.test.ts +69 -0
- package/src/phongGlMeshMaterialRenderer.test.ts +94 -0
- package/src/prepareGlScene3DForwardLights.test.ts +106 -0
- package/src/presentGlScene3D.test.ts +98 -0
- package/src/registerStandardPbrGlMaterial.test.ts +14 -0
- package/src/shadedGlMeshMaterialRenderer.test.ts +106 -0
- package/src/sheenPbrGlMeshMaterialRenderer.test.ts +83 -0
- package/src/specularGlossinessPbrGlMeshMaterialRenderer.test.ts +96 -0
- package/src/specularPbrGlMeshMaterialRenderer.test.ts +83 -0
- package/src/standardPbrGlMeshMaterialRenderer.test.ts +88 -0
- package/src/subsurfacePbrGlMeshMaterialRenderer.test.ts +86 -0
- package/src/toonGlMeshMaterialRenderer.test.ts +92 -0
- package/src/transmissionVolumePbrGlMeshMaterialRenderer.test.ts +93 -0
- package/src/unlitGlMeshMaterialRenderer.test.ts +88 -0
- package/src/vertexColorGlMeshMaterialRenderer.test.ts +60 -0
- package/src/wireframeGlMeshMaterialRenderer.test.ts +69 -0
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { MAX_FORWARD_LIGHTS } from '@flighthq/types';
|
|
2
|
+
import { GL_MESH_LIGHT_BLOCK_GLSL, resolveGlLitLocations } from './glLitProgram';
|
|
3
|
+
import { GL_SKIN_VERTEX_DECLARATIONS_GLSL, GL_UV_TRANSFORM_VERTEX_GLSL, compileGlProgram, ensureGlScene3DProgram, } from './glMeshProgram';
|
|
4
|
+
import { getGlScene3DRuntime } from './glScene3DRuntime';
|
|
5
|
+
// A short, stable, order-independent string identity for a classic define key, used as the program-
|
|
6
|
+
// cache key. The lighting model is encoded first (l/p/b) so the three models never collide, followed
|
|
7
|
+
// by the feature flags. Two keys with the same model + flags produce the same string and so share a
|
|
8
|
+
// compiled program.
|
|
9
|
+
export function buildGlClassicDefineKey(key) {
|
|
10
|
+
const model = key.lightingModel === 'phong' ? 'p' : key.lightingModel === 'blinnphong' ? 'b' : 'l';
|
|
11
|
+
return `${model}${key.alphaMaskEnabled ? 'm' : '-'}${key.hasDiffuseMap ? 'd' : '-'}${key.hasSpecularMap ? 's' : '-'}${key.hasNormalMap ? 'n' : '-'}${key.hasAlphaMap ? 'a' : '-'}${key.hasUvTransform ? 'u' : '-'}${key.hasSkin ? 'k' : '-'}`;
|
|
12
|
+
}
|
|
13
|
+
// Compiles the classic uber-shader for a define key, links it, and resolves its uniform locations.
|
|
14
|
+
// Pure GL work — no caching — used by ensureGlClassicProgram. Throws on a compile/link failure, which
|
|
15
|
+
// is a programmer error (a malformed prelude), not an expected runtime condition.
|
|
16
|
+
export function compileGlClassicProgram(gl, key) {
|
|
17
|
+
const vertexSource = getGlClassicVertexSourceForKey(key);
|
|
18
|
+
const fragmentSource = getGlClassicFragmentSourceForKey(key);
|
|
19
|
+
const program = compileGlProgram(gl, vertexSource, fragmentSource);
|
|
20
|
+
return {
|
|
21
|
+
...resolveGlLitLocations(gl, program),
|
|
22
|
+
program,
|
|
23
|
+
locAlphaCutoff: gl.getUniformLocation(program, 'u_alphaCutoff'),
|
|
24
|
+
locAlphaMap: gl.getUniformLocation(program, 'u_alphaMap'),
|
|
25
|
+
locJointTexture: gl.getUniformLocation(program, 'u_jointTexture'),
|
|
26
|
+
locDiffuse: gl.getUniformLocation(program, 'u_diffuse'),
|
|
27
|
+
locDiffuseMap: gl.getUniformLocation(program, 'u_diffuseMap'),
|
|
28
|
+
locModel: gl.getUniformLocation(program, 'u_model'),
|
|
29
|
+
locNormalMap: gl.getUniformLocation(program, 'u_normalMap'),
|
|
30
|
+
locNormalMatrix: gl.getUniformLocation(program, 'u_normalMatrix'),
|
|
31
|
+
locNormalScale: gl.getUniformLocation(program, 'u_normalScale'),
|
|
32
|
+
locShininess: gl.getUniformLocation(program, 'u_shininess'),
|
|
33
|
+
locSpecular: gl.getUniformLocation(program, 'u_specular'),
|
|
34
|
+
locSpecularMap: gl.getUniformLocation(program, 'u_specularMap'),
|
|
35
|
+
locViewProjection: gl.getUniformLocation(program, 'u_viewProjection'),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
// Resolves the classic program for a define key, compiling and caching it on first use through the
|
|
39
|
+
// shared scene program cache under the `classic:` family namespace, so each model + feature variant
|
|
40
|
+
// is compiled at most once per state and reused every frame.
|
|
41
|
+
export function ensureGlClassicProgram(state, key) {
|
|
42
|
+
// Fold the render-state skinned-run flag into the variant so a skinned draw of an otherwise-identical
|
|
43
|
+
// material compiles + caches its own HAS_SKIN program, without the material renderer knowing.
|
|
44
|
+
const fullKey = {
|
|
45
|
+
...key,
|
|
46
|
+
hasSkin: getGlScene3DRuntime(state).activeSkinnedRun,
|
|
47
|
+
};
|
|
48
|
+
return ensureGlScene3DProgram(state, `classic:${buildGlClassicDefineKey(fullKey)}`, (gl) => compileGlClassicProgram(gl, fullKey));
|
|
49
|
+
}
|
|
50
|
+
// The fragment shader body (everything after the "#version 300 es" + defines block). Implements the
|
|
51
|
+
// classic Lambert diffuse term plus an optional Phong / BlinnPhong specular lobe over one directional
|
|
52
|
+
// + one ambient light, and writes linear HDR radiance to fragColor.
|
|
53
|
+
export function getGlClassicFragmentSource() {
|
|
54
|
+
return CLASSIC_FRAGMENT_BODY;
|
|
55
|
+
}
|
|
56
|
+
// The full fragment source for a define key (define block + body), ready to hand to the GL compiler.
|
|
57
|
+
export function getGlClassicFragmentSourceForKey(key) {
|
|
58
|
+
return buildGlClassicDefineSource(key) + CLASSIC_FRAGMENT_BODY;
|
|
59
|
+
}
|
|
60
|
+
// The vertex shader body (everything after the "#version 300 es" + defines block). Transforms the
|
|
61
|
+
// canonical mesh vertex (position/normal/tangent/uv0) by the model and view-projection matrices and
|
|
62
|
+
// passes world-space position, normal, tangent, and uv to the fragment scene2d — the same vertex shape
|
|
63
|
+
// as the PBR family.
|
|
64
|
+
export function getGlClassicVertexSource() {
|
|
65
|
+
return CLASSIC_VERTEX_BODY;
|
|
66
|
+
}
|
|
67
|
+
// The full vertex source for a define key (define block + optional skin declarations + body), ready to
|
|
68
|
+
// hand to the GL compiler. The skin GLSL is vertex-only (its `in` attributes are illegal in a fragment
|
|
69
|
+
// shader), so it is spliced here rather than into the shared define block.
|
|
70
|
+
export function getGlClassicVertexSourceForKey(key) {
|
|
71
|
+
const skin = key.hasSkin ? GL_SKIN_VERTEX_DECLARATIONS_GLSL : '';
|
|
72
|
+
return buildGlClassicDefineSource(key) + skin + CLASSIC_VERTEX_BODY;
|
|
73
|
+
}
|
|
74
|
+
// Builds the leading "#version 300 es\n#define ..." block for a classic define key, to be prepended
|
|
75
|
+
// to the vertex and fragment prelude bodies before compile. Pure string assembly; the same key always
|
|
76
|
+
// yields the same source, which is what makes the program cache by define key sound.
|
|
77
|
+
function buildGlClassicDefineSource(key) {
|
|
78
|
+
let defines = `#version 300 es\n#define MAX_FORWARD_LIGHTS ${MAX_FORWARD_LIGHTS}\n`;
|
|
79
|
+
if (key.lightingModel === 'phong')
|
|
80
|
+
defines += '#define LIGHTING_PHONG\n';
|
|
81
|
+
if (key.lightingModel === 'blinnphong')
|
|
82
|
+
defines += '#define LIGHTING_BLINNPHONG\n';
|
|
83
|
+
if (key.alphaMaskEnabled)
|
|
84
|
+
defines += '#define ALPHA_MASK\n';
|
|
85
|
+
if (key.hasDiffuseMap)
|
|
86
|
+
defines += '#define HAS_DIFFUSE_MAP\n';
|
|
87
|
+
if (key.hasSpecularMap)
|
|
88
|
+
defines += '#define HAS_SPECULAR_MAP\n';
|
|
89
|
+
if (key.hasNormalMap)
|
|
90
|
+
defines += '#define HAS_NORMAL_MAP\n';
|
|
91
|
+
if (key.hasAlphaMap)
|
|
92
|
+
defines += '#define HAS_ALPHA_MAP\n';
|
|
93
|
+
if (key.hasUvTransform)
|
|
94
|
+
defines += '#define HAS_UV_TRANSFORM\n';
|
|
95
|
+
if (key.hasSkin)
|
|
96
|
+
defines += '#define HAS_SKIN\n';
|
|
97
|
+
return defines;
|
|
98
|
+
}
|
|
99
|
+
const CLASSIC_VERTEX_BODY = `
|
|
100
|
+
layout(location = 0) in vec3 a_position;
|
|
101
|
+
layout(location = 1) in vec3 a_normal;
|
|
102
|
+
layout(location = 2) in vec4 a_tangent;
|
|
103
|
+
layout(location = 3) in vec2 a_uv0;
|
|
104
|
+
|
|
105
|
+
uniform mat4 u_viewProjection;
|
|
106
|
+
uniform mat4 u_model;
|
|
107
|
+
uniform mat3 u_normalMatrix;
|
|
108
|
+
${GL_UV_TRANSFORM_VERTEX_GLSL}
|
|
109
|
+
out vec3 v_worldPosition;
|
|
110
|
+
out vec3 v_normal;
|
|
111
|
+
out vec4 v_tangent;
|
|
112
|
+
out vec2 v_uv0;
|
|
113
|
+
|
|
114
|
+
void main() {
|
|
115
|
+
#ifdef HAS_SKIN
|
|
116
|
+
mat4 skin = skinMatrix();
|
|
117
|
+
vec4 localPosition = skin * vec4(a_position, 1.0);
|
|
118
|
+
vec3 localNormal = mat3(skin) * a_normal;
|
|
119
|
+
vec3 localTangent = mat3(skin) * a_tangent.xyz;
|
|
120
|
+
#else
|
|
121
|
+
vec4 localPosition = vec4(a_position, 1.0);
|
|
122
|
+
vec3 localNormal = a_normal;
|
|
123
|
+
vec3 localTangent = a_tangent.xyz;
|
|
124
|
+
#endif
|
|
125
|
+
vec4 worldPosition = u_model * localPosition;
|
|
126
|
+
v_worldPosition = worldPosition.xyz;
|
|
127
|
+
v_normal = u_normalMatrix * localNormal;
|
|
128
|
+
v_tangent = vec4(u_normalMatrix * localTangent, a_tangent.w);
|
|
129
|
+
v_uv0 = applyUvTransform(a_uv0);
|
|
130
|
+
gl_Position = u_viewProjection * worldPosition;
|
|
131
|
+
}
|
|
132
|
+
`;
|
|
133
|
+
// LIGHTING_PHONG / LIGHTING_BLINNPHONG select the specular geometry; neither define = Lambert (no
|
|
134
|
+
// specular branch). u_specular / u_shininess / u_normalMap / u_normalScale exist only when a specular
|
|
135
|
+
// model is compiled in, so they are guarded by the same #ifdef as their use.
|
|
136
|
+
const CLASSIC_FRAGMENT_BODY = `
|
|
137
|
+
precision highp float;
|
|
138
|
+
|
|
139
|
+
in vec3 v_worldPosition;
|
|
140
|
+
in vec3 v_normal;
|
|
141
|
+
in vec4 v_tangent;
|
|
142
|
+
in vec2 v_uv0;
|
|
143
|
+
|
|
144
|
+
uniform vec4 u_diffuse;
|
|
145
|
+
uniform float u_alphaCutoff;
|
|
146
|
+
${GL_MESH_LIGHT_BLOCK_GLSL}
|
|
147
|
+
#if defined(LIGHTING_PHONG) || defined(LIGHTING_BLINNPHONG)
|
|
148
|
+
uniform vec4 u_specular;
|
|
149
|
+
uniform float u_shininess;
|
|
150
|
+
uniform float u_normalScale;
|
|
151
|
+
#endif
|
|
152
|
+
|
|
153
|
+
#ifdef HAS_DIFFUSE_MAP
|
|
154
|
+
uniform sampler2D u_diffuseMap;
|
|
155
|
+
#endif
|
|
156
|
+
#ifdef HAS_SPECULAR_MAP
|
|
157
|
+
uniform sampler2D u_specularMap;
|
|
158
|
+
#endif
|
|
159
|
+
#ifdef HAS_NORMAL_MAP
|
|
160
|
+
uniform sampler2D u_normalMap;
|
|
161
|
+
#endif
|
|
162
|
+
#ifdef HAS_ALPHA_MAP
|
|
163
|
+
uniform sampler2D u_alphaMap;
|
|
164
|
+
#endif
|
|
165
|
+
|
|
166
|
+
uniform float u_objectAlpha;
|
|
167
|
+
|
|
168
|
+
out vec4 fragColor;
|
|
169
|
+
|
|
170
|
+
// sRgb albedo texels are gamma-encoded; decode to linear before lighting.
|
|
171
|
+
vec3 srgbToLinear(vec3 c) {
|
|
172
|
+
vec3 lo = c / 12.92;
|
|
173
|
+
vec3 hi = pow((c + 0.055) / 1.055, vec3(2.4));
|
|
174
|
+
return mix(lo, hi, step(0.04045, c));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// The classic shading for ONE light: Lambert diffuse plus the optional Phong/BlinnPhong specular
|
|
178
|
+
// lobe. Every light type (directional, point, spot) routes through this one BRDF so they never fork
|
|
179
|
+
// the shading model — the caller supplies the surface->light direction and the light's (attenuated,
|
|
180
|
+
// cone-scaled) radiance. Specular reads the view vector and material specular/shininess from globals.
|
|
181
|
+
vec3 shadeClassicLight(vec3 normal, vec3 lightDir, vec3 lightColor, vec3 diffuseRgb) {
|
|
182
|
+
float nDotL = max(dot(normal, lightDir), 0.0);
|
|
183
|
+
vec3 result = diffuseRgb * nDotL * lightColor;
|
|
184
|
+
#if defined(LIGHTING_PHONG) || defined(LIGHTING_BLINNPHONG)
|
|
185
|
+
if (nDotL > 0.0) {
|
|
186
|
+
vec3 viewDir = normalize(u_cameraPosition - v_worldPosition);
|
|
187
|
+
vec3 specularColor = u_specular.rgb;
|
|
188
|
+
#ifdef HAS_SPECULAR_MAP
|
|
189
|
+
specularColor *= srgbToLinear(texture(u_specularMap, v_uv0).rgb);
|
|
190
|
+
#endif
|
|
191
|
+
#ifdef LIGHTING_PHONG
|
|
192
|
+
// Phong: reflection-vector specular.
|
|
193
|
+
vec3 reflectDir = reflect(-lightDir, normal);
|
|
194
|
+
float specAngle = max(dot(reflectDir, viewDir), 0.0);
|
|
195
|
+
#else
|
|
196
|
+
// BlinnPhong: half-vector specular.
|
|
197
|
+
vec3 halfVec = normalize(lightDir + viewDir);
|
|
198
|
+
float specAngle = max(dot(normal, halfVec), 0.0);
|
|
199
|
+
#endif
|
|
200
|
+
float specular = pow(specAngle, max(u_shininess, 1.0));
|
|
201
|
+
result += specular * specularColor * lightColor;
|
|
202
|
+
}
|
|
203
|
+
#endif
|
|
204
|
+
return result;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
void main() {
|
|
208
|
+
vec4 diffuse = u_diffuse;
|
|
209
|
+
#ifdef HAS_DIFFUSE_MAP
|
|
210
|
+
vec4 sampledDiffuse = texture(u_diffuseMap, v_uv0);
|
|
211
|
+
diffuse.rgb *= srgbToLinear(sampledDiffuse.rgb);
|
|
212
|
+
diffuse.a *= sampledDiffuse.a;
|
|
213
|
+
#endif
|
|
214
|
+
|
|
215
|
+
// Dedicated coverage (opacity) map: its green channel is linear data, multiplied into alpha before
|
|
216
|
+
// the alpha-mask cutoff so 'mask' cutout and 'blend' transparency both see the combined coverage.
|
|
217
|
+
#ifdef HAS_ALPHA_MAP
|
|
218
|
+
diffuse.a *= texture(u_alphaMap, v_uv0).g;
|
|
219
|
+
#endif
|
|
220
|
+
|
|
221
|
+
#ifdef ALPHA_MASK
|
|
222
|
+
if (diffuse.a < u_alphaCutoff) discard;
|
|
223
|
+
#endif
|
|
224
|
+
|
|
225
|
+
vec3 geometricNormal = normalize(v_normal);
|
|
226
|
+
if (!gl_FrontFacing) geometricNormal = -geometricNormal;
|
|
227
|
+
|
|
228
|
+
vec3 normal = geometricNormal;
|
|
229
|
+
#ifdef HAS_NORMAL_MAP
|
|
230
|
+
vec3 tangent = normalize(v_tangent.xyz);
|
|
231
|
+
vec3 bitangent = cross(geometricNormal, tangent) * v_tangent.w;
|
|
232
|
+
vec3 tangentNormal = texture(u_normalMap, v_uv0).xyz * 2.0 - 1.0;
|
|
233
|
+
tangentNormal.xy *= u_normalScale;
|
|
234
|
+
mat3 tbn = mat3(tangent, bitangent, geometricNormal);
|
|
235
|
+
normal = normalize(tbn * tangentNormal);
|
|
236
|
+
#endif
|
|
237
|
+
|
|
238
|
+
vec3 radiance = vec3(0.0);
|
|
239
|
+
|
|
240
|
+
// Directional light: -direction is the surface-to-light vector (light travels along direction).
|
|
241
|
+
// Only the directional term is shadow-mapped (mirrors the PBR path); point/spot/ambient stay unshadowed.
|
|
242
|
+
// sampleDirectionalShadow returns 1.0 when no shadow map is bound (u_shadowEnabled == 0), so a classic
|
|
243
|
+
// scene that never calls drawGlScene3DShadowMap is unchanged.
|
|
244
|
+
if (u_directionalCount > 0.5) {
|
|
245
|
+
vec3 lightDir = normalize(-u_directional.xyz);
|
|
246
|
+
radiance += shadeClassicLight(normal, lightDir, u_directionalRadiance.rgb, diffuse.rgb)
|
|
247
|
+
* sampleDirectionalShadow(v_worldPosition);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// Point lights: surface->light direction with a smooth inverse-square range falloff.
|
|
251
|
+
for (int i = 0; i < MAX_FORWARD_LIGHTS; i++) {
|
|
252
|
+
if (i >= u_pointCount) break;
|
|
253
|
+
vec3 toLight = u_pointLights[i * 2 + 0].xyz - v_worldPosition;
|
|
254
|
+
float dist2 = dot(toLight, toLight);
|
|
255
|
+
vec3 lightDir = toLight * inversesqrt(max(dist2, 1e-8));
|
|
256
|
+
float atten = rangeWindow(dist2, u_pointLights[i * 2 + 1].w) / max(dist2, 1e-4);
|
|
257
|
+
radiance += shadeClassicLight(normal, lightDir, u_pointLights[i * 2 + 1].rgb * atten, diffuse.rgb);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// Spot lights: point attenuation times a smooth cone falloff between the inner/outer cosines.
|
|
261
|
+
for (int i = 0; i < MAX_FORWARD_LIGHTS; i++) {
|
|
262
|
+
if (i >= u_spotCount) break;
|
|
263
|
+
vec3 toLight = u_spotLights[i * 4 + 0].xyz - v_worldPosition;
|
|
264
|
+
float dist2 = dot(toLight, toLight);
|
|
265
|
+
vec3 lightDir = toLight * inversesqrt(max(dist2, 1e-8));
|
|
266
|
+
float atten = rangeWindow(dist2, u_spotLights[i * 4 + 1].w) / max(dist2, 1e-4);
|
|
267
|
+
float cone = smoothstep(u_spotLights[i * 4 + 3].y, u_spotLights[i * 4 + 3].x,
|
|
268
|
+
dot(normalize(u_spotLights[i * 4 + 2].xyz), -lightDir));
|
|
269
|
+
radiance += shadeClassicLight(normal, lightDir, u_spotLights[i * 4 + 1].rgb * atten * cone, diffuse.rgb);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// Ambient term: flat irradiance over the diffuse albedo.
|
|
273
|
+
if (u_ambientCount > 0.5) {
|
|
274
|
+
radiance += diffuse.rgb * u_ambientRadiance;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// Hemisphere fill: sky/ground gradient blended by the normal's vertical component.
|
|
278
|
+
for (int i = 0; i < MAX_FORWARD_LIGHTS; i++) {
|
|
279
|
+
if (i >= u_hemisphereCount) break;
|
|
280
|
+
float f = 0.5 + 0.5 * dot(normal, u_hemisphereLights[i * 3 + 2].xyz);
|
|
281
|
+
radiance += mix(u_hemisphereLights[i * 3 + 1].rgb, u_hemisphereLights[i * 3 + 0].rgb, f) * diffuse.rgb;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
fragColor = vec4(radiance, diffuse.a);
|
|
285
|
+
fragColor.a *= u_objectAlpha;
|
|
286
|
+
}
|
|
287
|
+
`;
|
|
288
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,IAAI,CAAC;IACpF,IAAI,GAAG,CAAC,aAAa,KAAK,OAAO;QAAE,OAAO,IAAI,0BAA0B,CAAC;IACzE,IAAI,GAAG,CAAC,aAAa,KAAK,YAAY;QAAE,OAAO,IAAI,+BAA+B,CAAC;IACnF,IAAI,GAAG,CAAC,gBAAgB;QAAE,OAAO,IAAI,sBAAsB,CAAC;IAC5D,IAAI,GAAG,CAAC,aAAa;QAAE,OAAO,IAAI,2BAA2B,CAAC;IAC9D,IAAI,GAAG,CAAC,cAAc;QAAE,OAAO,IAAI,4BAA4B,CAAC;IAChE,IAAI,GAAG,CAAC,YAAY;QAAE,OAAO,IAAI,0BAA0B,CAAC;IAC5D,IAAI,GAAG,CAAC,WAAW;QAAE,OAAO,IAAI,yBAAyB,CAAC;IAC1D,IAAI,GAAG,CAAC,cAAc;QAAE,OAAO,IAAI,4BAA4B,CAAC;IAChE,IAAI,GAAG,CAAC,OAAO;QAAE,OAAO,IAAI,oBAAoB,CAAC;IACjD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,mBAAmB,GAAG;;;;;;;;;EAS1B,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;CAwB5B,CAAC;AAEF,kGAAkG;AAClG,sGAAsG;AACtG,6EAA6E;AAC7E,MAAM,qBAAqB,GAAG;;;;;;;;;;EAU5B,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6IzB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { GlDebugProgram, GlDebugDefineKey, GlRenderState, Texture } from '@flighthq/types';
|
|
2
|
+
export declare function bindGlDebugNormalMap(state: GlRenderState, program: Readonly<GlDebugProgram>, normalMap: Readonly<Texture> | null, normalScale: number): void;
|
|
3
|
+
export declare function bindGlDebugRange(state: GlRenderState, program: Readonly<GlDebugProgram>, near: number, far: number): void;
|
|
4
|
+
export declare function buildGlDebugDefineKey(key: Readonly<GlDebugDefineKey>): string;
|
|
5
|
+
export declare function compileGlDebugProgram(gl: WebGL2RenderingContext, key: Readonly<GlDebugDefineKey>): GlDebugProgram;
|
|
6
|
+
export declare function ensureGlDebugProgram(state: GlRenderState, key: Readonly<GlDebugDefineKey>): GlDebugProgram;
|
|
7
|
+
export declare function getGlDebugFragmentSourceForKey(key: Readonly<GlDebugDefineKey>): string;
|
|
8
|
+
export declare function getGlDebugVertexSourceForKey(key: Readonly<GlDebugDefineKey>): string;
|
|
9
|
+
//# sourceMappingURL=glDebugPrelude.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glDebugPrelude.d.ts","sourceRoot":"","sources":["../src/glDebugPrelude.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAMhG,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,aAAa,EACpB,OAAO,EAAE,QAAQ,CAAC,cAAc,CAAC,EACjC,SAAS,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,IAAI,EACnC,WAAW,EAAE,MAAM,GAClB,IAAI,CASN;AAKD,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,aAAa,EACpB,OAAO,EAAE,QAAQ,CAAC,cAAc,CAAC,EACjC,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,MAAM,GACV,IAAI,CAIN;AAID,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,QAAQ,CAAC,gBAAgB,CAAC,GAAG,MAAM,CAE7E;AAID,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,sBAAsB,EAAE,GAAG,EAAE,QAAQ,CAAC,gBAAgB,CAAC,GAAG,cAAc,CAYjH;AAID,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,aAAa,EAAE,GAAG,EAAE,QAAQ,CAAC,gBAAgB,CAAC,GAAG,cAAc,CAE1G;AAGD,wBAAgB,8BAA8B,CAAC,GAAG,EAAE,QAAQ,CAAC,gBAAgB,CAAC,GAAG,MAAM,CAEtF;AAGD,wBAAgB,4BAA4B,CAAC,GAAG,EAAE,QAAQ,CAAC,gBAAgB,CAAC,GAAG,MAAM,CAEpF"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { hasImageResourcePixels } from '@flighthq/image';
|
|
2
|
+
import { bindGlImageResourceTexture } from '@flighthq/render-gl';
|
|
3
|
+
import { compileGlProgram, ensureGlScene3DProgram } from './glMeshProgram';
|
|
4
|
+
// Binds the optional tangent-space normal map (on texture unit 0) and its scale for the normal-mode
|
|
5
|
+
// debug material. The caller has already selected the program (beginGlMeshDraw) and set the
|
|
6
|
+
// view-projection. A no-op when no map is bound; depth mode never calls this.
|
|
7
|
+
export function bindGlDebugNormalMap(state, program, normalMap, normalScale) {
|
|
8
|
+
const gl = state.gl;
|
|
9
|
+
gl.uniform1f(program.locNormalScale, normalScale);
|
|
10
|
+
if (normalMap !== null && normalMap.image !== null && hasImageResourcePixels(normalMap.image)) {
|
|
11
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
12
|
+
bindGlImageResourceTexture(state, normalMap.image, normalMap.sampler);
|
|
13
|
+
gl.uniform1i(program.locNormalMap, 0);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
// Uploads the depth-mode linearization range (the [near, far] eye-space window mapped to [0, 1]).
|
|
17
|
+
// The caller has already selected the program and set the view-projection. Normal mode never calls
|
|
18
|
+
// this.
|
|
19
|
+
export function bindGlDebugRange(state, program, near, far) {
|
|
20
|
+
const gl = state.gl;
|
|
21
|
+
gl.uniform1f(program.locNear, near);
|
|
22
|
+
gl.uniform1f(program.locFar, far);
|
|
23
|
+
}
|
|
24
|
+
// A short, stable, order-independent string identity for a debug define key, used as the program-
|
|
25
|
+
// cache key. Two keys with the same flags produce the same string and so share a compiled program.
|
|
26
|
+
export function buildGlDebugDefineKey(key) {
|
|
27
|
+
return `${key.mode === 'depth' ? 'd' : 'n'}${key.hasNormalMap ? 'm' : '-'}`;
|
|
28
|
+
}
|
|
29
|
+
// Compiles the debug shader for a define key, links it, and resolves its uniform locations. Pure GL
|
|
30
|
+
// work — no caching — used by ensureGlDebugProgram.
|
|
31
|
+
export function compileGlDebugProgram(gl, key) {
|
|
32
|
+
const program = compileGlProgram(gl, getGlDebugVertexSourceForKey(key), getGlDebugFragmentSourceForKey(key));
|
|
33
|
+
return {
|
|
34
|
+
locFar: gl.getUniformLocation(program, 'u_far'),
|
|
35
|
+
locModel: gl.getUniformLocation(program, 'u_model'),
|
|
36
|
+
locNear: gl.getUniformLocation(program, 'u_near'),
|
|
37
|
+
locNormalMap: gl.getUniformLocation(program, 'u_normalMap'),
|
|
38
|
+
locNormalMatrix: gl.getUniformLocation(program, 'u_normalMatrix'),
|
|
39
|
+
locNormalScale: gl.getUniformLocation(program, 'u_normalScale'),
|
|
40
|
+
locViewProjection: gl.getUniformLocation(program, 'u_viewProjection'),
|
|
41
|
+
program,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
// Resolves the debug program for a define key, compiling and caching it on first use through the
|
|
45
|
+
// shared scene program cache under the `debug:` family namespace.
|
|
46
|
+
export function ensureGlDebugProgram(state, key) {
|
|
47
|
+
return ensureGlScene3DProgram(state, `debug:${buildGlDebugDefineKey(key)}`, (gl) => compileGlDebugProgram(gl, key));
|
|
48
|
+
}
|
|
49
|
+
// The full fragment source for a define key (define block + body), ready to hand to the GL compiler.
|
|
50
|
+
export function getGlDebugFragmentSourceForKey(key) {
|
|
51
|
+
return buildDefineSource(key) + DEBUG_FRAGMENT_BODY;
|
|
52
|
+
}
|
|
53
|
+
// The full vertex source for a define key (define block + body), ready to hand to the GL compiler.
|
|
54
|
+
export function getGlDebugVertexSourceForKey(key) {
|
|
55
|
+
return buildDefineSource(key) + DEBUG_VERTEX_BODY;
|
|
56
|
+
}
|
|
57
|
+
function buildDefineSource(key) {
|
|
58
|
+
let defines = '#version 300 es\n';
|
|
59
|
+
if (key.mode === 'depth')
|
|
60
|
+
defines += '#define DEPTH_MODE\n';
|
|
61
|
+
else
|
|
62
|
+
defines += '#define NORMAL_MODE\n';
|
|
63
|
+
if (key.hasNormalMap)
|
|
64
|
+
defines += '#define HAS_NORMAL_MAP\n';
|
|
65
|
+
return defines;
|
|
66
|
+
}
|
|
67
|
+
const DEBUG_VERTEX_BODY = `
|
|
68
|
+
layout(location = 0) in vec3 a_position;
|
|
69
|
+
layout(location = 1) in vec3 a_normal;
|
|
70
|
+
layout(location = 2) in vec4 a_tangent;
|
|
71
|
+
layout(location = 3) in vec2 a_uv0;
|
|
72
|
+
|
|
73
|
+
uniform mat4 u_viewProjection;
|
|
74
|
+
uniform mat4 u_model;
|
|
75
|
+
uniform mat3 u_normalMatrix;
|
|
76
|
+
|
|
77
|
+
out vec3 v_worldPosition;
|
|
78
|
+
out vec3 v_normal;
|
|
79
|
+
out vec4 v_tangent;
|
|
80
|
+
out vec2 v_uv0;
|
|
81
|
+
|
|
82
|
+
void main() {
|
|
83
|
+
vec4 worldPosition = u_model * vec4(a_position, 1.0);
|
|
84
|
+
v_worldPosition = worldPosition.xyz;
|
|
85
|
+
v_normal = u_normalMatrix * a_normal;
|
|
86
|
+
v_tangent = vec4(u_normalMatrix * a_tangent.xyz, a_tangent.w);
|
|
87
|
+
v_uv0 = a_uv0;
|
|
88
|
+
gl_Position = u_viewProjection * worldPosition;
|
|
89
|
+
}
|
|
90
|
+
`;
|
|
91
|
+
const DEBUG_FRAGMENT_BODY = `
|
|
92
|
+
precision highp float;
|
|
93
|
+
|
|
94
|
+
in vec3 v_worldPosition;
|
|
95
|
+
in vec3 v_normal;
|
|
96
|
+
in vec4 v_tangent;
|
|
97
|
+
in vec2 v_uv0;
|
|
98
|
+
|
|
99
|
+
#ifdef DEPTH_MODE
|
|
100
|
+
uniform float u_near;
|
|
101
|
+
uniform float u_far;
|
|
102
|
+
#endif
|
|
103
|
+
#ifdef NORMAL_MODE
|
|
104
|
+
uniform float u_normalScale;
|
|
105
|
+
#ifdef HAS_NORMAL_MAP
|
|
106
|
+
uniform sampler2D u_normalMap;
|
|
107
|
+
#endif
|
|
108
|
+
#endif
|
|
109
|
+
|
|
110
|
+
uniform float u_objectAlpha;
|
|
111
|
+
|
|
112
|
+
out vec4 fragColor;
|
|
113
|
+
|
|
114
|
+
void main() {
|
|
115
|
+
#ifdef DEPTH_MODE
|
|
116
|
+
// Linear view-space distance is the perspective w: 1.0 / gl_FragCoord.w == w_clip == eye distance.
|
|
117
|
+
// This is camera-agnostic (no camera near/far needed); map it across the material's [u_near, u_far]
|
|
118
|
+
// visualization window to grayscale [0, 1].
|
|
119
|
+
float eyeDepth = 1.0 / gl_FragCoord.w;
|
|
120
|
+
float d = clamp((eyeDepth - u_near) / max(u_far - u_near, 1e-6), 0.0, 1.0);
|
|
121
|
+
fragColor = vec4(vec3(d), 1.0);
|
|
122
|
+
#endif
|
|
123
|
+
#ifdef NORMAL_MODE
|
|
124
|
+
// Visualize the WORLD-space surface normal (the geometric normal carried through u_normalMatrix).
|
|
125
|
+
vec3 geometricNormal = normalize(v_normal);
|
|
126
|
+
if (!gl_FrontFacing) geometricNormal = -geometricNormal;
|
|
127
|
+
|
|
128
|
+
vec3 normal = geometricNormal;
|
|
129
|
+
#ifdef HAS_NORMAL_MAP
|
|
130
|
+
vec3 tangent = normalize(v_tangent.xyz);
|
|
131
|
+
vec3 bitangent = cross(geometricNormal, tangent) * v_tangent.w;
|
|
132
|
+
vec3 tangentNormal = texture(u_normalMap, v_uv0).xyz * 2.0 - 1.0;
|
|
133
|
+
tangentNormal.xy *= u_normalScale;
|
|
134
|
+
mat3 tbn = mat3(tangent, bitangent, geometricNormal);
|
|
135
|
+
normal = normalize(tbn * tangentNormal);
|
|
136
|
+
#endif
|
|
137
|
+
|
|
138
|
+
fragColor = vec4(normal * 0.5 + 0.5, 1.0);
|
|
139
|
+
#endif
|
|
140
|
+
fragColor.a *= u_objectAlpha;
|
|
141
|
+
}
|
|
142
|
+
`;
|
|
143
|
+
//# sourceMappingURL=glDebugPrelude.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glDebugPrelude.js","sourceRoot":"","sources":["../src/glDebugPrelude.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AAGjE,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAC3E,oGAAoG;AACpG,4FAA4F;AAC5F,8EAA8E;AAC9E,MAAM,UAAU,oBAAoB,CAClC,KAAoB,EACpB,OAAiC,EACjC,SAAmC,EACnC,WAAmB;IAEnB,MAAM,EAAE,GAAG,KAAK,CAAC,EAAE,CAAC;IACpB,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC;IAElD,IAAI,SAAS,KAAK,IAAI,IAAI,SAAS,CAAC,KAAK,KAAK,IAAI,IAAI,sBAAsB,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;QAC9F,EAAE,CAAC,aAAa,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC;QAC9B,0BAA0B,CAAC,KAAK,EAAE,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;QACtE,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;IACxC,CAAC;AACH,CAAC;AAED,kGAAkG;AAClG,mGAAmG;AACnG,QAAQ;AACR,MAAM,UAAU,gBAAgB,CAC9B,KAAoB,EACpB,OAAiC,EACjC,IAAY,EACZ,GAAW;IAEX,MAAM,EAAE,GAAG,KAAK,CAAC,EAAE,CAAC;IACpB,EAAE,CAAC,SAAS,CAAC,OAA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C,KAAK,EAAE,SAAS,qBAAqB,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,qBAAqB,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC;AACtH,CAAC;AAED,qGAAqG;AACrG,MAAM,UAAU,8BAA8B,CAAC,GAA+B;IAC5E,OAAO,iBAAiB,CAAC,GAAG,CAAC,GAAG,mBAAmB,CAAC;AACtD,CAAC;AAED,mGAAmG;AACnG,MAAM,UAAU,4BAA4B,CAAC,GAA+B;IAC1E,OAAO,iBAAiB,CAAC,GAAG,CAAC,GAAG,iBAAiB,CAAC;AACpD,CAAC;AAED,SAAS,iBAAiB,CAAC,GAA+B;IACxD,IAAI,OAAO,GAAG,mBAAmB,CAAC;IAClC,IAAI,GAAG,CAAC,IAAI,KAAK,OAAO;QAAE,OAAO,IAAI,sBAAsB,CAAC;;QACvD,OAAO,IAAI,uBAAuB,CAAC;IACxC,IAAI,GAAG,CAAC,YAAY;QAAE,OAAO,IAAI,0BAA0B,CAAC;IAC5D,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,iBAAiB,GAAG;;;;;;;;;;;;;;;;;;;;;;;CAuBzB,CAAC;AAEF,MAAM,mBAAmB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmD3B,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Environment, GlRenderState, ImageResource } from '@flighthq/types';
|
|
2
|
+
export declare function ensureGlEnvironmentSourceCube(state: GlRenderState, environment: Readonly<Environment>): WebGLTexture | null;
|
|
3
|
+
export declare function getGlCubeFaceTarget(gl: WebGL2RenderingContext, face: number): number;
|
|
4
|
+
export declare function updateGlEnvironmentCubeFace(state: GlRenderState, face: number, image: Readonly<ImageResource>): boolean;
|
|
5
|
+
//# sourceMappingURL=glEnvironmentCube.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glEnvironmentCube.d.ts","sourceRoot":"","sources":["../src/glEnvironmentCube.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAe,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAa9F,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,aAAa,EACpB,WAAW,EAAE,QAAQ,CAAC,WAAW,CAAC,GACjC,YAAY,GAAG,IAAI,CAsBrB;AAID,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,sBAAsB,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAEpF;AAQD,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,aAAa,EACpB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,QAAQ,CAAC,aAAa,CAAC,GAC7B,OAAO,CAQT"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { uploadGlTextureImageResource } from '@flighthq/render-gl';
|
|
2
|
+
import { getGlScene3DRuntime } from './glScene3DRuntime';
|
|
3
|
+
// Uploads an Environment's source radiance cubemap (six ImageResource faces) to a GL cubemap texture,
|
|
4
|
+
// caching it on the scene runtime. Returns null when the environment has no complete cube — all six
|
|
5
|
+
// faces bound with pixels, either a decoded `source` element or raw `data` — which callers treat as
|
|
6
|
+
// "no environment this frame". Each face uploads through whichever representation it carries: the
|
|
7
|
+
// element overload for a `source`, or the raw-pixel overload for a data-only face (a generated
|
|
8
|
+
// Surface, e.g. the skybox's rotateSurface180 path, which never allocates a canvas). The upload is
|
|
9
|
+
// keyed by identity: re-uploaded only when the cached texture is absent (a changed cube must drop the
|
|
10
|
+
// cache first via destroyGlEnvironment). sRGB faces are decoded to linear by the shaders that sample
|
|
11
|
+
// them, matching the renderer's sRGB-passthrough convention.
|
|
12
|
+
export function ensureGlEnvironmentSourceCube(state, environment) {
|
|
13
|
+
const runtime = getGlScene3DRuntime(state);
|
|
14
|
+
if (runtime.environmentSourceCube !== null)
|
|
15
|
+
return runtime.environmentSourceCube;
|
|
16
|
+
const cube = environment.environment;
|
|
17
|
+
if (cube === null || !hasGlCubeFacePixels(cube))
|
|
18
|
+
return null;
|
|
19
|
+
const gl = state.gl;
|
|
20
|
+
const texture = gl.createTexture();
|
|
21
|
+
gl.bindTexture(gl.TEXTURE_CUBE_MAP, texture);
|
|
22
|
+
for (let face = 0; face < 6; face++) {
|
|
23
|
+
uploadGlTextureImageResource(gl, getGlCubeFaceTarget(gl, face), cube.faces[face]);
|
|
24
|
+
}
|
|
25
|
+
gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
26
|
+
gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
|
27
|
+
gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
28
|
+
gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
29
|
+
gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_R, gl.CLAMP_TO_EDGE);
|
|
30
|
+
gl.bindTexture(gl.TEXTURE_CUBE_MAP, null);
|
|
31
|
+
runtime.environmentSourceCube = texture;
|
|
32
|
+
return texture;
|
|
33
|
+
}
|
|
34
|
+
// The cubemap face target in CubeTexture.faces order (+X, -X, +Y, -Y, +Z, -Z), which is exactly
|
|
35
|
+
// gl.TEXTURE_CUBE_MAP_POSITIVE_X + face. Face loops call this rather than hardcoding the GL enum math.
|
|
36
|
+
export function getGlCubeFaceTarget(gl, face) {
|
|
37
|
+
return gl.TEXTURE_CUBE_MAP_POSITIVE_X + face;
|
|
38
|
+
}
|
|
39
|
+
// Restamps a single face of the already-built source cube in place, uploading whichever representation the
|
|
40
|
+
// image carries (element or generated `data`). This is the incremental counterpart of the all-six
|
|
41
|
+
// ensureGlEnvironmentSourceCube — for dynamic cube content (reflection probes, a live sky face, or a
|
|
42
|
+
// generated data face mixed into loaded ones) without dropping and rebuilding the whole cube. `face` is the
|
|
43
|
+
// CubeFace* index (+X, -X, +Y, -Y, +Z, -Z). Returns false when no cube has been built yet — the caller
|
|
44
|
+
// must call ensureGlEnvironmentSourceCube first.
|
|
45
|
+
export function updateGlEnvironmentCubeFace(state, face, image) {
|
|
46
|
+
const texture = getGlScene3DRuntime(state).environmentSourceCube;
|
|
47
|
+
if (texture === null)
|
|
48
|
+
return false;
|
|
49
|
+
const gl = state.gl;
|
|
50
|
+
gl.bindTexture(gl.TEXTURE_CUBE_MAP, texture);
|
|
51
|
+
uploadGlTextureImageResource(gl, getGlCubeFaceTarget(gl, face), image);
|
|
52
|
+
gl.bindTexture(gl.TEXTURE_CUBE_MAP, null);
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
// A face is uploadable when it carries pixels in either representation: a decoded `source` element or
|
|
56
|
+
// raw CPU `data` (a generated Surface). A cube is complete only when all six faces are uploadable.
|
|
57
|
+
function hasGlCubeFacePixels(cube) {
|
|
58
|
+
for (let face = 0; face < 6; face++) {
|
|
59
|
+
const image = cube.faces[face];
|
|
60
|
+
if (image == null || (image.source == null && image.data == null))
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=glEnvironmentCube.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glEnvironmentCube.js","sourceRoot":"","sources":["../src/glEnvironmentCube.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,qBAAqB,CAAC;AAGnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD,sGAAsG;AACtG,oGAAoG;AACpG,oGAAoG;AACpG,kGAAkG;AAClG,+FAA+F;AAC/F,mGAAmG;AACnG,sGAAsG;AACtG,qGAAqG;AACrG,6DAA6D;AAC7D,MAAM,UAAU,6BAA6B,CAC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AAI,IAAI,IAAI,KAAK,CAAC,IAAI,IAAI,IAAI,CAAC;YAAE,OAAO,KAAK,CAAC;IAClF,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Environment, GlRenderState } from '@flighthq/types';
|
|
2
|
+
export declare function bakeGlEnvironmentIbl(state: GlRenderState, environment: Readonly<Environment>): void;
|
|
3
|
+
export declare function destroyGlEnvironmentIblBakePrograms(state: GlRenderState): void;
|
|
4
|
+
//# sourceMappingURL=glEnvironmentIblBake.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glEnvironmentIblBake.d.ts","sourceRoot":"","sources":["../src/glEnvironmentIblBake.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAelE,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,QAAQ,CAAC,WAAW,CAAC,GAAG,IAAI,CAiCnG;AAOD,wBAAgB,mCAAmC,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI,CAU9E"}
|