Sign in to follow this  

GLSL - very strange behavior

This topic is 4305 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_FrontColor=gl_Color;
        gl_TexCoord[0] = gl_Vertex;

//THIS IS THE LINE THAT FUCKS EVERYTHING UP
	Origin=(gl_ModelViewProjectionMatrix*WorldOrigin);
}



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];
	factor[0]=20.0;
	vec4 flare0color=vec4(1.0,1.0,1.0,1.0);

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

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

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


	vec4 d=vec4(
		length(gl_TexCoord[0].xy-flare0pos),
		length(gl_TexCoord[0].xy-flare1pos),
		length(gl_TexCoord[0].xy-flare2pos),
		length(gl_TexCoord[0].xy-flare3pos)
		);

	vec4 d2=d*factor;

	d2=min(vec4(1.0),1.0/(d2));

	float sum=d2[0]+d2[1]+d2[2]+d2[3];
	//d/=sum;
	d2*=0.9+(sin(d*20.0)+1.0)*0.05;

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

	gl_FragColor.a=sum;
}


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.

-kRogue

Share this post


Link to post
Share on other sites

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