vm6502q / OpenRelativity

An open source framework to add the effects of traveling at relativistic speeds to visualizations or games
17 stars 2 forks source link

Shader refactor #9

Closed WrathfulSpatula closed 5 years ago

WrathfulSpatula commented 5 years ago

The various shader variants were always cumbersome and redundant. From a performance perspective, including acceleration in the shader was probably never a major factor. At least, some vertex shader matrix multiplications do not justify the exponential repetition of shader code.

Further, relativity is a "second order theory." Someone pointed out to me, if we include second partial derivatives, (effectively acceleration handling,) with the Unity update loop effectively making for a finite difference time step simulation, we should be able to fully represent the mechanics, by varying first and second order terms with a small enough time step. It goes beyond the scope of the original project, but acceleration handling certainly appears to work correctly, playing with it.

I wanted to use toggle options for lighting effects, but Unity's handling for enabling/disabling shader passes feels clunky. This reduced number of variants might be the best compromise.

Additionally, since we have the "isStatic" flag on RelativisticObject instances now, we know that world-static objects can share all material parameters, and therefore share a material! We can batch static environment objects, and bake lighting on them, too!