Dear friends,
I just started working with shaders on Solar2D.
I’m trying to run a normal map over animated sprites, but I’m not figuring out how to do that.
For example, the following code works for showing a “static” image with its normal map:
local multiTexture =
{
type = "composite",
paint1 = {type="image", filename="MyTexture.png"},
paint2 = {type="image", filename="MyNormalMap.png"}
}
local rect = display.newRect(0, 0, 256, 256)
rect.fill = multiTexture
rect.fill.effect = "composite.normalMapWith1PointLight"
rect.fill.effect.pointLightColor = {1, 1, 1, 1}
rect.fill.effect.ambientLightIntensity = 0.2
rect.fill.effect.attenuationFactors = {0.5, 1, 1}
rect.fill.effect.pointLightPos = {0.5, 0.5, 0.2}
But how should I procede if the rect were a sprite created by display.newSprite?
local boySheet = graphics.newImageSheet("BoyRunning.png", {width = 153, height = 153, numFrames = 10})
local boySheetNormalMap = graphics.newImageSheet("BoyRunningNormalMap.png", {width = 153, height = 153, numFrames = 10})
local paintBoy = {type = "image", sheet = boySheet}
local paintBoyNormalMap = {type = "image", sheet = boySheetNormalMap}
local multiTextureSprite =
{
type = "composite",
paint1 = paintBoy,
paint2 = paintBoyNormalMap
}
local boySprite = display.newSprite(boySheet, {start = 1, count = 10, time = 500})
boySprite.fill.effect = "composite.normalMapWith1PointLight"
boySprite.fill.effect.pointLightColor = {1, 1, 1, 1}
boySprite.fill.effect.ambientLightIntensity = 0.2
boySprite.fill.effect.attenuationFactors = {0.5, 1, 1}
boySprite.fill.effect.pointLightPos = {0.5, 0.5, 0.2}
boySprite:play()
Of course the code above doesn’t work, but it helps to clarify what I mean.
Any help?
Thanks in advance!