I took 4 squares with the outer corners painted in black, and the other ones in white. For some reason, they have a different gradient.

fixed4 frag (v2f i) : SV_Target
    fixed4 mainTex = tex2D(_MainTex, i.uv);
    fixed4 overTex = tex2D(_OverTex, i.uv3);
    fixed4 final = fixed4(lerp(mainTex.rgb, overTex.rgb, overTex.a) * i.color, 1.0);
    final = lerp(float4(0, 0, 0, 1.0), final, i.color.a); // shadows

    return final;

How can i make the same gradients as bottom-left and top-right?

In-game this is faces of blocks (like minecraft) and gradients - is smooth shadow/light. So I cannot change tris



2 Answers 2


If you can't change the vertices, there are two other approaches:

You can either give the triangles uv coordinates and do the lighting based on that (you'll need uv coordinates eventually anyways, why not add them now?)

Or you can overcompensate the colors a bit. The problem happens, because at the outer edges, the color is averaged along 1 unit, while at the inner edges it is √2 units (≈1.414). So instead of making every white vertex actually white, give the adjacent vertices to the black one a color of 1/√2 * white 0.5 * white (Thanks to DMGregory for correcting this) and the opposite vertex a color of 1 * white. Thid way the color gets averaged out to the same gray as the others earlier. Then in the fragmenr shader multiply the colors by 2 to make them white again.

  • \$\begingroup\$ For your second method, I think you'll want the lighter outside vertices to use a 50% grey instead. Then the diagonal edge between two of these vertices will be 50% grey along its whole length, so that the opposite diagonal is cut into two equal-length gradients: one from 0 to 0.5, and one from 0.5 to 1, matching the unsplit gradient in the other quads. With 1/sqrt(2), you won't get the same gradient in both cases. \$\endgroup\$
    – DMGregory
    Sep 20, 2019 at 10:50
  • \$\begingroup\$ @DMGregory You're probably right, I didn't really have time to test my hypothesis. I'll do that when I get home \$\endgroup\$
    – Bálint
    Sep 20, 2019 at 18:35
  • \$\begingroup\$ @dmgregory 50% gray is works. Thanks \$\endgroup\$
    – ArtyGrand
    Sep 21, 2019 at 16:29
  • \$\begingroup\$ @ArtyGrand please mark the answer as correct if it solved your problem \$\endgroup\$
    – Bálint
    Sep 21, 2019 at 19:42

That is the intended behaviour, since the center of an edge with two different colors has to have the 50% mix of both of them. The quad is cut into 2 triangles, their shared edge goes from the top left to the bottom right.

You have 2 ways to solve this: you can simply rotate one of the quads instead of changing the vertex color or you can split it into triangles in a different way.

If instead of the current approach with 2 triangles, you use 4, where they have a shared central vertex, then it will always look like the one on the right.

Basically, instead of only cutting the quad in the top-left -> bottom-right direction, cut them in the bottom-left -> top-right direction too.

|\        /|
| \      / |
|  \    /  |
|   \  /   |
|    \/    |
|    /\    |
|   /  \   |
|  /    \  |
| /      \ |
  • \$\begingroup\$ Oh, in-game this is faces of blocks (like minecraft) and gradients - is smooth shadow/light. So I cannot change tris. Sorry. \$\endgroup\$
    – ArtyGrand
    Sep 20, 2019 at 9:29
  • 1
    \$\begingroup\$ @ArtyGrand then give them uv coordinates and do it based on that \$\endgroup\$
    – Bálint
    Sep 20, 2019 at 9:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .