Jump to content

  • Log In with Google      Sign In   
  • Create Account


whysee

Member Since 07 Feb 2005
Offline Last Active Jul 07 2012 02:06 PM

Posts I've Made

In Topic: GLSL multiple spotlights

25 October 2005 - 09:14 AM

Quote:
Original post by eviltwigflipper
Quote:
Original post by whysee
but i want a do i by a GLSL shader
im a newbie in this scope

Theres like no advantages in doing it in a shader, your better off using glBlend, and it will probley be faster.


yes it's faster but my point is to do some per pixel shading. i have many spotlights casting their beam on flat surfaces like cubes, so per vertex don't fit


In Topic: GLSL multiple spotlights

25 October 2005 - 09:08 AM

ok
so here is the new frag
I control my light[0] parameters for each pass corresponding to each "real" light in my application


void main()
{
vec4 diffuse1,ambient1;

vec3 n,halfV;
float NdotL,NdotHV;
vec4 color = ambientGlobal;
vec4 color2= vec4(0.0,0.0,0.0,1.0);// = ambientGlobal;
float att,spotEffect;
float dist1 = length(lightDir1);

/* Compute the diffuse, ambient and globalAmbient terms */
diffuse1 = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse;
ambient1 = gl_FrontMaterial.ambient * gl_LightSource[0].ambient;
/* a fragment shader can't write a verying variable, hence we need
a new variable to store the normalized interpolated normal */

n = normalize(normal);

/* compute the dot product between normal and ldir */
NdotL = max(dot(n,normalize(lightDir1)),0.0);

if (NdotL > 0.0)
{

spotEffect = dot(normalize(gl_LightSource[0].spotDirection), normalize(-lightDir1));
if (spotEffect > gl_LightSource[0].spotCosCutoff) {
spotEffect = pow(spotEffect, gl_LightSource[0].spotExponent);
att = spotEffect / (gl_LightSource[0].constantAttenuation +
gl_LightSource[0].linearAttenuation * dist1 +
gl_LightSource[0].quadraticAttenuation * dist1 * dist1);

color += att * (diffuse1 * NdotL + ambient1);


halfV = normalize(halfVector1);
NdotHV = max(dot(n,halfV),0.0);
color += att * gl_FrontMaterial.specular * gl_LightSource[0].specular * pow(NdotHV,gl_FrontMaterial.shininess);
}
}
gl_FragColor = color;
}



in my app :
something like :


for nb lights
setGLLightPos(glLightNum, pos);
swapBuffer();




do you think it's a good way to do such a thing
BTW you said that conditonnals block are in concern for shader perf
do you have any pointer or more advices on the subject

do you think a sort of cubemap lighting can be more efficient. I lack of knowledge in this topic

In Topic: GLSL multiple spotlights

24 October 2005 - 11:17 AM

but i want a do i by a GLSL shader
im a newbie in this scope

so i don't know how to do a multi-light shader
here is what i begin
the problem is that is very ugly i just have duplicated the two process for the two spotlight
how could i do for any number of ligths


void main()
{
vec4 diffuse1,ambient1;
vec4 diffuse2,ambient2;

vec3 n,halfV;
float NdotL,NdotHV;
vec4 color = ambientGlobal;
vec4 color2= vec4(0.0,0.0,0.0,1.0);// = ambientGlobal;
float att,spotEffect;
float dist1 = length(lightDir1);
float dist2 = length(lightDir2);

/* Compute the diffuse, ambient and globalAmbient terms */
diffuse1 = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse;
ambient1 = gl_FrontMaterial.ambient * gl_LightSource[0].ambient;
diffuse2 = gl_FrontMaterial.diffuse * gl_LightSource[1].diffuse;
ambient2 = gl_FrontMaterial.ambient * gl_LightSource[1].ambient;
/* a fragment shader can't write a verying variable, hence we need
a new variable to store the normalized interpolated normal */

n = normalize(normal);

/* compute the dot product between normal and ldir */
NdotL = max(dot(n,normalize(lightDir1)),0.0);

if (NdotL > 0.0)
{

spotEffect = dot(normalize(gl_LightSource[0].spotDirection), normalize(-lightDir1));
if (spotEffect > gl_LightSource[0].spotCosCutoff) {
spotEffect = pow(spotEffect, gl_LightSource[0].spotExponent);
att = spotEffect / (gl_LightSource[0].constantAttenuation +
gl_LightSource[0].linearAttenuation * dist1 +
gl_LightSource[0].quadraticAttenuation * dist1 * dist1);

color += att * (diffuse1 * NdotL + ambient1);


halfV = normalize(halfVector1);
NdotHV = max(dot(n,halfV),0.0);
color += att * gl_FrontMaterial.specular * gl_LightSource[0].specular * pow(NdotHV,gl_FrontMaterial.shininess);
}
}
///*
NdotL = max(dot(n,normalize(lightDir2)),0.0);
if (NdotL > 0.0)
{

spotEffect = dot(normalize(gl_LightSource[1].spotDirection), normalize(-lightDir2));
if (spotEffect > gl_LightSource[1].spotCosCutoff) {
spotEffect = pow(spotEffect, gl_LightSource[1].spotExponent);
att = spotEffect / (gl_LightSource[1].constantAttenuation +
gl_LightSource[1].linearAttenuation * dist2 +
gl_LightSource[1].quadraticAttenuation * dist2 * dist2);

color2 += att * (diffuse2 * NdotL + ambient2);
halfV = normalize(halfVector2);
NdotHV = max(dot(n,halfV),0.0);
color2 += att * gl_FrontMaterial.specular * gl_LightSource[1].specular * pow(NdotHV,gl_FrontMaterial.shininess);
}
}
//*/

gl_FragColor = color2+ color;
}



my problem is also in term of performance
one more light decrease famerate a lot

please need help
or any pointers on multi light shader

In Topic: writing assembly vertex and fragment program

02 March 2005 - 05:29 AM

thanks for your answer

I'm wondering if something like Cg SDK or an other one working on linux can help writing vertex program, if someone has set up a good environment for that.
Or if there a way to write GLSL code to be converted in ARBvp/fp1.0

I have read some spec on ARBvp assembly so I think i could understand something but my was on a good tutorial on how to make complex shader, passing parameters adding projective texture blending and so on ..

I'm new to this post and maybe this question is an other topic for graphic theory ?

PARTNERS