Jump to content

[1.8][OpenGL] Entity rendered too bright


Bedrock_Miner

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 3 weeks later...

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?

Link to comment
Share on other sites

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

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

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