Jump to content
  • Advertisement
Sign in to follow this  

GLSL - very strange behavior

This topic is 4611 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

ok, i have a shader that renders a lensflare, but it doesnt work as i want it. the thing is: when i dont assign to a variable, that isnt used anywhere, it works, but when i do a calculation, that doesnt affect anything, i get wierd results. heres the vertex shader:
varying vec4 Origin;
uniform float Time;

void main()
	vec4 WorldOrigin=vec4(1.5,1.0,0.0,1.0);
	gl_Position = gl_Vertex;
        gl_TexCoord[0] = gl_Vertex;


fragment shader:

varying vec4 Origin;

uniform float Time;
uniform vec2 Position2D;

void main()
const vec2 Center=vec2(0.0,0.0);
const vec4 Positions=vec4(0.0,0.55,1.30,2.0);

	vec2 o=Position2D;
	//vec2 o=Origin.xy;
	//vec2 o=vec2(1.0,1.0);

	vec2 Direction=Center-o;
	//vec2 OrthoDirection=vec2(Direction.y,-Direction.x);
	vec4 factor;

	vec2 flare0pos=o+Direction*Positions[0];
	vec4 flare0color=vec4(1.0,1.0,1.0,1.0);

	vec2 flare1pos=o+Direction*Positions[1];
	vec4 flare1color=vec4(0.6,0.6,0.2,1.0);

	vec2 flare2pos=o+Direction*Positions[2];
	vec4 flare2color=vec4(0.5,0.5,0.0,1.0);

	vec2 flare3pos=o+Direction*Positions[3];
	vec4 flare3color=vec4(0.4,0.10,0.0,1.0);

	vec4 d=vec4(

	vec4 d2=d*factor;


	float sum=d2[0]+d2[1]+d2[2]+d2[3];

	gl_FragColor = d2[0]*flare0color+d2[1]*flare1color+d2[2]*flare2color+d2[3]*flare3color;


ok, the code is long, but it doesnt really matter. so whats going on? Origin is only used in this assignment. but the result depends on it! how can that be? commenting it out gives the right result, but i want that calculation to simplify the shader.

Share this post

Link to post
Share on other sites
im not 100% sure what u want
just treat the lensflare as a billboarded quad, in the program calculate the 4 corners of the quad and pass them in + use

gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; // or ftransform

to draw them

try searching for lensflare with opengl or something theres bound to be some tutorials (ive seen some in the past)

Share this post

Link to post
Share on other sites
My knee jerk reply is to ask "what card and what drivers?".... and then let others flame the dirvers... but seriously, are you absolutely sure you are using those source files in your calls to create the GLslang shaders? another thing, the driver may get confused if you want more varying inputs to the fragment shader than the card supports... in that case and if the driver is a touch buggy, then your assigment Origin=whatever may endup changing the values of another (used) varying parameter.


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!