I tried using vertex for every verticies, but my lighting comes out weird. What happens is the value gets there but everything has the same lighting. Its like they have the same value for everything.
Excerpts
#ifdef NEED_TEXCOORD8
attribute int inTexCoord8; // This is holding light level
#endif
void main()
{
basicLightAdjustment = ((inTexCoord8) >> 1) * 0.31;
}
Java code - Define the Quad and load it with a ‘0’ in all the texCoord values
public static LBQuad createLowerQuad(float x, float y, float z)
{
LBQuad quad = new LBQuad(x, y, false);
VertexBuffer inBuf = quad.getBuffer(VertexBuffer.Type.TexCoord);
int numElements = inBuf.getNumElements();
VertexBuffer inBuf = quad.getBuffer(VertexBuffer.Type.TexCoord);
int numElements = inBuf.getNumElements();
initBuffer(quad, VertexBuffer.Type.TexCoord8, BufferUtils.createByteBuffer(numElements), Usage.Dynamic, 1, Format.UnsignedByte, false);
VertexBuffer buf = quad.getBuffer(VertexBuffer.Type.TexCoord8);
final ByteBuffer quadVerticies = (ByteBuffer) buf.getData();
numElements = buf.getNumElements();
quadVerticies.rewind();
quadVerticies.put((byte) 0).put((byte)0).put((byte)0).put((byte)0);
quadVerticies.flip();
buf.updateData(quadVerticies);
return quad;
}
Now we process the torches and set the light level for all the affect Grid position. The function before this loops through all the torches and figures based on grid distance which grid positions are affect and calls setBasicLightLevel()
protected void setBasicLightLevel(WorldLocationData location, int lightLevel, int torchActive)
{
for(LOCATION loc : WorldLocationData.LOCATION.values())
{
GameItem item = location.getLocation(loc);
if (item != null)
{
Mesh mesh = item.getMesh();
final VertexBuffer cvb = mesh.getBuffer(VertexBuffer.Type.TexCoord8);
if (cvb != null)
{
int numElements = cvb.getNumElements();
final ByteBuffer lightLevelFB = (ByteBuffer) cvb.getData();
// update data in vertex buffers
lightLevelFB.rewind();
//Need to update the light level
int newLevel = torchActive + (lightLevel << 1);
System.out.println("num Elements "+numElements+"new level "+newLevel +" LightLevel "+lightLevel+" active torch "+torchActive);
for(int index =0; index < numElements; index++)
lightLevelFB.put((byte)newLevel);
lightLevelFB.flip();
cvb.updateData(lightLevelFB);
mesh.updateBound();
}
}
}
}
Output when the game runs, so I can see the levels and the light level each grid should be. Light is in grid 36x32. Same grid space gets level 7 light, and the rest range from 0 - 5. So there should be different light levels in different grid spaces, but they are all the same on the output.
It doesn’t seem like the value inside the shader is anything like what I’m putting them in
basic light level x,y-1,-1 2 35,31
num Elements 4new level 3 LightLevel 1 active torch 1
basic light level x,y0,-1 1 36,31
num Elements 4new level 5 LightLevel 2 active torch 1
num Elements 4new level 5 LightLevel 2 active torch 1
basic light level x,y1,-1 2 37,31
num Elements 4new level 0 LightLevel 0 active torch 0
num Elements 4new level 0 LightLevel 0 active torch 0
num Elements 4new level 0 LightLevel 0 active torch 0
num Elements 4new level 0 LightLevel 0 active torch 0
basic light level x,y-1,0 1 35,32
num Elements 4new level 5 LightLevel 2 active torch 1
num Elements 4new level 5 LightLevel 2 active torch 1
basic light level x,y0,0 0 36,32
num Elements 4new level 7 LightLevel 3 active torch 1
num Elements 4new level 7 LightLevel 3 active torch 1
basic light level x,y1,0 1 37,32
num Elements 4new level 0 LightLevel 0 active torch 0
num Elements 4new level 0 LightLevel 0 active torch 0
num Elements 4new level 0 LightLevel 0 active torch 0
num Elements 4new level 0 LightLevel 0 active torch 0
basic light level x,y-1,1 2 35,33
num Elements 4new level 3 LightLevel 1 active torch 1
num Elements 4new level 3 LightLevel 1 active torch 1
num Elements 4new level 3 LightLevel 1 active torch 1
num Elements 4new level 3 LightLevel 1 active torch 1
num Elements 4new level 3 LightLevel 1 active torch 1
basic light level x,y0,1 1 36,33
num Elements 4new level 5 LightLevel 2 active torch 1
num Elements 4new level 5 LightLevel 2 active torch 1
basic light level x,y1,1 2 37,33
num Elements 4new level 3 LightLevel 1 active torch 1
num Elements 4new level 3 LightLevel 1 active torch 1
num Elements 4new level 3 LightLevel 1 active torch 1
I’m not sure what I did wrong. I hope I supplied enough info to see something. If you need something else, let me know.