tile map

Hi,

If you have a tile map say 2000x2000 (each tile say 16x16 pixels). When wanting to put these tiles through a shader such as bloom, do you pass each tile at
a time to the shader or a screen full of them, i.e. what the camera sees?

Thanks

You’re not passing any tiles to the shader because the shader is bound to the SpriteBatch. You would just set the batch’s shader, render as normal, and unset it.

You are definitely not going to render 2000x2000 tiles at a time. If you’re doing something to that extent, use a FrameBuffer.

I’m guessing it is the drawmap method that will need changing to something like:



public void drawMap(boolean bDebug, SpriteBatch batch, TextureRegion[][] region, int sx, int sy, int ex, int ey,
         int w, int h) {
      for (int row = sy ; row < ey + 1; row++)
         for (int col = sx ; col < ex + 1; col++) {
            BlankEntity entity = getEntity(col, row);
            if (entity != null) {
               {
                  batch.setColor((float) entity.lightValue / MAXLIGHT, (float) entity.lightValue / MAXLIGHT,
                        (float) entity.lightValue / MAXLIGHT, 1);
                  if (entity.lightValue > 0)
                     worldMap[col][row].draw(batch, region, col-sx, row-sy);   // <------ I subtract the camera start position from the row and col 
               
               }
            }
         }

   }


So subtracting the camera start position from the row and col and then would need to render the fboRegion to the camera position:


  batch.draw(fboRegion, camera.position.x, camera.position.y);      

Not sure if this would be correct? Cannot test atm as not got PC with my game on it.

[UPDATE] - that does work but now when scroll screen around it is if the color buffer not being cleared:

Thanks

Fixed the drawing code by adding:


		Gdx.gl.glClearColor( 0, 0, 0, 1 );
		Gdx.gl.glClear( GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT );		

But obviously this clears out my cloud background due to alpha being 1 - if it isn’t 1 the landscape goes back to how it use to be with it not clearing?! Any ideas why?

Here is image with blur code:

and without:

The shader going to be changed to do bloom so scene should look nicer.

Thanks

Driving me insane this now ??? ???, just cannot get the clouds to render, and if I do, I have to remove Gdx.gl.glClearColor( 0, 0, 0, 1 ); line but then the landscape leaves artifacts all over the place. Anybody any ideas as what this could be or where I could look?

I have tried Gdx.gl.glClearColor( 0, 0, 0, 0 ); setting alpha to zero, but then get the landscape artifacts, although the clouds are drawn.

Thanks

[icode]
clear screen
render background

start bloom shader
render world
end bloom shader
[/icode]

If that really doesn’t work, you can render your clouds to another frame buffer and draw that frame buffer before the bloom stuff.

Hi,

Thanks for that. The cloud renderer code does clear the screen first then renders the clouds(background).

So, I have this at the moment

clear screen in cloud renderer
draw cloud

bloom shader starts
render to fbo’s etc
render world
end bloom shader

Will try what you say by putting cloud into another fbo and then draw that, why would this work btw as opposed to drawing it directly to the screen?

Thanks again, appreciate it.

It might work because if you’re rendering the clouds to the screen, and then overwriting the screen with some of your bloom stuff (you really shouldn’t do this), then having the separate framebuffer will allow you to render each thing completed all at once.

Not sure what you mean by I shouldn’t really do this - with overwriting the screen? Cannot see another way of doing it, draw the clouds (which clear the screen first), then draw my landscape from the fbo’s needed to do the blur/bloom effect, I thought this was how to do it. Only way to get this to work so no screen artifacts is to clear the screen again, but clouds then don’t appear. I have just cleared the FBO’s and this will allow the clouds to appear but now get tiny pixel holes in random places appearing in my landscape?


		Gdx.gl.glClearColor( 0, 0, 0, 0 );
		Gdx.gl.glClear( GL20.GL_COLOR_BUFFER_BIT);
		cloudBackground.render(0.05f,null);// render clouds

// Render landscape with blur shader
		blurTargetA.begin();
		Gdx.gl.glClearColor( 0, 0, 0, 0 );    // clear FBO
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
		batch.setShader(null);
		batch.begin();

		worldMap.drawMap(debug, batch, regions, camX+1, camY+1, endX , endY, WORLDWIDTH, WORLDHEIGHT);
				
		batch.flush();
		blurTargetA.end();

		batch.setShader(blurShader);
		// pass 1 - horizontal blur
		blurShader.setUniformf("dir", 1f, 0f);
		blurShader.setUniformf("radius", 1 * MAX_BLUR);
		blurTargetB.begin();
		Gdx.gl.glClearColor( 0, 0, 0, 0 );  // clear FBO
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

		fboRegion.setTexture(blurTargetA.getColorBufferTexture());
		
		batch.setColor(1,1,1,1);  

		batch.draw(fboRegion, 0, 0);
		batch.flush();
		blurTargetB.end();

		blurShader.setUniformf("dir", 0f, 1f);
		blurShader.setUniformf("radius", 1 * MAX_BLUR);
		fboRegion.setTexture(blurTargetB.getColorBufferTexture());

		batch.setProjectionMatrix(camera.combined);  // bind to main camera projection - VIP!!!
		
		batch.draw(fboRegion, (camX*16),(camY*16));//, 320,480);draw to position x400,y400
			
		batch.setShader(null);


This is what I’m getting now, as can be seen in the landscape, something not correct?

Thanks again

Thanks

I have now fixed this issue! I needed to bind the frame buffers, so we make sure we are rendering to them before the scene!