Jump to content

Fog originates from vertex position instead of player position in RenderWorldLastEvent


Recommended Posts

Posted (edited)

I'm rendering some things in RenderWorldLastEvent and would like to have fog applied to them. However when I enable fog, it originates from vertex position instead of player position.

NYqieH7.png

Here's my code:

Tessellator tess = Tessellator.getInstance();
BufferBuilder buffer = tess.getBuffer();

GlStateManager.pushMatrix();
RenderHelper.translateToZero();

GlStateManager.disableTexture2D();
GlStateManager.color(1, 0, 0);
GlStateManager.disableCull();
GlStateManager.enableFog();

buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION);

buffer.pos(0, 100, 0).endVertex();
buffer.pos(-1.1, 100, 0).endVertex();
buffer.pos(-100, 100, 0).endVertex();
buffer.pos(-101.1, 100, 0).endVertex();

tess.draw();

GlStateManager.disableFog();
GlStateManager.enableCull();
GlStateManager.enableTexture2D();

GlStateManager.popMatrix();

And this is the translateToZero() method:

public static void translateToZero() {
	Entity entity = mc.getRenderViewEntity();
	float partialTicks = mc.getRenderPartialTicks();

	GlStateManager.translate(
		-(entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * (double)partialTicks),
		-(entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * (double)partialTicks),
		-(entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * (double)partialTicks)
	);
}

Do I need to draw my quads in a different way? I've never done anything with OpenGL fog.

Edited by Silly511
Posted

You might want to contact TheGreyGhost. He does a fair bit with GL.

 

Otherwise, you need to debug the old fashioned way. You are already right to be suspicious of the translate to zero method. So maybe print out the values and get a sense of what is happening. I expect it is something wrong with the math that will become obvious.

 

For example one thing may be that by the time the render happens the current position and the last tick position may be equal to each other (since at some point in the tick the last tick position must copy the current position and the current position will get updated later). That's my guess.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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