Hi sporkfin, I know - you da man!

In fact, everything I was doing is based on you invaluable input in this post.

I also looked at your dynamic shader plugin, but I am just testing the waters with corona at the moment and not ready to commit to any plugins or the engine itself.

Here is a screenshot of the test scene, the light (point light here) is orbiting the image, what I want is for it to always point towards the center.

**dfjkbdfjkdfkjsdfg908df89-dsfsdg.jpg** **22.07KB**
0 downloads

Attaching the test project and a screenshot.

Here is the relevant code:

-- calculate rotation
local lightTimer = timer.performWithDelay( 100, function() -- inline function repeats 10x/sec
--local physicsState = physics.getPhysicsState() -- get current physics state
-- I cannot find property physicsState - getting an error
--if (physicsState == "play") then -- if physics state is "play" e.i. not paused
if (1) then -- if physics state is "play" e.i. not paused
--local sunX, sunY = sun.moveSun() --[[
-- calls the moveSun() method from the sun module (require file) which:
-- 1) rotates the sun around the center by a set number of degrees
-- 2) compares the position of the sun to the center (in degrees)
-- 3) converts postion degrees to radians and gets quadrant info for +/- values
-- 4) math.cos(radians) = sunX
-- 5) math.sin(radians) = sunY
-- 6) returns sunX, sunY --]]
--
--local rot = math.mod(testPlate.rotation,360)
--local rot = testPlate.rotation
local rot = system.getTimer() / 10
print("rot:"..rot)
local rotrad = math.rad(rot)
-- I don't understand how to implement quadrant stuff the sporkfin mentioned in his post.
--local quad = math.floor(rotrad / 1.570796)
--
--local multX -- X -/+ switch
--local multY -- Y -/+ switch (multiplier)
--
--if quad == 1 or quad == 2 then
-- multX = 1
--else
-- multX = 1
--end
--
--if quad == 0 or quad == 1 then
-- multY = 1
--else
-- multY = 1
--end
-- print("quad:"..quad )
-- normalizaton ?
local Remap = function(value, from1, to1, from2, to2)
return (value - from1) / (to1 - from1) * (to2 - from2) + from2;
end
local origX = 0.5
local origY = 0.5
-- standard rotation formula
local posX = origY * math.sin(rotrad) + origX * math.cos(rotrad)
local posY = origY * math.cos(rotrad) - origX * math.sin(rotrad)
posX = Remap(posX, -1,1,0,1)
posY = Remap(posY, -1,1,0,1)
--local posX = math.sin(rotrad)
--local posY = math.cos(rotrad)
--print("rot rad:"..rot)
--print("posX:"..math.round(posX*100)/100)
--print("posY:"..math.round(posY*100)/100)
-- testPlate.fill.effect = "composite.normalMapWith1PointLight"
-- testPlate.fill.effect.dirLightDirection = { 1, 0, 0 }
--testPlate.fill.effect.pointLightColor = { 1, 1, 1, 1 }
--testPlate.fill.effect.ambientLightIntensity = 0.2
--if (testPlate.alive == true) then -- if the object is not dead
-- testPlate.fill.effect.dirLightDirection = { 0.7, 0.3, 0.5 } -- x, y, z values for the Normal Map ; applied to each object
-- pointLightPos
testPlate.fill.effect.pointLightPos = { posX, posY, 0 } -- x, y, z values for the Normal Map ; applied to each object
--testPlate.fill.effect.pointLightPos = { 0.1, 0.2, 0 } -- x, y, z values for the Normal Map ; applied to each object
--end
end
end, 0) -- end inline function and set repeat to infinite

I also tried to write a custom shader to address my needs, but the vector math and GLSL is out of my depth at the moment. Corona Shader Playground link: https://goo.gl/q9jjD3

**EDIT:**

I wouldn't mind using directional light instead, I think it would serve my purpose better. it's just that the point light demonstrates the issue better.

Preview of effect I am after.

**testOINSUIPD7896ydfdfgbnghufgyIfyGV.gif** **210.35KB**
0 downloads