Jump to content

[Solved][1.7.10] Problem with rendering shadows


wesserboy

Recommended Posts

Hello,

I am currently on my summer break, and i decided i would go do some minecraft modding.

One thing i could never do was rendering, so i figured i would use this extra time to learn how to do it.

To learn how to do it i set myself up with a nice challenge.

I wanted to make a block look like it was decaying by gradually making little blocks disappear from it.

 

I already learned a lot and its beginning to look like something, but i'm not yet happy with it.

 

This is how it currently looks:

Video

 

I use the following code to achieve this:

link

 

There's a couple of problems with this:

 

Firstly, the animation looks different depending on the side of the block you're looking at, form one side it looks like the blocks are disappearing, but from the other side it looks like the blocks 'slide away'. If you look at the video you will see what i mean.

 

Secondly, I keep rendering the original top of the block, this way there is still a crafting grid on layers deeper inside the block, which looks kinda odd. I would like to render the bottom of the block on top after the first layer has been removed, because i think it would look better that way. I know how to write the logic for this, but the rendering code...

 

If i would have to guess i think i need to stop using the RenderStanderdBlock method and draw the sides by directly interacting with the tessellator.

But I am not sure about this at all, as i said it is just i guess.

 

So my question is if someone knows how i would go about achieving this. Is my guess right, or is there a better way? And if my guess is right how would i go about implementing this idea? Does somebody maybe know a good tutorial where this is explained?

 

If you need more code/screenshots/video's or explanation, just ask and i will provide it.

I would like to thank you in advance!

 

-Wesserboy

I made the Mob Particles mod, you can check it out here: http://www.minecraftforum.net/topic/2709242-172-forge-mob-particles/

Link to comment
Share on other sites

Hello,

Today i spent the day rewriting my rendering code, and at this point it is almost perfect.

 

This is how it looks using the new code:

Video

 

This is my updated rendering code:

Link

 

There is only one problem, the block renders too bright. (there is no shadow)

15sar1y.png

 

(left is an original crafting table, right is my decaying block)

The block can look like any block in the game, I made it to look like a crafting table because it has a 'complex' texture, which is nice to test with.

 

I have tried different values in the methods tessellator.setColorOpaque_F(1F, 1F, 1F) and tessellator.setBrightness(block.getMixedBrightnessForBlock(world, x, y, z)). But i can't get the shadows to work properly.

 

My question is: How do i get/calculate the right values for the mentioned methods to render the shadows properly, or am i using the wrong methods and is there a different way of doing this?

 

-Wesserboy

I made the Mob Particles mod, you can check it out here: http://www.minecraftforum.net/topic/2709242-172-forge-mob-particles/

Link to comment
Share on other sites

Hi

What happens when you do not use these methods:

tessellator.setColorOpaque_F(1F, 1F, 1F); 
tessellator.setBrightness(block.getMixedBrightnessForBlock(world, x, y, z)); 

I'm not good at rendering, but there seems to be either something your setting that is causing this, or lightning that needs to be updated when changing the block model frequently.

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

Link to comment
Share on other sites

When i remove those two lines it looks like this:

2ir3fpw.png

The block looks very dark, the top is a lot darker than it is supposed to be, the sides look more like the normal crafting table, but still not quite the same.

 

as i said in the first post, this is one of my first attempts at rendering, so i'm also not quite sure what i am supposed to set, and what is already setup for me...

I made the Mob Particles mod, you can check it out here: http://www.minecraftforum.net/topic/2709242-172-forge-mob-particles/

Link to comment
Share on other sites

Try to set the normal in the tessellator before drawing each plane.

Look at

renderBlockAnvilRotate()

inside

net.minecraft.client.renderer.RenderBlocks

on how to set the normals correctly.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

Try to set the normal in the tessellator before drawing each plane.

Look at

renderBlockAnvilRotate()

inside

net.minecraft.client.renderer.RenderBlocks

on how to set the normals correctly.

 

It looks to me like renderBlockAnvilRotate() only uses the tessellator.setNormal() method when it renders the block in an inventory. I think the boolean declares wether it is rendered in an inventory or in the world, and if it is rendered in the world it looks like it just passes the args to renderStandardBlock(). But i could be wrong, it's a little hard to follow the code with all the deobf arg names...

 

