Page 1 of 1
Are dual-texture SpriteBatches possible?
Posted: Thu Mar 13, 2014 8:39 pm
by Klowner
From what I can tell, the documentation makes it pretty clear that a SpriteBatch is associated with a single source texture, but I was curious if there is any way to bind a secondary texture so I could use texture samplers in a Shader while drawing the SpriteBatch.
The specifics of what I'm attempting to do are bind a regular texture for diffuse coloring as well as a matching normal map texture for lighting, ideally allowing me to reuse the same SpriteBatch and render all the Quads in one pass.
I suppose my other option would be to bind "color" Canvas, batch:setImage(colortiles), draw scene, bind second "normal map" Canvas, batch:setImage(normaltiles), draw batch, then combine the canvases at the end?
Any ideas would be greatly appreciated!
-Klowner
Re: Are dual-texture SpriteBatches possible?
Posted: Thu Mar 13, 2014 8:55 pm
by micha
You are correct in that you can only attach one image to a spriteBatch.
I don't know much about normal maps and lighting, but depending on what you mean by "combine the canvases" you can possibly do this without canvases: batch:setImage(colortiles), draw scene, batch:setImage(normaltiles) draw batch with lighting shader.
Re: Are dual-texture SpriteBatches possible?
Posted: Thu Mar 13, 2014 9:08 pm
by Klowner
That basically sounds like what I need! Thank you. I was also skimming the docs and noticed there is a Shader:send(name, image, ...), I imagine I can use that to access additional textures from within a Shader during a SpriteBatch draw.
Re: Are dual-texture SpriteBatches possible?
Posted: Thu Mar 13, 2014 9:11 pm
by slime
Klowner wrote:From what I can tell, the documentation makes it pretty clear that a SpriteBatch is associated with a single source texture, but I was curious if there is any way to bind a secondary texture so I could use texture samplers in a Shader while drawing the SpriteBatch.
The specifics of what I'm attempting to do are bind a regular texture for diffuse coloring as well as a matching normal map texture for lighting, ideally allowing me to reuse the same SpriteBatch and render all the Quads in one pass.
All draw operations in love use up to one main texture, and anything more than that is up to the shader you use.
For example:
Code: Select all
image = {
diffuse = love.graphics.newImage("diffuse.png"),
normals = love.graphics.newImage("normals.png"),
}
spritebatch = love.graphics.newSpriteBatch(image.diffuse)
spritebatch:add(100, 100)
shader = love.graphics.newShader[[
extern Image normalmap;
vec4 effect(vec4 vcolor, Image diffuse, vec2 texcoord, vec2 pixcoord)
{
vec4 diffusecolor = Texel(diffuse, texcoord) * vcolor;
vec3 normal = normalize(2.0 * Texel(normalmap).xyz - 1.0);
// etc.
vec4 finalcolor = /* whatever */;
return finalcolor;
}
]]
shader:send("normalmap", image.normals)
function love.draw()
love.graphics.setShader(shader)
love.graphics.draw(spritebatch, 0, 0)
love.graphics.setShader()
end
Re: Are dual-texture SpriteBatches possible?
Posted: Thu Mar 13, 2014 9:55 pm
by Klowner
Thank you, slime! That's exactly what I needed.