Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: need some help with radial gradient and smoothstep  (Read 2150 times)

0 Members and 1 Guest are viewing this topic.

dydya-stepa

  • Jr. Member
  • **
  • Posts: 82
    • View Profile
need some help with radial gradient and smoothstep
« on: December 30, 2011, 06:21:51 pm »
I've written this shader to create a radial gradient (translated code from hlsl found on internet)

uniform sampler2D tex;

const vec2 center = vec2(0.5, 0.5);
const vec3 start = vec3(1.0, 0.0, 0.0);
const vec3 end = vec3(1.0, 1.0, 1.0);
const float radius = 1.0;

void main()
{
   float dist = clamp(distance(center, gl_TexCoord[0]) / radius, 0.0, 1.0);      
   gl_FragColor = vec4(mix(start, end, dist), 1.0);
}
1) The result shows me blue and black but i would like to have a red - white transition. If I change smoothstep() to mix() then it works but produces banding effect.

2) I would like to have a circle instead of an ellipse which is the case if screen width != screen height

any suggestions?