Sign in to follow this  

GLSL Blending Distance Function Error

This topic is 3107 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

//Vertex Shader: ////////////// varying vec3 normal; varying vec4 pos; uniform vec3 MyPoint[2]; uniform float activationSize; varying float dist; float distancefinder(vec3 Point[2]) { int i; //float tempDist = distance(Point,gl_Vertex); float tempDist; for (i=0;i<2;i++) { tempDist = distance(Point[i],gl_Vertex); tempDist /= 15; if (tempDist <= 1.0) { i=3; } } return (tempDist*activationSize); } void main() { normal = gl_NormalMatrix * gl_Normal; gl_Position = ftransform(); pos = gl_ModelViewMatrix * gl_Vertex; dist = distancefinder(MyPoint); //dist = distancefinder(MyPoint[0]); //dist = distance(MyPoint[1],gl_Vertex); //dist /= (45-(40)); // Change Value to Change Distance of Electrode // activationSize } ///////////// ///Fragment Shader /////////////// varying vec3 normal; varying vec4 pos; varying float dist; uniform float activation; uniform sampler1D texturecolors; void main() { vec4 color; bool flag = false; if (dist <= 1.0) { vec4 colormap = tex1D(texturecolors, 1-(dist)); // Distance from Vertex // dist*activation color[0] = colormap[0]; color[1] = colormap[1]; color[2] = colormap[2]; color[3] = 0.0; } else { color = gl_FrontMaterial.diffuse; } vec4 matspec = gl_FrontMaterial.specular; float shininess = gl_FrontMaterial.shininess; vec4 lightspec = gl_LightSource[0].specular; vec4 lpos = gl_LightSource[0].position; vec4 s = -normalize(pos-lpos); vec3 light = s.xyz; vec3 n = normalize(normal); vec3 r = -reflect(light, n); r = normalize(r); vec3 v = -pos.xyz; v = normalize(v); vec4 diffuse = color * max(0.0, dot(n, s.xyz)) * gl_LightSource[0].diffuse; vec4 specular; if (shininess != 0.0) { specular = lightspec * matspec * pow(max(0.0, dot(r, v)), shininess); } else { specular = vec4(0.250, 0.250, 0.250, 0.0); } gl_FragColor = diffuse + specular; } The Two shaders will produce two activation points given the input of MyPoint[2] is located on a model in XYZ Coordinates. For Some reason when I produce two of these using the distance function, the second activation is not drawn as smoothly. The edges of all polygons are shown. Does anyone know of a way to get around this? Or fixes in my code to try? Much appreciated

Share this post


Link to post
Share on other sites
Problem Partially Solved -

if (tempDist <= 1.0)

Changed to

if (tempDist <= 2.0)

and drawn correctly. The threshold here determines what can be drawn within radius. Now I am not 100% sure how to interact with it and/or how to solve now for collisions.

Any help would be apprecaited

Share this post


Link to post
Share on other sites

This topic is 3107 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this