To follow up on another (now closed) topic normal-map-filters-help-needed, I have new observations on the matter:
In the below image, the top row has individually loaded images, the second row - frames from an image sheet (2 images, sheet size 512x256). It is clear that point light position in texture space (0 to 1) is applied to the whole sheet texture, not the used frame. As I read in other posts, it has to do with OpenGL design / limitation.
Is my assumption correct that it is not possible to use image sheets with normal maps for lighting effects and I should stop wasting time trying?
Second question is when I use directional light with the same settings as above, I get a weird “flip” effect, when the light seem to roll over the center of the image at the end of the loop.
However, when I comment out the following code (effectively disabling normalization of the coordinate values to 0–1 range from original -1.414 – 1.414 range), the light animation looks correct:
-- posX = Remap(posX, -1,1,0,1) -- posY = Remap(posY, -1,1,0,1)
This makes me think that this statement from the docsis false :
“The origin and the growth direction of each axis is the same as described for pointLightPos”
and, in fact, dirLightDirection origin is at the center of the image, as opposed to top left corner.
I’d appreciate if anyone can shed some light on this for me (no pun intended)
Here is the function I use to calculate light position:
-- LIGHT TIMER FUNCTION -- calculate rotation local lightTimer = timer.performWithDelay( 100, function() -- inline function repeats 10x/sec for i = 1, #testPlates do local testPlate = testPlates[i] -- testPlate.rotation = testPlate.rotation + 4 -- local rot = math.mod(testPlate.rotation,360) local rot = system.getTimer() / 10 local rotrad = math.rad(rot) -- normalizaton local Remap = function(value, from1, to1, from2, to2) return (value - from1) / (to1 - from1) \* (to2 - from2) + from2; end -- how far is light from the center local origX = 1 local origY = 1 -- standard rotation formula local posX = origY \* math.sin(rotrad) + origX \* math.cos(rotrad) local posY = origY \* math.cos(rotrad) - origX \* math.sin(rotrad) print("posX:"..posX) -- posX = Remap(posX, -1,1,0,1) -- posY = Remap(posY, -1,1,0,1) testPlate.fill.effect.dirLightDirection = { posX, posY, .1} -- x, y, z values for the Normal Map ; applied to each object -- testPlate.fill.effect.pointLightPos = { posX, posY, .2 } -- x, y, z values for the Normal Map ; applied to each object end -- end for loop end, 0) -- end inline function and set repeat to infinite -- LIGHT TIMER FUNCTION END
The test project is attached as well.