OpenGL vertex color interpolation from center (how to?) -
here's image show mean:
i've assigned blue top, , red bottom.
how make entire top half blue, start interpolating bottom?
there's 2 solutions.
either render blue rectangle top half, , blue-->red rectangle bottom half:
float vertices[] { -1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, -1, 1, 0, 0, 0, 1, -1, -1, 0, 1, 0, 0, 1, -1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, -1, 0, 0, 0, 0, 1 };
or write fragment shader manually interpolation you.
#version 450 //we're assuming these normalized [0,1]. in vec2 texturecoord; out vec4 color; void main() { if(texturecoord.y >= 0.5) color = vec4(0, 0, 1, 1); else { float factor = 1 - (texturecoord.y * 2); color = vec4(1, 0, 0, 1) * factor + vec4(0, 0, 1, 1) * (1 - factor); } }
Comments
Post a Comment