Skip to content

Instantly share code, notes, and snippets.

@Tom-Ski
Last active March 12, 2025 21:41
Show Gist options
  • Save Tom-Ski/edb67ef5f1ff4213d47171c0342045e1 to your computer and use it in GitHub Desktop.
Save Tom-Ski/edb67ef5f1ff4213d47171c0342045e1 to your computer and use it in GitHub Desktop.
Just on PBR for now but would also need to support Gouraud. That might be as separate material and base_shader_type, or just driven from material
and handled in shaded material shader?
Material
ShaderMaterial
PBRMaterial
Ya basic PBR mat
PBRShaderMaterial (allowing glsl snippet customization within the PBRShaders)
flags: disable_lighting, disable_vertex_calculation, vertex_lighting etc
e.g. vertex() { do some modification after PBR vertrex processing finished}
e.g. fragment() { customize albedo after PBR albedo fetched}
e.g. lighting () { customize the lighting contributions }
e.g. perhaps depthVertex() to customize depth write instead of DepthMaterial
Pass
Data oriented method of registering passes to be used later on. Passes can be setup via shaders, exposing all uniforms/attributes they need
base_shader_type depth/shaded/shadow/empty(empty frag basically)
What type of pass we are doing. Organization really of uber shaders so we can split these up and have a bit more clarity.
Based on this, we use differnt base shaders, combine with Material to create correct shader for each pass. Potentially user can inject any kind here
and reference it from dsl
shader_flags
Can supply all flags in dsl to control the pass. Have it data orientated rather than hard coded at Shader level and material level.
e.g. for a specific material you want to disable depth depth writing, or you are going to control its vertex positions yourself,
so you want to disable vertex manipulation to gain performance
Renderable
Optional DepthMaterial: Material
Can be used to potentially override depth shader by injecting snippets
Custom depth material could expose per object bias, or custom vertex() method for adjusting depth
RenderMaterial: Material
Used for shaded pass/empty pass
Passes:
Render pass would just be an isolated way to render Meshes. I don't think this should include sorting to be extra customizable and handle all pass tyes. Probably not a user
facing api because its very low level. Exposing a utility around these passes is probably preferrable. One that handles sorting etc.
Passses api would exist just to combine and create shaders and render. Up to the user (higher level api) to wrap framebuffers and collection of models
Passes also could be entirely defined by a markup file. Describing the base shader, targets etc. Which shader materials could hook into each type of pass and inject their own custom code. This would allow complete customization at material level of any pass type. Which would be very cool.
effectively api would juts be pass.render(some kind of state to give us 'type' of pass to detemine base shaders, models)
1. renderCSM1
sortModelsForPass
beginCSM1 buffer target
passSystem.render(shadowPass, models)
for each model we combine base shadow shader with Environment + materials to create/get shader appropriate for this pass
endCSM1 buffer target
SceneManager would do this internally not exposed to user, but lets us also write fully customized passes.
2. renderDepthPrepass
collect objects near to far (opaque)
alpha tested objects front to back
blended completely skip
base_shader_type depth
beginDepthBuffer()
passSysetm.render(depthPass, models)
for each model combine base depth shader with Environment + material to create/get appropriate shader for this pass
endDepthBuffer()
3. renderColor
get all objects, sort transparents
beginColorBuffer()
passSystem.render(colorPass, models)
for each model combine colour/shaded with Enviroment + material to create/get appropriate shader for this pass
endColorBuffer()
4. Rendering water
WaterMaterial extends ShaderMaterial {
//Would load this from a glsl dsl file
uniform sampler2D screenDepthTexture;
uniform sampler2D screenColorTexture;
uniform watercolor;
vertex () {} do any wave stuff on flat plane
fragment () {} mix colour based on screenDepthTexture, waterColor and screenColorTexture
}
gather your water objects
passSystem.render(emptyPass, models)
Here our wtaer materials handle the customization themselves with their injected glsl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment