lowenware / dotrix

A 3D engine with ECS and Vulkan renderer for Rust developers
https://dotrix.rs
MIT License
290 stars 11 forks source link

fixes/Lighting refractor #158

Closed QuantumEntangledAndy closed 2 years ago

QuantumEntangledAndy commented 2 years ago

This adds features from https://github.com/lowenware/dotrix/pull/152 that I am adding here to make the PRs more modular

Mostly this is some house keeping in the lighting, that makes it easier for other modules to use the light code

  1. Reduce repeated code in light.inc.wgsl
    • Done with a kind of iter funtion over any light objects calculate_nth_light_ray
    • You can see the improvment in pbr.inc.wgsl where what used to be four for loops one for each type of light is now reduced to a single loop
  2. Seperate lighting and pbr code into light.inc.wgsl and pbr.inc.wgsl
  3. Remove redundant normal vector in light.inc.wgsl

I would also like to discuss moving Lights (and their light.inc.wgsl) into core and leaving only pbr.inc.wgsl indotrix_pbr but feel that should be another PR

Lowentwickler commented 2 years ago

Looks good to me and this is definitely not the last change in pbr/lighting code

QuantumEntangledAndy commented 2 years ago

We seem to be using something like jinja templating.

Have we considered about using the tera crate for formally providing a templating engine. We could fill it will all our own includes and provide the Tera struct for users to extend too. If we pass code through Tera when we load a shader it will error early if there are any missing {{ binding }} that would otherwise error at the Naga level with a perhaps harder to interpret message. We could also provide perhaps some common useful functions and use jinja templates and code to help write our shaders.

Lowentwickler commented 2 years ago

Yeah, exactly, I was thinking about using a template engine. At the time of PBR implementation I decided to use DUMB solution. Thank for the reference, I will check the tera crate.

QuantumEntangledAndy commented 2 years ago

I am using tera in #152 already so maybe look at how it works there would help too.