Usually you have to define the ‘normal’ vector to each tile, V.
Then you have to define an illumination vector V0.
These vectors should be nromalized.
Then you compute for each tile the dot product dp = V0:dot(V).
If dp <0 then dp =0.
Then you change the color of you vertext simply multiplying the colors by dp.
Your object will be correctly shaded.
If your light is just white you can omit the lightColor. And curNormal and vLightDirection need to be in the same orientation. I have some complexity to this because I transform light normalised against each triangle and the normal for a flat triangle is then always 90 degrees, but you can instead transform your normals to the same space as the light instead.
Just to make things clear, I can do the math, I just need to know how to change the colors of the sides individually. I don’t need the light source or anything else, just how I change each side. Thanks for all the help!
In that case, make an image with all the different images you will need for the various sides, next to each other in the same image. Make this the mesh texture, then map the texture for each side to the part you want to use for it.
@1980geeksquad (pffffew! You should use a shorter alias, this is an ipad keyboard… ;-). ) To change the color of a mesh vertex, check the mesh.color(i) function. This is used to put shadows to a mesh.
The shade needs to be able to change. I’m not just mapping out a house or something, just trying to add a nice effect as the cubes are rotating. Sorry if I’m not clear enough.
The idea is that you have the camera as the light source, and the sides of the block get darker as their angle to the camera increases (like the picture I posted in the first comment).
I just need to know how to change the fill (or tint) during gameplay. Sorry if I’m not clear.
Great… It worked when I did two sides but once I added the third side, it said that the color was out of bounds for the first one… I tried removing the third one, and it is still “out of bounds”.
I got the colors to change, but they don’t update as the variables change. They are set in place when the mesh is created. Is there a way that I can re-call just the color part so the colors update?