Create a plane mesh, with points defining colors

南楼画角 提交于 2019-12-06 08:47:17

I have solved it ^^

Much smoother, faster and easier!

Main issue with my algorithm was the distance was in 'millimeter' when it should have been in 'm'.

dist = dist / (T * T * T);

Check it out here:

http://jsfiddle.net/zDh4y/13/

JAre

Edit: Now it's pretty and on WebGL http://glsl.heroku.com/e#16831.0 (Thanks to the gman)

It blends point color to the base color of the quad based on the distance between the point and the current fragment.

uniform vec2 pointA;
uniform vec2 pointB;
uniform vec2 pointC;
uniform vec4 pointColor;
uniform vec4 baseColor;
varying vec2 texCoord;

float  blendF(float val){
   return pow(val, 1.2) * 5;
}

vec4 addPoint(vec4  base, vec2 pointTexCord, vec4 pointColor){
   return mix(pointColor, base, blendF(distance(pointTexCord, texCoord)));
}

void main(void)
{ 
    vec4 accumulator = addPoint(baseColor, pointA, pointColor);
    accumulator = addPoint(accumulator, pointB, pointColor);
    accumulator = addPoint(accumulator, pointC, pointColor);     
    gl_FragColor = accumulator;
}

It would work with any kind of geometry and be as fast as it gets.

Here's Rendermonkey file with this shader You can tinker with it and don't worry about OpenGL\WebGL stuff - only shaders.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!