Hi, I am fairly new to shaders so and started to work with some basics and even here I find first issues . I did a simple vertex-fragment shader that uses vertex colors. The problem is how color lerps between vertices in corners. As you can see on images below, longer edges doesn't look good. How to fix that?
You can try flipping the triangle edges at the corners of your vertex colored patch. This will make it look more rounded or beveled. But that is the nature of vertex colors - they will only bing you so far as your mesh is tesselated. To break up the edge you could use modulated blending with a mask texture that further influences the shape.
Hi Marco-Sperling, thanks for your answer. What do you exactly mean by flipping edges? Changing order of vertices? Plane's vertices create grid where I snap cubic objects. I change vertices' colors in runtime to create fake shadows under those cubics. As you can see on the screens, I put 3 objects creating 'L' shape. Do you think is it possible to use mask texture in my case? I find it odd, that edge triangles with 1 black and 2 white verts are more blackish and 1 white and 2 black verts are more whiteish. I would say it should be opposite?
I'm not sure what you're looking to get, all of those corners are exactly the same; any difference / brightening / darkening between the outer and inner corner is an optical illusion. Same thing happens with a hard edge corner gradient from photoshop or anything else for that matter.
Hi bgolus, I didn't check color values before, you are right that those gradients are same. Is there any chance to change the way how those gradients are calculated between vertices? I am aiming more or less to this effect:
Not really, no. Gradients between vertices are linear gradients, always. You can add more vertices to make that rounded shape with, or do it with a texture. There are some complicated setups you can do using two channels of the vertex color to blend them together to make rounded corners, but it significantly complicates things. Basically you store a red and green as separate gradients that only overlap on the corners and multiply the two channels together. The result is a nice rounded gradient corner, but it's prone to breaking.