I’m trying to write a custom illumination model for a surface shader.
However I find no way to pass a custom value calculated in the “surf()” function to the custom illumination model.
If it was possible to just extend the SurfaceOutput struct, then I could just add there the extra info I need, but I could not find out if this is possible.
Note that I can’t just use shader properties, since the value is calculated during the shader, in the surf() function.
Right now I cheated by using the SurfaceOutput.alpha to store a float and then retrieve it in the illumination function. However later I want to make a transparent version of the shader, so I need to find a better solution.
Thanks, but I’ve read that link before writing this thread
Anyway, I’ve found a solution, which is actually very obvious…
Any shader variable declared outside the surf() function can be used to calculate a value inside the surf(), store the result and read the result in the lighting function.
Hey, I just looked over that page again and realized it didn’t contain the snippet I thought it did. You can definitely declare a global variable, but you can (and probably should) also create a struct to pass into your custom lighting model, like so (only including the relevant code):