Jump to content

Recommended Posts

Posted

Hello everyone,

I've got a probably very dumb question.

I've created an entity that is supposed to be rendered without lighting and stuff, so that it can be seen in the dark.

However, I discovered that if two entities are onscreen, the one that is rendered later is way too bright.

I probably messed up with opengl at some point, but I cannot figure out where.

This is the entity how it should look like:

 

8FI0jg2.png

 

And this is the entity how it looks when another one is rendered before:

 

(It's the entity on the ground, not the one levitating on the right.)isMBw1Q.png

 

 

Here is my rendering code:

 

@Override
public void doRender(Entity entity, double x, double y, double z, float rotation, float partialTicks) {
	super.doRender(entity, x, y, z, rotation, partialTicks);

	EntityShootingStar star = (EntityShootingStar) entity;

	ObjectRenderer.pushMatrix(); //Wrapper for GLStateManager.doAnything
	ObjectRenderer.pushAttrib();

	ObjectRenderer.translate(x, y + 0.25, z);
	ObjectRenderer.enableLighting(false); //Calls GlStateManager.disableLighting();, GlStateManager.disableLight(0);, GlStateManager.disableLight(1);
	ObjectRenderer.enableBlend(true);
	ObjectRenderer.defaultBlendFunc(); //Calls GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
	ObjectRenderer.setColor(Color.WHITE);

	if (star.isSmall())
		ObjectRenderer.scale(0.5, 0.5, 0.5);

	if (star.getType() != Type.NO_CORE) {
		ObjectRenderer.pushMatrix();
		ObjectRenderer.rotate(star.rotationYaw, 0, 1, 0);
		ObjectRenderer.rotate(star.rotationPitch, 1, 0, 0);
		ObjectRenderer.rotate((star.getTicksAtAll() - star.getTicksOnGround()) * 10, 1, 0, 0);

		Image img = star.getType() == Type.MORIATUM ? this.dark : this.light;
		TexPos tex = img.getTexPos();

		// Render Shape
		ObjectRenderer.bindTexture(null);
		img.bind();
		if (!star.isSmall()) {
			ObjectRenderer.startDrawingQuads();
			ObjectRenderer.stretchTextures = true;
			ObjectRenderer.renderAABox(new Vector3d(-CORE_SIZE, -CORE_SIZE, -CORE_SIZE), new Vector3d(CORE_SIZE, CORE_SIZE, CORE_SIZE), tex.interpolate(0.5, 0, 1, 0.5));
			ObjectRenderer.stretchTextures = false;
			ObjectRenderer.draw();
		}
		ObjectRenderer.startDrawing(GL11.GL_TRIANGLES);
		for (EnumFacing dir : EnumFacing.values()) {
			Vector3d core = new Vector3d(dir.getDirectionVec().getX() * CORE_SIZE, -dir.getDirectionVec().getY() * CORE_SIZE, dir.getDirectionVec().getZ() * CORE_SIZE);
			Vector3d spike = new Vector3d(dir.getDirectionVec().getX() * SPIKE_SIZE, -dir.getDirectionVec().getY() * SPIKE_SIZE, dir.getDirectionVec().getZ() * SPIKE_SIZE);
			double inverted = dir.getAxisDirection() == AxisDirection.POSITIVE ? 1 : -1;
			for (EnumFacing side : EnumFacing.HORIZONTALS) {
				Vector2d offset = new Vector2d(side.getDirectionVec().getX() * CORE_SIZE, side.getDirectionVec().getZ() * CORE_SIZE);
				Vector2d sided = new Vector2d(inverted * side.getDirectionVec().getZ() * CORE_SIZE, -inverted * side.getDirectionVec().getX() * CORE_SIZE);

				Vector3d core1 = new Vector3d(core);
				Vector3d core2 = new Vector3d(core);
				Vector2d off = new Vector2d();
				off.add(offset);
				off.add(sided);
				this.offset(core1, off);
				off = new Vector2d();
				off.add(offset);
				off.sub(sided);
				this.offset(core2, off);
				ObjectRenderer.addVertexWithUV(core1.x, core1.y, core1.z, tex.getMinU(), tex.getMaxV());
				ObjectRenderer.addVertexWithUV(core2.x, core2.y, core2.z, tex.getInterpolatedU(0.5), tex.getMaxV());
				ObjectRenderer.addVertexWithUV(spike.x, spike.y, spike.z, tex.getInterpolatedU(0.25), tex.getMinV());
			}
		}
		ObjectRenderer.draw();
		ObjectRenderer.popMatrix();
	}

	ObjectRenderer.disableTexture();
	GL11.glShadeModel(GL11.GL_SMOOTH);
	ObjectRenderer.startDrawing(GL11.GL_TRIANGLES);

	double size = Math.min(star.getTicksOnGround(), star.getTicksAtAll()) / 600.0;
	if (size > 1)
		size = 1;

	this.rotateBeam(star, new Vector3d(size * 5, 0, 0), 1.0);
	this.rotateBeam(star, new Vector3d(0, size * 5, 0), 1.25);
	this.rotateBeam(star, new Vector3d(0, 0, size * 5), 0.75);
	this.rotateBeam(star, new Vector3d(-size * 3, 0, 0), 1.25);
	this.rotateBeam(star, new Vector3d(0, -size * 3, 0), 0.75);
	this.rotateBeam(star, new Vector3d(0, 0, -size * 3), 1.0);
	this.rotateBeam(star, new Vector3d(-size * 5, size * 3, 0), 1.25);
	this.rotateBeam(star, new Vector3d(0, -size * 5, size * 3), 0.75);
	this.rotateBeam(star, new Vector3d(size * 3, 0, -size * 5), 1.0);

	ObjectRenderer.draw();
	GL11.glShadeModel(GL11.GL_FLAT);
	ObjectRenderer.enableTexture();
	ObjectRenderer.enableBlend(false);
	ObjectRenderer.enableLighting(true);
	ObjectRenderer.popAttrib();
	ObjectRenderer.popMatrix();
}

private void rotateBeam(EntityShootingStar star, Vector3d base, double seed) {
	Matrix3d m = new Matrix3d(1, 0, 0, 0, 1, 0, 0, 0, 1);
	Matrix3d m1 = new Matrix3d(1, 0, 0, 0, 1, 0, 0, 0, 1);
	m.rotX(0.05 * seed * star.ticksExisted % (Math.PI * 2));
	m1.rotY(0.025 * seed * star.ticksExisted % (Math.PI * 2));
	m.mul(m1);
	m.transform(base);
	this.renderBeam(star, base);
}

private void renderBeam(EntityShootingStar star, Vector3d direction) {
	ObjectRenderer.setColorToWorldrenderer(star.getColor());
	ObjectRenderer.addVertex(0, 0, 0);
	Color c = star.getColor().clone();
	c.a = 0;
	ObjectRenderer.setColorToWorldrenderer(c);
	EntityPlayer player = ClientUtils.mc().thePlayer;
	Vector3d look = new Vector3d(star.posX - player.posX, star.posY - player.posY - player.getEyeHeight(), star.posZ - player.posZ);
	Vector3d cross = new Vector3d();
	cross.cross(direction, look);
	cross.normalize();
	cross.scale(0.5);
	Vector3d A = new Vector3d(direction);
	Vector3d B = new Vector3d(direction);
	B.add(cross);
	A.sub(cross);

	ObjectRenderer.addVertex(A);
	ObjectRenderer.addVertex(B);
}

private void offset(Vector3d vec, Vector2d offset) {
	boolean pos = false;
	if (vec.getX() == 0) {
		vec.setX(offset.getX());
		pos = true;
	}
	if (vec.getY() == 0) {
		if (pos)
			vec.setY(offset.getY());
		else
			vec.setY(offset.getX());
	}
	if (vec.getZ() == 0) {
		vec.setZ(offset.getY());
	}
}

 

(hope you understand it)

 

Thanks in advance for your efford.

 

EDIT: It has probably something to do with the blend function, because in front of the black background of the sky, it is rendered normal.

Posted

I did post even two screenshot, they're inside the first two spoiler boxes, if you haven't found them yet.

 

Changing the order of pushAttrib and pushMatrix didn't change anything.

 

Yes, cuz you do not have anything in those pushAttrib() methods. But its just cleaner.

Posted

Please try changing blend function into

GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE)

