View Full Version : GLSL shaders
smite-meister
March 11th, 2007, 02:08 PM
I was toying with the OpenGL renderer code a while ago, and added in crude support for GLSL shaders. They require OpenGL version 2.0 to work. Here is a screenshot of a fairly unimaginative fragment shader (http://users.tkk.fi/~vberghol/doom/Legacy_shaders.jpeg) that does some animated sine deformations, multitexturing and alpha effects on the walls and floors.
(The shader test is enabled by compiling video/hardware/oglrenderer.cpp with -DTEST_SHADERS)
Now I'd like to know how the shader - game engine interface is realized in modern games. What kinds of game data can you access from within the shader code? How do you define which shader(s) are applied to which polys? How do you do multiple shader passes?
For example, the OGRE method for defining surface rendering properties (http://www.ogre3d.org/docs/manual/manual_14.html#SEC23) sure is cool, but maybe a bit overkill.
Rellik_jmd
March 11th, 2007, 06:17 PM
That looks damn cool! I wonder how long it'll be before the engine is so modified and there are so many original new assets that it becomes it's own game completely free of copyright worries....
Osiris's_Legacy
March 12th, 2007, 04:55 AM
Whoa, that looks wild and sooo cool!!
MR_ROCKET
March 12th, 2007, 05:02 PM
Hehe yeah that's neat, definitely different :)
I donno if it's the same setup as say quake3 or wolf et, but the map author fixes up an external script to apply the effect and packs it into a scripts directory.
smite-meister
March 13th, 2007, 04:16 AM
This is what a GLSL fragment shader could look like (shaders are small programs run on the GPU):
uniform sampler2D tex0;
uniform float T;
void main()
{
vec4 texel;
vec2 tc;
tc.s = gl_TexCoord[0].s + 0.1*sin(T + gl_TexCoord[0].t);
tc.t = gl_TexCoord[0].t + 0.1*(1 - cos(T + gl_TexCoord[0].s));
texel = texture2D(tex0, tc);
gl_FragColor = vec4(texel.rgb, texel.a*abs(sin(T)));
}
The map author would write a program like this (or pick one from a library of shaders written by someone else) and somehow attach it to a surface or texture.
The shader code needs to access some external data from the renderer to do meaningful things. Some of this is provided by GLSL directly, such as texture coordinates, lights, vertex colors etc. Other external data has to be supplied by the main application (in this example the texture tex0 and the time counter T).
These "uniform" and "attribute" variables define the engine - shader interface I was referring to in the OP.
I was hoping someone could point me to an editing guide explaining how this interface is realized in other modern games, so that I could steal some ideas for Legacy.
BTW, the way GLSL shaders work is explained here (http://www.lighthouse3d.com/opengl/glsl/index.php?oglvariables) in case you're interested.
MR_ROCKET
March 13th, 2007, 04:11 PM
Holy snap, this stuff looks more advanced than what q3 or wolfet would have to offer.
I can't wait to check this stuff out, neat ! :)
In some ways the same deal, and I'll have to look into it more, in q3 for example though, you would add the texture name and location into the script so the engine would know where and what to apply the effect to.
xbolt
March 13th, 2007, 09:40 PM
That there, is some cool looking stuff!
g6672D
March 18th, 2007, 06:36 PM
Goodbye jDoom. Goodbye ZDoom. :D
Erpster
April 9th, 2007, 08:44 PM
Is my old ATI X700 256mb video card with shaders 2.0 going to render this OK, or will I need to get a new card with shaders 3.0? Don't play too many other games so I don't really want to but I will for this.
Aliotroph?
April 9th, 2007, 09:21 PM
Well, considering that Supreme Commander and Oblivion only need Shader 2.0 cards I'm thinking you'll be ok. :p
DaniJ
April 9th, 2007, 09:40 PM
Goodbye jDoom. Goodbye ZDoom. :D
Do you honestly think we're going to sit idly by while Legacy 2.0 takes the graphics crown in the realm of DOOM sourceports?
All joking aside. I wish you (the Legacy guys) the greatest of luck with this, I know how difficult a task you have ahead of you in order to fully integrate this stuff into your render pipeline whilst making them user-definable. Besides, we'll be able to use your code for reference when we do this in Doomsday :)
MR_ROCKET:
Quake3's "shaders" are not the same as whats being discussed here (GLSL). In Quake3, a "shader" is a strictly texture only language for compositing (sometimes procedural) textures and rendered utilizing multitexturing.
xbolt
April 9th, 2007, 10:11 PM
The Battle of the Source Ports shall soon begin... *dark*
[/dramaticness]
smite-meister
April 10th, 2007, 12:17 AM
I wish you (the Legacy guys) the greatest of luck with this, I know how difficult a task you have ahead of you in order to fully integrate this stuff into your render pipeline whilst making them user-definable. Besides, we'll be able to use your code for reference when we do this in Doomsday :)
I was thinking of borrowing the definition syntax from OGRE (see the link in the OP), but forgo the technique and pass layers (for now at least). The smart thing to do would most likely be to simply use OGRE as our renderer, but there's a kind of strange pleasure in writing your own.
With Doomsday, at least, you won't be having the trouble of dragging the software renderer along :)
smite-meister
April 10th, 2007, 12:28 AM
Is my old ATI X700 256mb video card with shaders 2.0 going to render this OK, or will I need to get a new card with shaders 3.0? Don't play too many other games so I don't really want to but I will for this.
Depends on the features the particular shader is using, but in principle you only require OpenGL 2.0 compatible video card. See here:
http://en.wikipedia.org/wiki/Comparison_of_NVIDIA_Graphics_Processing_Units
http://en.wikipedia.org/wiki/Comparison_of_ATI_Graphics_Processing_Units
DaniJ
April 10th, 2007, 03:19 AM
The smart thing to do would most likely be to simply use OGRE as our renderer, but there's a kind of strange pleasure in writing your own.Exactly, that IS the fun part after all :)
With Doomsday, at least, you won't be having the trouble of dragging the software renderer along I don't envy you having to get it working in software too. It would be an interesting challenge though.
smite-meister
April 10th, 2007, 07:14 AM
I don't envy you having to get it working in software too. It would be an interesting challenge though.
Not really. I'll just make the software renderer use the first texture unit for each surface/material as a traditional texture and completely ignore any possible shaders/multitexturing/other effects except for scaling, colormapping and simple transparency.
MR_ROCKET
April 13th, 2007, 11:41 PM
Dani J666, the relation "in some ways" the same deal does not mean it's the same thing heh.
Don't attack me just because g6672D pissed you off lol :D
Shader scripts from q3 and et are the only shader scripts I could relate with Smites question up top. Truthfully the shaders from q3, et and d3's mtr's are the only I'v known of until this. Even though being a different type. ;)
Thanks for the texture>script terminology heh, I know about that. What I don't know about is this new type of shader system, well new to me anyways ;)
DaniJ
April 14th, 2007, 05:18 AM
Not really. I'll just make the software renderer use the first texture unit for each surface/material as a traditional texture and completely ignore any possible shaders/multitexturing/other effects except for scaling, colormapping and simple transparency.Ah ok, I thought you meant you were planning on replicating the pipeline completely in software.
Dani J666, the relation "in some ways" the same deal does not mean it's the same thing heh.
Don't attack me just because g6672D pissed you off lol That was an attack? I was pissed off? Honestly, no. I was merely pointing out the common misconception that Q3 "shaders" == GLSL when in fact they are different technologies.
MR_ROCKET
April 14th, 2007, 03:12 PM
Ok good, I will cancle the wet stick beatings asap.
The Undertaker
April 15th, 2007, 05:12 AM
No beat Smite instead. If he used the proper term fragment program instead this whole mess could have been avoided. Unless he's secretly writing a D3D 10 renderer to get us to switch to Vista and let the word shader slip by mistake then order 2 beatings.
Graf_Zahl
April 15th, 2007, 10:20 AM
Umm, before you act like a smartass you should do some research yourself!
It is called GL shading language - and the code it executes are actually called shaders.
Fragment programs is for the old assembly language to do the same thing.
Rellik_jmd
April 15th, 2007, 11:14 AM
there's a kind of strange pleasure in writing your own.
And by strange you mean perverse, right?
As in I get a strange pleasure out of being spanked with a splintery broom handle...
I know how you programmers think. Sickos. :)
smite-meister
April 15th, 2007, 03:27 PM
And by strange you mean perverse, right?
Well, yes. But really, there's no need to weird it up. Writing a renderer is not that different from being suspended from one's ankles while being whipped with poison ivy, and I don't think there's anyone here who hasn't done that at least once, right? Right?
It is called GL shading language - and the code it executes are actually called shaders.
Almost accurate :)
Quoting from the GLSL 1.20 specs:
2.2 Fragment Processor
The fragment processor is a programmable unit that operates on fragment values and their associated
data. Compilation units written in the OpenGL Shading Language to run on this processor are called
fragment shaders. When a complete set of fragment shaders are compiled and linked, they result in a
fragment shader executable that runs on the fragment processor.
smite-meister
April 28th, 2007, 03:35 PM
Another shader screenshot (http://users.tkk.fi/~vberghol/doom/Legacy_shaders2.jpeg), with true multitexturing (now we have both a ducky and a toucan).
This is what the definition file looks like (the shader I used just does some animated texture deformations and adds them together):
shader myshader
{
vertex_source "vertex_shader.glsl";
fragment_source "frag_shader.glsl";
}
material BROWN1
{
texture_unit
{
texture "toucan.png";
scale 0.2;
}
texture_unit
{
texture "ducky.jpeg";
scale 0.25;
}
shader_ref myshader;
}
Next step, steep parallax mapping... :D
Rellik_jmd
May 5th, 2007, 03:46 PM
Looking good! It's really nice coming back every week and seeing some new stuff!
Aliotroph?
May 5th, 2007, 09:32 PM
LOL I was just thinking Oblivion needs some steep parallax mapping. :D
vBulletin® v3.8.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.