some notes about custom lighting shading of surfaces...

Started by RemiD, March 17, 2018, 11:15:36

Previous topic - Next topic

RemiD

Hello,

Some notes for those who want to do experiments with custom lighting shading of surfaces (in this case using vertices colors, but the same rules applies with texels colors)

For static surfaces, this is easier, since they are never changing their orientations / positions, so you only have to get the global position of each vertex ( using TFormPoint() )
However for turning moving animating surfaces (characters, weapons, projectiles, vehicles), you have to get the global position and the global normal vector of each vertex ( using TFormPoint() and TFormVector() )

and then, it works well :
http://rd-stuff.fr/blitz3d/custom-lighting-shading-20180317.png

Rick Nasher

Really like the lighting effects. Looks really nice.
_______________________________________
B3D + physics + shaders + X-platform = AGK!
:D ..ALIENBREED *LIVES* (thanks to Qube).. :D
_______________________________________

RemiD

The lighting shading on the static surfaces is precalculated before the mainloop, and the lighting shading on the turning moving animating surfaces is updated during the mainloop, it is fast enough as long as there are not too many lights in an area, and not too many turning moving animating surfaces in an area (and in view), and the turning moving animating surfaces don't have too many vertices / triangles. (but in this scene there are 9 lights, maybe it is not necessary to have so many lights in such a small area !)

What is frustrating is that DX7 lighting shading is fast, but you can't customize the formulas... Else i could achieve the same result but very fast.

RemiD

nice shades and blends of colors, just for the pleasure of the eyes : 8)


Rick Nasher

Really looking nice indeed.

I've done something similar before, but real-time, for I don't know how to actually do this pre-calculated in AGK, but works fast enough so can't complain.. (yet) :-)
_______________________________________
B3D + physics + shaders + X-platform = AGK!
:D ..ALIENBREED *LIVES* (thanks to Qube).. :D
_______________________________________

RemiD

@Rick>>these lights only light shade the surface of one area, so they do not go through floors walls ceilings. Not sure if you can do this with AGK lights (i hope so, this can be useful). Also the lighting shading is precalculated on static surfaces and only updated on turning moving animating surfaces (so faster to update)
Also this is lighting shading using vertices colors, so different than lighting shading using pixels (no idea how it is done and i don't think that it can be precalculated).

Just consider that this uses only Blitz3d and Directx7, so it is rather a nice result 8)
(but of course per pixel lighting looks much better, especially for spot lights)

Now i need to add more things in these rooms...

RemiD

Something that i have noticed recently, even if it is to be expected, is that if you want to create a custom lighting shading system using vertices colors, you can't use copyentity(), because it creates a copy of a source mesh / surface and so if you have several shapes which refer to the same surface, and if you change the colors of the vertices, they will all look the same (like the source surface) and therefore the different shapes will not be lighted shaded correctly.

The solution is to not use copyentity() and instead to use loadmesh() (for static surfaces) or loadanimmesh() (for rigged skinned animated surfaces) so that each shape has its own surface.


Now you may say that it will be slower to render because there are more different unique surfaces, and this is true, but if you also use a smart "hidden surfaces culling" system, this is not an issue. (only the shapes in the active area and in view will be rendered...)

RemiD

I just found (yesterday) that it is possible to set a vertex color at more than 255,255,255, (not sure how high you can go)
So this means that it is possible to have a "uniform light intensity", whatever the color.
The formula is :

CurCoef# = Float(ColR+ColG+ColB)/Float(255+255+255) ;255+255+255 corresponds to white
TweakCoef# = 1.0+(1.0-CurCoef)
ColR = ColR*TweakCoef : ColG = ColG*TweakCoef : ColB = ColB*TweakCoef


Compare the lighting intensity of the 1st screenshot to the lighting intensity of the 3rd screenshot
Quite surprising... Not sure if this is documented somewhere, but i have never read about this anywhere.

Rick Nasher

Oops, could have told you that if I'd known you didn't and that Blitz allows this too.
I've done 1255 as a test and gave a nice oversaturated effect.
_______________________________________
B3D + physics + shaders + X-platform = AGK!
:D ..ALIENBREED *LIVES* (thanks to Qube).. :D
_______________________________________

STEVIE G

Quote from: RemiD on March 31, 2018, 19:34:20
I just found (yesterday) that it is possible to set a vertex color at more than 255,255,255, (not sure how high you can go)
So this means that it is possible to have a "uniform light intensity", whatever the color.
The formula is :

CurCoef# = Float(ColR+ColG+ColB)/Float(255+255+255) ;255+255+255 corresponds to white
TweakCoef# = 1.0+(1.0-CurCoef)
ColR = ColR*TweakCoef : ColG = ColG*TweakCoef : ColB = ColB*TweakCoef


Compare the lighting intensity of the 1st screenshot to the lighting intensity of the 3rd screenshot
Quite surprising... Not sure if this is documented somewhere, but i have never read about this anywhere.

If I remember you can also set the color to be negative which gives some really nice effects.

RemiD

Quote
you can also set the color to be negative which gives some really nice effects.
not so nice, rather buggy, see : https://www.syntaxbomb.com/index.php/topic,4290.msg14330.html#msg14330

peteswansen

thanks for your posts Remi regarding shaders and coloring,  I read my Blitz 3D manual and was able to figure out vertex coloring in my programs-  it is very nice!

RemiD

the cool thing is that you can create a unique lighting shading system (if your surfaces are subdivided enough).

see how the floors, walls, ceilings are subdivided, in "normal" view and in "wireframe" view :

you don't need to subdivide small surfaces like items or small furnitures / containers, only big surfaces like floors, walls, ceilings, doors...

Just a precision : to color your meshes (surfaces), you want to use textures, and to light shade your meshes (surfaces), you want to use vertices colors.