Help needed - Unexpected scary rendering issue

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
sisyphu2
Prole
Posts: 17
Joined: Mon Sep 28, 2020 3:15 pm

Help needed - Unexpected scary rendering issue

Post by sisyphu2 »

Hi there, I am currently struggling with an issue that I fear will make my game unreleasable. :cry:

I am rendering a 2d grid-based world map with 3 different layers (each layer is a spritebatch). Sometimes when running the game 2 of the layers render in a very weird way: some of the tiles either flash (either to 0 opacity, or to white), or they seem to stretch from their actual tile coordinates to some (seemingly) random coordinates near the top of the grid, or both. Only some of the tiles do this, not the whole batch. I have encountered the issue multiple times, nothing I've changed has stopped it. What makes it more difficult and weird is that the issue only occurs occasionally, most times I run the game it all works as normal.

Relevant Details:
- There are 3 rendering layers rendered in this order: base map (grass etc), border lines, towns.
- The issue only ever affects layers 2 and 3 (border lines and towns).
- Each layer is contained within its own spritebatch (so as to store a large number of different tiles).
- The border line spritebatch has different colours applied to its various tiles, and also the blend mode is changed to 'add' when actually rendering the layer. The other two layers have no colours or blend modes applied to them.
- There are two texture atlases (1 for base map and the second for border lines and towns).
- The game uses the 'Push' library to double the resolution.
- The game uses a simple camera logic to translate the screen when holding mouse right.
- The issue only occurs sometimes, perhaps 1 in 10 or even 1 in 20 playthroughs.
- I am unable to decipher what the conditions that cause it are.
- The tiles that are affected by the issue vary and are not the same every time.
- When it occurs, most of the tiles remain perfectly normal - but a significant number have this behaviour which completely ruins the game.

Thoughts on issue:
- I have encountered the same issue before with using spritebatches (and I also did not discover the solution to it back then!)
- Could it be to do with the camera / or push?
- Or is there a known issue with spritebatch rendering in love 2d? I cannot seem to find anything on google.
- I believe that my limited knowledge on the underlying rendering processes is hindering me here...

Code extract to follow

Any help greatly appreciated.
Sisyphu2
sisyphu2
Prole
Posts: 17
Joined: Mon Sep 28, 2020 3:15 pm

Re: Help needed - Unexpected scary rendering issue

Post by sisyphu2 »

Some key code extracts:

The Border Lines spritebatch is 'pre-rendered' in this way:

Code: Select all


local pre_render = function(empires)
              batch:clear()
              batch:setColor(1,1,1,1)

                  for i=1,#empires do
                          local colour = empires[i].colour
                          local this_owner = empires[i].index
                          for j=1,#towns do
                              if towns[j].owner == this_owner then
                                  local town_tiles = towns[j].town_tiles
                                  for k=1,#town_tiles do
                                      local quad_index = get_quad_index(town_tiles[k])
                                      batch:setColor(colour)
                                      batch:add(batch_quads[quad_index], this_tile.x_pos, this_tile.y_pos)
                                  end
                              end
                          end
                      end
                batch:setColor(1,1,1,1)
                batch:flush()
              end
 

That layer is then rendered to screen as follows:

Code: Select all

 local render = function()
     lg.setColor(1,1,1,0.6)
     lg.draw(batch,0,0)
     lg.setColor(1,1,1,0.8)
     lg.setBlendMode('add')
     lg.draw(batch,0,0)
     lg.setBlendMode('alpha')
     lg.setColor(1,1,1,1)
 end
The other two layers are pre-rendered and then rendered in a similar way minus the colour and blend mode changes.

Then all the layers are rendered together very simply:

Code: Select all

 push:start()
 camera.set()

 world_map.render()
 border_lines.render()
 towns.render()

 camera.unset()
 push:finish()
The camera does this (where tx and ty are the x and y translation of the camera):

Code: Select all


local set = function()
    lg.push()
    lg.translate(tx, ty)
end

local unset = function()
    lg.pop()
end

And of course push is a well known library. The settings are:

Code: Select all

push:setupScreen(512, 384, 1024, 768, {
        fullscreen = false,
        vsync = true,
        resizable = false
    })

User avatar
pgimeno
Party member
Posts: 3550
Joined: Sun Oct 18, 2015 2:58 pm

Re: Help needed - Unexpected scary rendering issue

Post by pgimeno »

Do you think you can provide a minimal, runnable example that exhibits the problem? You can use placeholder assets.

Also, what are your graphics card specs?
sisyphu2
Prole
Posts: 17
Joined: Mon Sep 28, 2020 3:15 pm

Re: Help needed - Unexpected scary rendering issue

Post by sisyphu2 »

pgimeno wrote: Mon Apr 25, 2022 3:12 pm Do you think you can provide a minimal, runnable example that exhibits the problem? You can use placeholder assets.

Also, what are your graphics card specs?
Thanks for replying. Yes I will get a minimal running example uploaded as soon as I can.

Specs are: intel(R) HD Graphics 620. 64bit Win10, 8GB Ram,2.5ghz
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 62 guests