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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Reach Out To Rapid Digital: What sapp Info: +1 41 4 80 7 14 85 Email INFO: rap iddi gita lrecov ery @ exe cs. com Hello, my name is Jayson, and I’m 35 years old from the United Kingdom. My family and I recently endured an incredibly challenging experience that I wouldn’t wish on anyone. We became victims of a cryptocurrency investment fraud scheme that saw us lose a staggering $807,000 in USDT and Bitcoins. The fraudsters had created a convincing facade, and we were lured into investing, only to discover later that the platform was a complete scam. We were left devastated, not just financially, but emotionally, as we had trusted these people and believed in the legitimacy of the investment. After the initial shock wore off, we desperately searched for ways to recover the lost funds. It seemed like an impossible task, and we felt as though there was no hope. That’s when, by sheer luck, we stumbled across a post about Rapid Digital Recovery, a cryptocurrency and funds recovery organization with a proven track record in cybersecurity and fraud recovery. We decided to reach out to them, and from the first interaction, we were impressed with their professionalism and transparency. They explained the recovery process in detail and reassured us that they had the skills and expertise to track down the perpetrators and recover our funds. This gave us a renewed sense of hope, something we hadn’t felt in months. What truly stood out during our experience with Rapid Digital Recovery was their dedication to the recovery process. The team went above and beyond, using sophisticated tracking tools and cyber forensics to gather critical information. Within a matter of weeks, they had successfully located the funds and traced the scam back to the fraudsters responsible. They worked with the authorities to ensure the criminals were held accountable for their actions. To our relief, the team at Rapid Digital Recovery was able to recover every single penny we had lost. The funds were returned in full, and the sense of closure we felt was invaluable. We couldn’t have imagined such a positive outcome in the early stages of our recovery journey, and we are deeply grateful for the work they did. If you ever find yourself in a similar situation, I highly recommend contacting Rapid Digital Recovery. Their expertise, transparency, and dedication to their clients make them the go-to choice for anyone seeking to recover lost cryptocurrency or funds. They truly gave us back our financial future.  
    • This is my first time modding anything, so maybe just skill issue. I'm using Forge 54.0.12 and Temurin 21.0.5+11-LTS I wanted to create a custom keybind and to check whether it works I'd like to send a chat message. I tried using Minecraft.getInstance().player.sendSystemMessage(Component.literal("test")); but IntelliJ couldnt resolve sendSystemMessage(...). Since I saw people using it in earlier versions, I tried the same thing with 1.20.6(- 50.1.0), where it works fine, now I can't figure out if this is intentional and whether there are other options for sending chat messages. On that note, is there more documentation than https://docs.minecraftforge.net/en/1.21.x/? It seems very incomplete compared to something like the Oracle Java docs
    • Hi, i'm having this error and I wanna fix it. we try: -Reload drivers -Eliminate .minecraft -Eliminate Java -Restart launcher -Verify if minecraft is using gpu -Mods  in .minecraft is empty -Install the latest and recomended version of forge idk what i have to do, help me pls. the lastest log is: https://mclo.gs/WAMao8x  
    • Read the FAQ, Rule #2. (https://forums.minecraftforge.net/topic/125488-rules-and-frequently-asked-questions-faq/)  
  • Topics

×
×
  • Create New...

Important Information

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