codeonwort / pathosengine

OpenGL Rendering Engine for Study
MIT License
20 stars 0 forks source link

Material shader assembly system (v0.6.5) #32

Closed codeonwort closed 2 years ago

codeonwort commented 2 years ago

This system needs more refinement but I'm so exhausted. Merging now as basic functionalities are working.

Initial backlog

Currently all material shader variations are hard-coded.

I can't make a full GUI-based material editor now, but at least let's make a material assembler that generates material shaders.

Material shaders only define specialized things - vertex position offset, texture input, Gbuffer attributes, so on. Common code is provided by a material template.

The assembler generates final material shaders, replacing various parts of a material template with a given concrete material.

Complete rework of material shader management

Previous implementation defined a hard-coded base pass shader, a subclass of Material, and a corresponding render pass class.

For example, for a material that samples PBR textures:

These things were defined for each material type, and I also had to add ad-hoc logic for depth prepass and shadowmap pass if a material has non-trivial depth only shader (that is, final position is not just MVP * localPosition, due to vertex animation or manual control of gl_FragDepth, etc.).

Everything above is now gone. No separate VS/FS shaders, no subclasses, no separate render pass classes.

In rendering pipeline, mesh batches are split into an opaque mesh list and a translucent mesh list. Each list is first sorted by material shader, then by material instance ID. The opaque list is rendered in depth prepass and base pass. The translucent one is rendered in translucency pass.

TODO