home home

downloads files

forum forum

docs docs

wiki wiki

faq faq

Cube & Cube 2 FORUM


glsl (fullscreen)shaders

by dvsdata on 05/03/2009 11:39, 8 messages, last message: 05/10/2009 15:11, 1748 views, last view: 05/02/2024 04:01

Hi All. I've been trying adding a full-screen glsl shader to suerbraten. I see it being compiled but I see no effect when I enable it with setfullscreenshader. I've also tried to use glsltest. I've modified its code but could see no difference on screen when I use it. Question: is glsl supported beyond compilation?

here is an example of a shader I wrote :)

shader 5 my_shader [
void main(void)
{
gl_Position = ftransform();
}

] [
void main(void)
{
gl_FragColor = vec4(gl_Color.r, gl_Color.b, 1.0, 1.0);
}
]

   Board Index   

#1: ..

by baby~rabbit on 05/04/2009 07:14

You may need to look at the C code that calls the shaders to see how to set things up. The following example fullscreen glsl shader swizzles the color at each pixel

shader 4 my_shader [
void main(void) {
gl_Position = gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0;
}
] [
uniform sampler2DRect tex0;
void main(void)
{
vec4 color = texture2DRect(tex0, gl_TexCoord[0].st);
gl_FragColor = vec4(color.b, color.r, color.g, 1.0);
}
]

reply to this message

#2: ..

by dvsdata on 05/04/2009 20:13

Thank you for answering BR, I think I overlooked the use of textures in GLSL. I'll re-start from your example. Cheers

reply to this message

#3: ..

by dvsdata on 05/06/2009 00:00

Hi Sauer-Folks, me again with fullscreen-shader question.

Well, from what I understand, with the default functionality, the vertices passed-on to the vertex shader undergo the projection and model-view transformation after which their coordinates are expressed in the eye/camera frame of reference.

void main()
{
gl_Position = ftransform();
}

After this step one can assume that the camera is in (0,0,0) and looks down the negative z axis.

Is this also true for Sauer? In Baby-Rabbit example the incoming vertices are not trasformed and this confuses me. It's like vertices have been already transformed into the correct frame by the time the vertex program is executed.

Here is my code:

//Rudimental torch light effect.
//Light source located at the camera position pointing along z
shader 4 torch [
varying vec4 posizione; //vertex position in eye-coords
varying float distanza; //distance between eye (origin) and vertex

void main ( void )
{
gl_TexCoord[ 0 ] = gl_MultiTexCoord0;

//??? whatever I do here the shader doesn't work
//gl_Position = ftransform ( );
gl_Position = gl_Vertex;

//??? whatever I do here the shader doesn't work
//posizione = normalize ( gl_ModelViewMatrix * gl_Vertex );
posizione = normalize ( gl_Vertex );

distanza = length ( posizione );
}
] [
uniform sampler2DRect tex0;

varying vec4 posizione; //vertex position in eye-coords
varying float distanza; //distance between eye (origin) and vertex

//torch full-light
const vec3 luce = vec3 ( 0.7, 0.8, 0.9 );

//some params that change light distribution
const float esponente1 = 21.0;
const float esponente2 = 5.0;

void main ( void )
{
//fraction of torch light to be added to the texture color
float illuminazione =
pow ( -posizione.z, esponente1 ) *
pow ( distanza , esponente2 );

vec4 tassello = texture2DRect ( tex0, gl_TexCoord[ 0 ].st );

//output orig texture color plus light add-on
gl_FragColor = vec4 ( tassello.rgb + luce * illuminazione, 1.0 );
}
]

Well the shader doesn't work in Sauer (it does in Shader Designer) seemingly because of wrong coordinates of vertices. Any idea of what I'm missing/mis-understanding?

reply to this message

#4: ..

by baby~rabbit on 05/06/2009 01:18

It's a FULLSCREEN shader, this means it is applied by drawing a single quad covering the fullscreen. So the vertex is the screen pos in 2d, there is no eyecoord, etc.

If you want to add lighting based on postion, eye, normals, etc then you need to affect the shaders applied when drawing models and map geometry...

reply to this message

#5: ..

by dvsdata on 05/06/2009 19:12

There we go again... Thank you BR, I understand better now.

I had a look to the CPP code and found the function that does the rendering of the fullscreen shader. I see that the longest side between the quad's width and height is normalised to 1. I suppose I can still write a shader that fakes the torch-light circular beam in the middle of the screen. I cannot perform light attenuation along z, though. I'll give it a try, but it'll suck for sure...

But what if I wanted to go the long way and write a model/map shader, stacked on top of the canonical ones, that implements the torch-light effect and applies to every texture of the scene and to all models as well? Is that something that sauer allows? Would that be feasible by only playing with shaders or would I need to change the CPP side?

mumbling

reply to this message

#6: Re: ..

by baby~rabbit on 05/07/2009 03:36, refers to #5

You currently can't stack shaders used for models & geometry, so you'll simply have to rewrite/replace them with your own version that implements different lighting. The existing "glsltest" shader should give you an idea of how things are set up for glsl, though it may be easier to learn and extend the exiting assembler versions.

reply to this message

#7: Fullscreen Shaders

by Goober on 05/10/2009 14:53

What is the command in trooper edition for fullscreen shaders? It's not /setfullscreenshader anymore.

reply to this message

#8: Re: Fullscreen Shaders

by eihrul on 05/10/2009 15:11, refers to #7

showgui postfx

reply to this message

   Board Index   


Unvalidated accounts can only reply to the 'Permanent Threads' section!


content by Aardappel & eihrul © 2001-2024
website by SleepwalkR © 2001-2024
53867124 visitors requested 71642282 pages
page created in 0.041 seconds using 10 queries
hosted by Boost Digital