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
Are dual-texture SpriteBatches possible?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Are dual-texture SpriteBatches possible?
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.
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.
Check out my blog on gamedev
Re: Are dual-texture SpriteBatches possible?
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.
- slime
- Solid Snayke
- Posts: 3166
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: Are dual-texture SpriteBatches possible?
All draw operations in love use up to one main texture, and anything more than that is up to the shader you use.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.
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?
Thank you, slime! That's exactly what I needed.
Who is online
Users browsing this forum: No registered users and 4 guests