Jump to content

[152][Solved]How to render entities/TileEntities ignoring lighting?


WeAthFolD

Recommended Posts

I'm recently doing some stuff like weapon ray and lightballs, so I'm trying to find a way to make the entity/TileEntity renders in a constant brightness, regardless of daytime and environment, but I've met some problem.

First I tried to disable GL_LIGHTING, like what I saw in the original src code.

in my RenderXXX extends Render :

public void render(entity e, ...) {
Tessellator t = Tessellator.instance;
GL11.glPushMatrix();
GL11.glDisable(GL11.GL_LIGHTING);
//....other gl settings ignored

t.startDrawingQuads();
//...Actual draw call
t.draw();
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glPopMatrix();
}

But disable lighting just won't do, the entity renders as it used to be.

After then I found Tessellator#setBrightness(int) function, and I modified my code to this:

public void render(entity e, ...) {
Tessellator t = Tessellator.instance;
GL11.glPushMatrix();
GL11.glDisable(GL11.GL_LIGHTING);
//....other gl settings ignored

t.startDrawingQuads();
t.setBrightness(0xFFFFFF);
//...Actual draw call
t.draw();
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glPopMatrix();
}

Now the rendering behaves somehow different but I didn't get what I expected. When I was trying with brightness 255, the entity looks kinda dark during the day, but really bright at night. I also tried 65535 and 0xFFFFFF but it became even darker.

I've looked Beacon's TileRender and didn't see it doing anything special but disabling GL_LIGHTING.

So what's wrong with my code? What should I do if I want an entity/TileEntity to render in full brightness always?

Thanks a lot for your help>_<

Link to comment
Share on other sites

It seems that Minecraft not only uses OpenGL light source but also uses other things (such as lightmap) to control brightness. Disabling OpenGL light source in Render can make Entity more clear, but not bright.

If you are using Tessellator to draw Entity, you can try to use setBrightness to control its brightness. Try 15728880 in your param. BTW, I don't think using Tessellator to draw Entity is a good idea even though it's a lightweight solution to render...

Link to comment
Share on other sites

20130716200935.jpg

♪~ It works.

 

The terrifying pigs are rendered with glDisable(GL11.GL_LIGHTING) and OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240f, 240f). Yep, Minecraft also use lightmap to control brightness. The door is drew with setBrightness(15728880).

BTW, resetting the lightmap without disabling OpenGL light source will make Entities more soft.

 

Codes of Standardized Entity Render

GL11.glPushMatrix();
GL11.glDisable(GL11.GL_LIGHTING);
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240f, 240f);
...render...
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glPopMatrix();

 

Codes of Tessellator Drawer

tessellator.setBrightness(15728880);

 

If you are curious about why I chose 15728880...

 

15728880 = 15 << 20 | 15 << 4

The first 15 is lighting of environment, and the second 15 is lighting of itself.

So, I guess that 15728880 is potential the brightest lighting in game...

Link to comment
Share on other sites

20130716200935.jpg

♪~ It works.

 

The terrifying pigs are rendered with glDisable(GL11.GL_LIGHTING) and OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240f, 240f). Yep, Minecraft also use lightmap to control brightness. The door is drew with setBrightness(15728880).

BTW, resetting the lightmap without disabling OpenGL light source will make Entities more soft.

 

Codes of Standardized Entity Render

GL11.glPushMatrix();
GL11.glDisable(GL11.GL_LIGHTING);
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240f, 240f);
...render...
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glPopMatrix();

 

Codes of Tessellator Drawer

tessellator.setBrightness(15728880);

 

If you are curious about why I chose 15728880...

 

15728880 = 15 << 20 | 15 << 4

The first 15 is lighting of environment, and the second 15 is lighting of itself.

So, I guess that 15728880 is potential the brightest lighting in game...

> >Thanks a lot! That's exactly the answer I am looking for! Also gained lots of knowledge about Minecraft rendering...

(BTW:其实我们可以说中文)

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.