however, if i look at the renderBlockAnvilMetadata() method, it uses the tessellator.setBrightness(block.getMixedBrightnessForBlock()) method, which leads me to think that that line in my code was correct.

It also uses the tessellator.setColorOpaque_F() method, but it seems to calculate the three float values according to a block.colorMultiplier() and some hardcoded bit manipulation...

The values are calculated even more if EntityRenderer.anaglyphEnable is true. I'm not quite sure what anaglyphEnable means, but it seems odd to me that a setting in the EntityRenderer influences the way a block is rendered...

 

I will put the tessellator.setBrightness(block.getMixedBrightnessForBlock()) call back in my code, because it seems to be right since minecraft itself uses the same call.

The bit manipulation is still a bit of a mystery to me, I don't get where all these hardcoded values come from, but it seems to me that the answer to my problem lies within that calculation.

You would think there must be a method to get the calculated results for those floats, but the hardcoded calculations lead me to think that's not the case...

 

I will have another look through the RenderBlocks class, any help/explanation on these calculations, or on another approach would be very much appreciated.

I made the Mob Particles mod, you can check it out here: http://www.minecraftforum.net/topic/2709242-172-forge-mob-particles/

Link to comment
Share on other sites

From TheGreyGhost's blog/lighting post:

render the six faces with a different lighting intensity depending on which direction the faces points:

1. Top face (Ypos) is at full intensity

2. Bottom face (Yneg) is 50% intensity

3. Z-side faces (Zpos, Zneg = South, North) are 80% intensity

4. X-side faces (Xpos, Xneg = East, West) are 60% intensity.

Use

Tessellator#setColorOpaque_F

to set the intensity before rendering the actual side. Use 1F for 100%, and e.g. 0.6F for 60%.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Thank you very much!!!  :)

if smooth lighting is turned off my block looks exactly the same as the original:

2qu2fde.png

(left vanilla crafting table, right my block)

 

I looked up the blog post you mentioned (I think you ment this one) and I still have a couple of questions.

In the tutorial it shows a chart on how to apply lighting when rendering.

 

It states the first thing you have to do is apply the side dependent intensities. This is what i have done to (mostly) fix my problem.

Then you have to apply the ColorMultiplier. It states this is what makes blocks appear blue underwater etc.

I didn't apply any colorMultiplier, but underwater my block still looks exactly the same as a normal block:

2r2vw5i.png

(left vanilla crafting table, right my block)

 

I saw the tutorial is a little outdated (2013) so my question is: Is it possible that minecraft applies the ColorMultiplier automatically now?

 

When i turn on smooth lighting, my block doesn't look the same anymore, in the tutorial it states that this is due to the 'Ambient occlusion', and if i'm not mistaking it should be as easy as to multiply the side dependent percentage with another calculated value.

But the tutorial only tells what the value is based on, not how to get/calculate it. So my question is, is there some method or formula somewhere to get this value from?

 

It's not completely necessary to fix this, but if it is as easy as applying a multiplication, i think it would be worth the effort.

 

I made the Mob Particles mod, you can check it out here: http://www.minecraftforum.net/topic/2709242-172-forge-mob-particles/

Link to comment
Share on other sites

If you have a Block without a custom renderer, you can use the

colorMultiplier

method to return a hexadecimal color value and Minecraft uses that that to apply colors (that is what those bitwise operaters are doing, getting the RGB values from 1 value).

 

If the player is underwater, that lighting is done automatically somewhere else, so you don't need to worry about that.

 

As for ambient occlusion, if you have a look at

RenderBlocks#renderStandardBlockWithAmbientOcclusion

, you can see how Minecraft calculates the ambient occlusion. As you can see, it's not easy to replicate and Minecraft doesn't even do that for it's custom renderer block, so you probably don't have to worry about that.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Thank you for your explanation, I understand it a lot better now :)

 

I had a look at renderStandardBlockWithAmbientOcclusion, but it looks really difficult, so I'll just leave it the way it is now. The difference is so small that it's probably not worth the effort anyway. ;)

I made the Mob Particles mod, you can check it out here: http://www.minecraftforum.net/topic/2709242-172-forge-mob-particles/

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.

×
×
  • Create New...

Important Information

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