Shader Replacement Based on Program Type#2424
Open
mathsvisualization wants to merge 1 commit into3b1b:masterfrom
Open
Shader Replacement Based on Program Type#2424mathsvisualization wants to merge 1 commit into3b1b:masterfrom
mathsvisualization wants to merge 1 commit into3b1b:masterfrom
Conversation
in VShaderWrapper, allowing independent GLSL modifications for:
- stroke programs
- fill programs
- depth programs
Previously, `set_color_by_code()` relied on a single global
replacement mechanism. As a result:
- Multiple calls to `set_color_by_code()` would override each other.
- Applying different GLSL logic to stroke and fill was not possible.
- The last shader replacement always won.
This update solves that limitation by:
1. Storing shader code replacements per program type.
2. Applying replacements only to shaders matching the given program_type.
3. Preserving previously applied replacements for other program types.
4. Maintaining backward compatibility when program_type is None.
Now users can safely do:
set_color_by_code(..., program_type="stroke")
set_color_by_code(..., program_type="fill")
without one affecting the other.
This makes stroke and fill shader logic fully independent,
opening the door for:
- Different gradients for stroke and fill
- Custom sheen effects per layer
- Advanced shader experimentation
- Cleaner shader architecture
Backward compatibility:
If no program_type is provided, behavior falls back to the
original global replacement logic.
This improves flexibility without breaking existing scenes.
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.
Motivation
Currently, shader code replacement in
set_color_by_codeis not program-type aware.If
set_color_by_codeis called multiple times on the sameVMobjectwith differentprogram_typevalues (e.g.,"fill","stroke"and"depth"), only the last applied shader modification takes effect.This happens because shader code replacement is not scoped to individual program types, causing unintended overrides when both fill and stroke shaders are customized.
This change introduces program-type aware shader code replacement, ensuring that:
fill,stroke, anddepthshader programs are handled independently.VMobjectno longer override each other.This improves flexibility and makes shader customization more predictable and robust.
Proposed changes
program_type.fill,stroke, anddepthprograms maintain separate shader modifications.set_color_by_codeis called multiple times on the same object.Test
Code
Before
After