Bedrock_Miner Posted September 13, 2015 Share Posted September 13, 2015 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: 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.) 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. Quote http://i.imgur.com/wNvtGZw.png[/img] MODS and MODDING TUTORIALS Link to comment Share on other sites More sharing options...
ItsAMysteriousYT Posted September 16, 2015 Share Posted September 16, 2015 Paste a screenshot of the rendered entity please. Also, call pushAttrib before pushMatrix(). Quote Link to comment Share on other sites More sharing options...
Bedrock_Miner Posted September 16, 2015 Author Share Posted September 16, 2015 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. Quote http://i.imgur.com/wNvtGZw.png[/img] MODS and MODDING TUTORIALS Link to comment Share on other sites More sharing options...
ItsAMysteriousYT Posted September 16, 2015 Share Posted September 16, 2015 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. Quote Link to comment Share on other sites More sharing options...
ItsAMysteriousYT Posted September 16, 2015 Share Posted September 16, 2015 Why do you set the color in there? For transparent bits, use GLStateManager.setColorOpaque() or GLStatemanager.setColorRGBA() Quote Link to comment Share on other sites More sharing options...
Bedrock_Miner Posted September 16, 2015 Author Share Posted September 16, 2015 The method I used is a wrapper again and just calls GLStateManager.color (setColor... was renamed to that). Quote http://i.imgur.com/wNvtGZw.png[/img] MODS and MODDING TUTORIALS Link to comment Share on other sites More sharing options...
ItsAMysteriousYT Posted September 16, 2015 Share Posted September 16, 2015 Oh - im sorry, the setColorOpaque is in the Worldrenderer. Use it like this: WorldRenderer renderer=Tessellator.getInstance().getWorldRenderer(). then do renderer.setColorOpaque(...). Sorry, my mistake Quote Link to comment Share on other sites More sharing options...
Bedrock_Miner Posted September 16, 2015 Author Share Posted September 16, 2015 Unfortunately, neither this nor .setBrightness solved the issue. I still assume it's something with the blend, but I have no idea. Quote http://i.imgur.com/wNvtGZw.png[/img] MODS and MODDING TUTORIALS Link to comment Share on other sites More sharing options...
ItsAMysteriousYT Posted September 18, 2015 Share Posted September 18, 2015 Try leaving the light enabled, so the blendfunction uses the brightness of the blocks underneeth it. Quote Link to comment Share on other sites More sharing options...
Bedrock_Miner Posted September 21, 2015 Author Share Posted September 21, 2015 Didn't change anything Quote http://i.imgur.com/wNvtGZw.png[/img] MODS and MODDING TUTORIALS Link to comment Share on other sites More sharing options...
ItsAMysteriousYT Posted September 21, 2015 Share Posted September 21, 2015 Hm... okay, do you bind the white stuff as texture? If yes, its clear that is is brighter than the normal stuff, cuz it is being scaled down. Quote Link to comment Share on other sites More sharing options...
Bedrock_Miner Posted September 21, 2015 Author Share Posted September 21, 2015 Where do you mean it's scaled down? The Star is rendered completely equal in size all the time. Quote http://i.imgur.com/wNvtGZw.png[/img] MODS and MODDING TUTORIALS Link to comment Share on other sites More sharing options...
ItsAMysteriousYT Posted September 21, 2015 Share Posted September 21, 2015 Does the console have any glOverflow or glUnderflow output in it? Quote Link to comment Share on other sites More sharing options...
Bedrock_Miner Posted September 21, 2015 Author Share Posted September 21, 2015 No, I would have noticed that Quote http://i.imgur.com/wNvtGZw.png[/img] MODS and MODDING TUTORIALS Link to comment Share on other sites More sharing options...
ItsAMysteriousYT Posted September 21, 2015 Share Posted September 21, 2015 Hm... i have no idea what it is caused by Sorry for that. Quote Link to comment Share on other sites More sharing options...
Bedrock_Miner Posted September 21, 2015 Author Share Posted September 21, 2015 It's OK... I hope no one will notice that in the mod.. Quote http://i.imgur.com/wNvtGZw.png[/img] MODS and MODDING TUTORIALS Link to comment Share on other sites More sharing options...
Warix Posted September 21, 2015 Share Posted September 21, 2015 It looks like 2 entities spawned at same location so it looks brighter. Quote Link to comment Share on other sites More sharing options...
Abastro Posted September 22, 2015 Share Posted September 22, 2015 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) Quote 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 More sharing options...
Bedrock_Miner Posted September 22, 2015 Author Share Posted September 22, 2015 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: With Other: Second with ONE: Alone: With Other: Third with ZERO: Alone: With Other: I hope this helps you... Quote http://i.imgur.com/wNvtGZw.png[/img] MODS and MODDING TUTORIALS Link to comment Share on other sites More sharing options...
Abastro Posted September 22, 2015 Share Posted September 22, 2015 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. Quote 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 More sharing options...
Bedrock_Miner Posted October 12, 2015 Author Share Posted October 12, 2015 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: 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? Quote http://i.imgur.com/wNvtGZw.png[/img] MODS and MODDING TUTORIALS Link to comment Share on other sites More sharing options...
Recommended Posts
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.