&

GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ZERO)

and take screenshots of them, for debug purpose.

(Because it might be problem of blending)

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

It looks like 2 entities spawned at same location so it looks brighter.

They are not 2 entities, see the new screenshots I made:

 

First, as it was before. I just rotated the head a bit until the other entity comes into sight, I changed nothing else:

 

Alone:

HkcPyFh.png

With Other:

C3kolBG.png

 

Second with ONE:

 

Alone:

dRdatBk.png

With Other:

lE1MzWk.png

 

Third with ZERO:

 

Alone:

QIHYFuc.png

With Other:

QoVsVFQ.png

 

 

I hope this helps you...

Posted

Strange. It seems like blending function does not applied when 2 entities are drawn.

I think it is reset to the GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE) then, but idk why.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

  • 3 weeks later...
Posted

It's getting even weirder...

 

I ran a GL State checker over it and the differences between the two rendering modes are those:

[20:03:53] [Client thread/INFO] [minersbasic]: GL_VERTEX_ARRAY_STRIDE: 28 -> 16 (Stride between vertices)
[20:03:53] [Client thread/INFO] [minersbasic]: GL_COLOR_ARRAY_STRIDE: 28 -> 16 (Stride between colors)
[20:03:53] [Client thread/INFO] [minersbasic]: GL_TEXTURE_COORD_ARRAY_STRIDE: 28 -> 20 (Stride between texture coordinates)

(Left side is normal, right side is wrongly rendered)

 

I actually don't know what they mean, but maybe anyone knows?

 

Also I discovered that other Entities are affected as well, even if no shooting star is nearby. Here's a screenshot of Items being rendered weirdly when laying next to one:

 

SiJJRU2.png

 

Also, the bows of skeletons show that halfway-transparent look.

I really need a way to fix it, it's so annoying...

 

EDIT: I think I have found out something useful: It does work if I call

GL11.glDisable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

instead of

GlStateManagerdisableLighting();
GlStateManager.enableBlend();
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

 

Is there maybe something that I don't understand with the GLStateManager?

And, even more important, is it OK when I do it like that or do I break something else with it? Or should I maybe call both?

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.