efactor(shader): migrate GLSL shaders to ShaderLab and clean up shader infrastructure #2961
Draft
zhuxudong wants to merge 22 commits intogalacean:dev/2.0from
Draft
efactor(shader): migrate GLSL shaders to ShaderLab and clean up shader infrastructure #2961zhuxudong wants to merge 22 commits intogalacean:dev/2.0from
zhuxudong wants to merge 22 commits intogalacean:dev/2.0from
Conversation
… and clean up old files All GLSL chunks and complete shaders have been migrated from packages/core/src/shaderlib/ to packages/shader/src/shaders/ with a unified directory structure. ShaderLib.ts is now an empty runtime registry populated by the shader package's registerIncludes(). Old VS/FS shader pairs in extra/ are replaced by ShaderLab .shader files. Post-process and AO GLSL includes updated to use new .glsl-suffixed keys. Blit.vs.glsl relocated from extra/ to shaderlib root.
… assertions Move camera_ProjectionParams declaration from Transform.glsl to Common.glsl where it is actually used by remapDepthBufferEyeDepth(). Update ShaderLab test to match new PBR.shader structure with inlined ShadowCaster/DepthOnly passes. Fix PrecompileABTest macro expansion test to find Forward Pass by name instead of hardcoded index.
…te PostProcess/AO Split shader package into two layers, create .shader files for PostProcess and AO, simplify FXAA3_11.glsl for ShaderLab compatibility, remove Shader.create() from core passes.
…ng with pre-migration source FXAA3_11.glsl was incorrectly stripped of conditional branches (FXAA_DISCARD, FXAA_FAST_PIXEL_OFFSET, FXAA_GATHER4_ALPHA) and type alias macros during the initial migration. Restore the full original 1028-line version to preserve all code paths. FinalAntiAliasing.glsl now includes the FXAA_GLSL_130/120 conditional defines and uses FxaaFloat type aliases, matching the pre-migration FinalAntiAliasing.fs.glsl source exactly.
…ly across all material shaders PBR/BlinnPhong/Unlit/PBRSpecular now reference Utility/ShadowMap and Utility/DepthOnly via UsePass instead of inlining or referencing PBR. Fix _resolveUsePass to handle shader names containing "/" by parsing from the end. Reorder registerShaders() so Utility shaders are created before material shaders.
- Remove `path` parameter from `Shader.create()` ShaderLab overload - Remove `_shaderRootPath` from ShaderPass - Remove `basePathForIncludeKey` from IShaderLab, ShaderLab, and Preprocessor - Remove relative path resolution in Preprocessor._replace() - Delete ShaderChunkLoader and simplify ShaderLoader - Clean up basePath references in tests and devtools example
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…alacean#2960 - Delete unused noise files (NoiseCellular, NoisePerlin, NoisePsrd, NoiseSimplex) - Add NoiseSimplexGrad.glsl with simplexGrad() returning vec3 gradient - Add algorithm attribution comments to NoiseCommon.glsl - Add Particle/Module/NoiseModule.glsl with curl noise sampling - Integrate noise velocity into ParticleFeedback.glsl - Update Shaders/index.ts registrations for new includes
- Remove _createShader wrapper that handled ShaderPool name conflicts - ShaderPool no longer registers VS/FS fallbacks, so no conflict exists - Fix Shaders/index.ts noise registrations reverted by case issue
…m core - Strip shader package to zero dependencies (pure data exports only) - Move include registration to ShaderPool.init() and shader registration to ShaderPool.registerShaders() in core - Split exports: ShaderLibrary/index.ts for fragmentList, Shaders/index.ts for complete shader sources - Auto-register built-in shaders in Engine._initialize() after ShaderLab is set, so external callers no longer need manual register calls - Remove registerIncludes/registerShaders from all tests, examples, e2e - Update docs to reflect automatic registration
… DepthOnly passes - ShadowMap.shader: bind RenderQueueType = material_ShadowCasterRenderQueue - DepthOnly.shader: bind RenderQueueType = material_DepthOnlyRenderQueue - Remove duplicate lowercase shaders/utility/ entries from git index
- rollup-plugin-shaderlab transforms .shader to IPrecompiledShader JSON when PRECOMPILE=true - ShaderPool.registerShaders() detects string vs precompiled object and calls appropriate Shader factory method - Move ShaderLab setting and registerShaders() from Engine._initialize() to constructor, before BasicResources - Route .shader through shaderlabPlugin in rollup.config.js - Tests read .shader source via readFile() instead of package import - Remove redundant Shader.create(PBRSource) calls from e2e cases
…ransform - Remove double shadow intensity mixing in sampleShadowMap, move fade calc back inside the if block - Restore inverse-transpose normal transform for BlinnPhong skinning
… add sources subpath - Add libs/ directory with 21 precompiled .gsp files (checked into git) - libs/index.ts aggregates all .gsp imports as IPrecompiledShader objects - src/index.ts re-exports from libs/ (FinalAntiAliasing kept as string fallback) - Add src/sources.ts for editor use: raw .shader strings via /sources subpath - Add package.json exports field with "." and "./sources" subpaths - Add *.gsp type declaration in global.d.ts - rollup-plugin-glsl: handle .gsp files (JSON → object export) - rollup-plugin-shaderlab: revert to .gs only, add buildStart/watchChange hooks - rollup.config.js: add sources build entry for shader package - scripts/precompile-shaders.mjs: full/incremental precompile script - ShaderPool: add missing UIDefaultSource registration
- Revert lazy getter in BasicResources, Background, PostProcessUberPass back to eager constructor init - Migrate render states from TS to .shader files: * Blit/BlitScreen: DepthState disabled * BackgroundTexture: DepthState CompareFunction LessEqual * Sprite/Text: BlendState, DepthState, RasterState - Remove unused imports
macOS case-insensitive FS caused both Shaders/ and shaders/ paths to coexist in the git index after directory rename.
…ile compatibility - Sprite/Text shaders: use PBR-consistent variable names for render states (renderQueueType, sourceColorBlendFactor, blendEnabled, etc.) - Skybox/SkyProcedural shaders: add hardcoded DepthState and RasterState - BasicResources._create2DMaterial: use shaderData.setInt() instead of renderState API - BaseMaterial: migrate setIsTransparent/setBlendMode/setRenderFace/_setAlphaCutoff from renderState API to shaderData.setInt() - PBRMaterial: migrate renderQueueType to shaderData.setInt() - SkyBoxMaterial/SkyProceduralMaterial: remove TS render state code (now in shader) - Fix precompile script: handle undefined throw, non-fatal exit on failure - Add precompile dedup flag to avoid repeated runs in b:all - Regenerate all .gsp files to reflect shader source changes
- Move shaderLab configuration back to _initialize() where it was on dev/2.0 - registerShaders() stays in constructor (precompiled path doesn't need ShaderLab)
- PBR: material_OcclusionTextureCoord Float → Enum(UV0/UV1), material_AttenuationDistance range max 1 → 5 - PBRSpecular: same OcclusionTextureCoord fix, add Clear Coat group (5 properties matching PBR) - BlinnPhong: material_EmissiveColor Color → HDRColor, material_Shininess range (1,1024) → (0,100) - Particle: add full Editor block (Base, Emissive, Common) - 2D/Trail: add full Editor block (same as Particle) - Sky/Skybox: add Editor block (TintColor, Exposure, Rotation, CubeTexture) - Sky/SkyProcedural: add Editor block (Exposure, SunMode, SunSize, etc.) - Fix precompile script error logging to print full stack trace
- Add libs/ to tsconfig include so tsc generates types for .gsp imports - Update package.json types paths to types/src/ (tsc output structure)
…omment handling - Add ShaderLabUtils.skipComment() as shared primitive for comment detection - Add ShaderLabUtils.removeComments() to strip all comments preserving newlines - Preprocessor.parse() now strips comments before include expansion and macro collection, fixing false matches on #include inside block comments (e.g. FXAA3_11.glsl) - BaseLexer.skipCommentsAndSpace() reuses ShaderLabUtils.skipComment() - Lexer overrides skipCommentsAndSpace() to only skip whitespace since comments are already stripped by Preprocessor - IShaderLab._parseShaderPass return type: IShaderProgramSource | undefined
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
core/shaderlib(raw GLSL + rollup-plugin-glsl) toshaderpackage as ShaderLab.shaderfilesShaders/(ShaderLab entry points) andShaderLibrary/(GLSL include fragments)UsePassto reference themShaderChunkLoaderand shader path/chunk loading infrastructure (_shaderRootPath,basePathForIncludeKey)_resolveUsePassto support shader names containing "/" (e.g.Utility/ShadowMap)Motivation
Raw GLSL shaders scattered across
core/shaderlibrelied onrollup-plugin-glslfor bundling and lacked the renderstate / pass structure that ShaderLab provides. This migration:
shaderpackage with a clear Shaders + ShaderLibrary layoutregisterIncludes()for includeregistration and ShaderLab for shader creation
Key Changes
Shader Migration (
packages/shader/)BackgroundTexture, Particle, Blit, BlitScreen, ShadowMap, DepthOnly, PostProcess shaders (Bloom, SAO, FinalSRGB,
FinalAntiAliasing, UberShader)
.glslinclude fragments organized by category (Common, Lighting, PBR, Skin, Shadow, Fog,PostProcess, Particle)
UsePass Architecture
Utility/ShadowMapandUtility/DepthOnlyare canonical shared passesUsePass "Utility/ShadowMap/Default/ShadowCaster"registerShaders(): Utility first, then material shadersInfrastructure Cleanup
ShaderChunkLoader, remove_shaderRootPath,basePathForIncludeKeyfrom Preprocessor/ShaderLab/IShaderLabShader.create()only accepts ShaderLab source (vertex/fragment string overload removed from implementation, kept asoverload signature for now)
_resolveUsePassparses from end to handle multi-segment shader namesKnown Issue
Precompile.test.tssuite fails at load time becauseFinalAntiAliasing.shaderincludes FXAA3_11.glsl which usesconditional
#definetype aliases (FxaaFloat,FxaaBool) — the Preprocessor collects these as macros causing parsefailures. To be fixed on
fix/shaderlabbranch.Test Plan
npm run buildpassesnpx vitest run tests/src/shader-lab/— 62/62 tests pass_createFromPrecompiledround-trip works for PBR