I was under wrong impression that ‘normal’ variable in mid of Lightning.frag shader represents world-space normal - but this seems to be not a case. Is there any easy way to get world-space normal in there? Even in vertex shader, it seems that only usable matrix goes immediately from model to view space.
Reason why I want to use it is because Skyrim has trivial but effective snow shader - it seems to be just take configurable max angle and covers everything less then that angle from up vector with snow. But up vector has to be world space…
You will have to add it to your j3md file so that it’s set but the NormalMatrixInverse may give you what you want… though it may also take it straight to model space (likely).
Since you have to modify the shader anyway, your best bet might be to set a world space normal varying in the vertex shader and then just access that from the .frag. Probably with the world matrix and then remove the translation.
It occurs to me that another even cheaper way to do this would be to have an “up” uniform that is the up vector rotated into view space. Then you can just use the normals as they are without additional calculation and you only have to set that “up” uniform just once per frame.
I have done a quick test by multiplying up vector with normal matrix in vert shader and it worked - as long as I was not using normal map, just vertex normals.
It seems that normal.xyz is in tangent space when I use normal maps… and I need it in view space using that approach;)
Seems that I will need to convert up-vector to tangent space in vertex shader instead to view space.
vUp = normalize(g_NormalMatrix *vec3(0,0,1))*tbnMat;
seems to do the trick, not that I really understand all the implications
(I’m in z-up world, so it is 0,0,1, not 0,1,0; on top of that model is not rotated, so I get away with using model->view transform for now, instead of world->view one - will have to fix it)
Looks nice. I plan to do something similar in Mythruna someday… though I will do a similar effect to my “dirt/noise” stuff and use a simple noise texture-based fractal to partially filter the snow to give it variation.
I’m going to do the same thing for moss, also. Someday.
Someday I may even write a post about texture-based fractal noise and combining it with existing textures. Neat effects.