Passing parameter to shader

Hi,

If I have a class as of such:


public class Entity
{
    bool lightUp;
    ...
}

Is there a way I can pass the lightUp property to the vertex shader which would then pass this onto the fragment shader?

So in fragment shader could test if lightUp is true and if so, light the texture up?

Many thanks for any advice

yes, via uniforms

Simple example here https://www.opengl.org/sdk/docs/tutorials/ClockworkCoders/uniform.php

Thank you for this.

Is it a good idea to pass in something like if a tile needs lighting up to the shader?

Like @theagentd already answered this question in your other thread, it is not at all a good idea to pass this kind of information to a shader at least in the form of a uniform. Use vertex attributes like he suggested.
Why are uniforms inefficent in this case?
Because the word “tiles” somewhat implies that you probably don’t have just two or three of them to render, but maybe a hundred forming a grid of tiles. When using a uniform which is uniform/constant per draw call you would have to make 100 draw calls and 100 uniform updates to just render 100 tiles, in the worst case without state-batching. This is very inefficient.
In this case, what you want to do is to “batch” all tiles to be rendered using a single draw call, since doing many draw calls and shader uniform uploads is what is really expensive in OpenGL.
@theagentd suggested to you to use vertex attributes for that, because those would allow for a single draw call.

I think I may have miss understood your question, KaiHH is right, uniforms are used to pass general parameters to a shader but they are not used to pass vertex information. The values are global in nature and once set are accessible across multiple draw calls. Some examples of good usages are when you want to pass light parameters, pass in the model / view / projection matrix, etc. They are constant values for at least a single draw call and typically an entire render cycle.

Thanks all,

Ultimately I draw my tile map as follows:


	worldMap[col][row].draw(batch, region);

Where worldMap is a ‘tile’ object whose draw method looks like:


public void draw(Batch batch, TextureRegion[][] t) {
	batch.draw(t[2][1], x << 4, y << 4);
}

Full code:


	for (int row = sy; row < ey + 1; row++)
				for (int col = sx; col < ex + 1; col++)
					if (getEntity(col, row) != null) 
					{
						BlankEntity entity = getEntity(col, row);
						if (entity instanceof WaterEntity)
							batch.setColor(0, 0, 0.4f, 1);
						else if (entity.lightUp)
							batch.setColor(entity.r, entity.g, entity.b, 1);
						else
							batch.setColor(0.4f, 0.4f, 0.8f, 1);
						worldMap[col][row].draw(batch, region);
					}

Thus I draw 64 tiles x 32 tiles in the loop - is this not efficient the way I am calling the batch.draw for each tile? Should I be sending the 64x32 tiles
in one batch.draw method?

Thanks for your help.