Jump to content

Only Rendering The Visible Sides Of A Mob


ducsuus

Recommended Posts

Hello!

 

Due to my derp nature, I felt the need to make a door mob in-game (literally, a door which walks around and beets the shizz out of you). As many of you may know, you can only ever see up to three sides of a block when you look at it, this means if the block is transparent, you can't see textures from the other side of the block.

 

This is the case for doors as well. Doors have a window in the top part of the block, because of the above rule you can look through the window and never see the other side of the door.

 

Unfortunately, this rule doesn't apply to rendering mobs. Mobs appear to have all sides rendered, meaning if you have create a door and look through the window you will still see the back of the door.

 

An screenshot below I took illustrates this:

 

width=800 height=424DvTJrqK.png?1 [/img]

 

Could somebody please explain to me how I would create a mob with the same effect as the door has.

 

I haven't supplied code because I didn't feel it was needed, if code is needed please ask.

 

Thanks!

 

~Joe

Link to comment
Share on other sites

I had hoped there was some option to disable rendering invisible sides.

 

The problem is that the back side is NOT invisible.  I mean the transparency on the front side means that the graphics engine will try to render the back too -- I think even with culling it would decide that it should be rendered.  I'm not expert on this, just thinking that a good graphics engine would try to do that.

 

But this would make one side look like it has a massive hole in it, surely that's worse?

 

Well, it is good to be picky, but I'm not sure it would look that bad -- I'm suggesting to just remove the lattice between the panes in the window on the back side.  There would still be the lattice on the other side which people would see from the back (indeed that is your current problem from the front).

 

Anyway, someone that is good with the rendering may know a better way to do client-side disabling.  However, a block is different than an entity because blocks have a regular model and so the idea of sides is well-defined whereas generally entities have all sorts of moving pieces and so I don't think there is a general solution.

 

One other idea is to swap the texture depending on what side of the entity is facing the player running the client.  That would take a little bit of coding, but shouldn't be too hard.  So you could use a texture with the back transparent if the front is facing player, and use a texture with the front transparent if the back is facing the player.

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

Link to comment
Share on other sites

I had hoped there was some option to disable rendering invisible sides.

 

The problem is that the back side is NOT invisible.  I mean the transparency on the front side means that the graphics engine will try to render the back too -- I think even with culling it would decide that it should be rendered.  I'm not expert on this, just thinking that a good graphics engine would try to do that.

 

But this would make one side look like it has a massive hole in it, surely that's worse?

 

Well, it is good to be picky, but I'm not sure it would look that bad -- I'm suggesting to just remove the lattice between the panes in the window on the back side.  There would still be the lattice on the other side which people would see from the back (indeed that is your current problem from the front).

 

Anyway, someone that is good with the rendering may know a better way to do client-side disabling.  However, a block is different than an entity because blocks have a regular model and so the idea of sides is well-defined whereas generally entities have all sorts of moving pieces and so I don't think there is a general solution.

 

One other idea is to swap the texture depending on what side of the entity is facing the player running the client.  That would take a little bit of coding, but shouldn't be too hard.  So you could use a texture with the back transparent if the front is facing player, and use a texture with the front transparent if the back is facing the player.

 

In fact, I think it would be easier (possible more efficient?) to just create a model which is made of 6 cubes shaped like a door, that way the "inside" sides of the cubes could be textured to be transparent.

 

The only problem I could see, is Techne seems to have a bug when texturing objects - if I have two cubes in Techne, they will use the same coordinates on the texture map meaning I can't have individual textures :S Please not it is completely possible that this is not a bug and is me being a derp; I don't have to time to conduct proper research right now :P

 

I think that the reason blocks have this feature and entities do not is because entities are more subject to moving around and exposing the "invisible" sides. Blocks don't turn around, the only way the invisible sides can be rendered is for the player to move around the block.

 

Try comparing the yaws of your entity and the player and switching between two textures depending on what side of the door the player is facing. Each texture would have a different side of the door transparent!

 

This may be the way I have to go, but it seems a bit sloppy? I would need 6 textures, which seems a bit stupid :S

 

Why? The door has 6 sides, therefore there are 6 possible combinations of the 3 sides the player can see, for each one of those combinations there are 3 sides which should be invisible. I certainly don't like the sound of having to:

 

a) make 6 textures for each one of these blocks I am making (more blocks to be like this one)

 

b) use this method - I hate hard coding stuff like this :( (it's not the nature of programming...).

 

Thanks for both of your replies, I suspect when I get home later today I will have bigger and deeper look at this (hopefully finding some kind of holy grail).

 

~Joe

Link to comment
Share on other sites

Hi

 

There is an easy way to do this, it is called back face culling.  If you turn culling off, the game will render both sides of each face.  If you turn back face culling on, you will only see one of them.

 

        GL11.glCullFace(GL11.GL_BACK);

        GL11.glEnable(GL11.GL_CULL_FACE);

or

        GL11.glDisable(GL11.GL_CULL_FACE);

 

 

This guide to openGL is pretty good and has more details.

http://www.glprogramming.com/red/

 

This link talks a bit about the tessellator and the "sides" of faces if you turn back face culling on.

 

http://greyminecraftcoder.blogspot.com.au/2013/08/the-tessellator.html

 

-TGG

Link to comment
Share on other sites

Hmm, I was thinking that backface culling wouldn't work if the front polygon is transparent -- normally in backface culling you use it for polygons that are fully not visible, but I guess you are right -- it will probably cull the back face anyway since that is usually determined simply by the direction considered the outside of the surface.  Basically in this particular case he wants an artifact that is usually undesirable.

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

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



×
×
  • Create New...

Important Information

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