Jump to content

Recommended Posts

Posted (edited)

I'm having a really confusing problem with shading on a json block model. The model is quite complex and made of several parts, and the block can be placed facing in any horizontal direction. In three directions, it looks normal, but when it's facing south, there's this strange shading error:

 

 

Spoiler

2017-05-31_20_58_44.png.37f8bd3eafc353260915372f08e19779.png

 

To explain what's going on, that triangle is made of two elements (they are different sizes to stop them poking out the edges of the rest of the block), and for some reason on one side of the bock when it's facing one direction, the elements are shaded differently. Here is how the same face on that model looks when it's placed facing north (this is the way it should look all the time):

 

Spoiler

2017-05-31_20_59_02.png.a0f3a20315a07069dfdb3abcaae18134.png

 

Here is the model file (the relevant elements are the two that have rotation):

 

Spoiler

{
"parent": "block/block",
"textures": {
    "stonebrick": "jjmod:blocks/complex/stonebrick",
    "stone2": "jjmod:blocks/complex/stone2",
    "particle": "jjmod:blocks/complex/stone2"
},
"elements": [ 
{
    "from": [ -0.01, 12, 0 ],
    "to": [ 16.01, 16, 9.5 ],
    "faces": {
        "down":  { "uv": [ 16, 9.5, 0, 0 ], "texture": "#stone2" },
        "up":    { "uv": [ 0, 0, 16, 9.5 ], "texture": "#stone2", "cullface": "up" },
        "north": { "uv": [ 0, 0, 16, 4 ], "texture": "#stonebrick", "cullface": "north" },
        "south": { "uv": [ 0, 0, 16, 4 ], "texture": "#stonebrick" },
        "west":  { "uv": [ 0, 0, 9.5, 4 ], "texture": "#stonebrick", "cullface": "west" },
        "east":  { "uv": [ 6.5, 0, 16, 4 ], "texture": "#stonebrick", "cullface": "east" }
    }
},
{
    "from": [ 0, 1.4375, -2.5 ],
    "to": [ 16, 4.9375, 11 ],
    "rotation": { "origin": [ 0, 4.9375, -2.5 ], "axis": "x", "angle": -45 },
    "faces": {
        "down":  { "uv": [ 16, 13.5, 0, 0 ], "texture": "#stone2" },
        "up":    { "uv": [ 0, 0, 16, 13.5 ], "texture": "#stone2", "cullface": "up" },
        "north": { "uv": [ 0, 12.5, 16, 16 ], "texture": "#stonebrick" },
        "south": { "uv": [ 0, 12.5, 16, 16 ], "texture": "#stonebrick" },
        "west":  { "uv": [ 0, 12.5, 13.5, 16 ], "texture": "#stone2", "cullface": "west" },
        "east":  { "uv": [ 2.5, 12.5, 16, 16 ], "texture": "#stone2", "cullface": "east" }
    }
},
{
    "from": [ 0, 12, 9.5 ],
    "to": [ 16, 16, 16 ],
    "faces": {
        "down":  { "uv": [ 16, 16, 0, 9.5 ], "texture": "#stone2" },
        "up":    { "uv": [ 0, 9.5, 16, 16 ], "texture": "#stone2", "cullface": "up" },
        "north": { "uv": [ 0, 0, 16, 4 ], "texture": "#stonebrick", "cullface": "north" },
        "south": { "uv": [ 0, 0, 16, 4 ], "texture": "#stonebrick" },
        "west":  { "uv": [ 9.5, 0, 16, 4 ], "texture": "#stonebrick", "cullface": "west" },
        "east":  { "uv": [ 0, 0, 6.5, 4 ], "texture": "#stonebrick", "cullface": "east" }
    }
},
{
    "from": [ 0, 6, -2.875 ],
    "to": [ 16, 9.5, 4.625 ],
    "rotation": { "origin": [ 0, 9.5, -2.875 ], "axis": "x", "angle": -45 },
    "faces": {
        "down":  { "uv": [ 16, 10.5, 0, 3 ], "texture": "#stone2" },
        "up":    { "uv": [ 0, 3, 16, 10.5 ], "texture": "#stone2", "cullface": "up" },
        "north": { "uv": [ 0, 9, 16, 12.5 ], "texture": "#stonebrick" },
        "south": { "uv": [ 0, 9, 16, 12.5 ], "texture": "#stonebrick" },
        "west":  { "uv": [ 3, 9, 10.5, 12.5 ], "texture": "#stone2", "cullface": "west" },
        "east":  { "uv": [ 5.5, 9, 13, 12.5 ], "texture": "#stone2", "cullface": "east" }
    }
},
{
    "from": [ -0.01, 0, -5 ],
    "to": [ 16.01, 15.99, 0 ],
    "faces": {
        "down":  { "uv": [ 16, 16, 0, 11 ], "texture": "#stone2", "cullface": "north" },
        "up":    { "uv": [ 0, 11, 16, 16 ], "texture": "#stone2", "cullface": "north" },
        "north": { "uv": [ 0, 0, 16, 16 ], "texture": "#stonebrick", "cullface": "north" },
        "south": { "uv": [ 0, 0, 16, 16 ], "texture": "#stonebrick", "cullface": "north" },
        "west":  { "uv": [ 11, 0, 16, 16 ], "texture": "#stonebrick", "cullface": "north" },
        "east":  { "uv": [ 0, 0, 5, 16 ], "texture": "#stonebrick", "cullface": "north" }
    }
}
]
}

 

I can't see anything in the model that can explain this. The elements are rotated exactly the same and constructed as similarly as they could be. I understand that minecraft automatically shades the different faces of an element differently to make cubes look realistic, but surely the faces of these two elements should always be the same anyway, so the minecraft-applied shading should match? And if it wasn't going to match, surely they would mismatch in every direction, not just on one side in one direction only? I know that I can add "shade": false as a fix, but this makes the whole element appear weirdly bright relative to things around it, and I'd much rather allow the default shading which is so close to being just right. Can anyone explain how this happens in one direction and not others? Is there anything I can do to fix it?

Edited by Jay Avery
Posted

Bump! I've tried digging through the block modelling code to see if I can figure anything out, but I'm really struggling to interpret. I've found where the 'face' of the element defines the shading brightness and it seems pretty definitive, so I'm guessing something goes wrong in the process of calculating which face is actually in which direction. It seems like this is done in FaceBakery#makeBakedQuad, with the makeQuadVertexData and getFacingFromVertexData methods. But it seems to use some mysterious bitwise calculations using arrays, and I do not understand how it works at all.

 

Can anyone help me understand how those calculations are done, or suggest how/why they might be producing the wrong answers for my model?

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.