Posts Tagged ‘glsl’
Here is a GLSL code snippet to convert the exponential depth to a linear value:
float f=1000.0;
float n = 0.1;
float z = (2 * n) / (f + n - texture2D( texture0, texCoord ).x * (f - n));
where:
- f = camera far plane
- n = camera near plane
- texture0 = depth map.
The tutorial The Art of Texturing Using the OpenGL Shading Language has been included in OpenGL.org website in OpenGL API OpenGL Shading Language Sample Code & Tutorials section. Rather cool… ![]()

As I said in this news, the release of Catalyst 8.10 BETA comes with a nice bugfix: vertex texture fetching is now operational on Radeon (at least on my Radeon HD 4850). From 2 or 3 months, Catalyst makes it possible to fetch texture from inside a vertex shader. You can see with GPU Caps Viewer how many texture units are exposed in a vertex shader for your Radeon:

But so far, vertex texture fetching in GLSL didn’t work due to a bug in the driver. But now this is an old story, since VTF works well. For more details about vertex displacement mapping, you can read this rather old (2 years!) tutorial: Vertex Displacement Mapping using GLSL.
This very cool news makes me want to create a new benchmark based on VTF!

I’ve only tested the XP version of Catalyst 8.10. If someone has tested the Vista version, feel free to post a comment…
Next step for ATI driver team: enable geometry texture fetching: allows texture fetching inside a geometry shader…
See you soon!
During the conversion of shaders written in Cg/HLSL, we often find the saturate() function. This function is not valid in GLSL even though on NVIDIA, the GLSL compiler accepts it (do not forget that NVIDIA’s GLSL compiler is based on Cg compiler). But ATI’s GLSL compiler will reject saturate() with a nice error. This function allows to limit the value of a variable to the range [0.0 - 1.0]. In GLSL, there is a simple manner to do the same thing: clamp().
Cg code:
float3 result = saturate(texCol0.rgb - Density*(texCol1.rgb));
GLSL equivalent:
vec3 result = clamp(texCol0.rgb - Density*(texCol1.rgb), 0.0, 1.0);
BTW, don’t forget all float4, float3 and float2 which correct syntax in GLSL is vec4, vec3 and vec2.
Are you ready for a small velvet GLSL shader? Here’s one, at least a preview of the one I’ve just coded for a demo with Smode. Smode… a software dedicated to create… demos! And the cool thing, is that Smode demos will be also available for Demoniak3D. Don’t look for Smode, it’s not available for you, public… Only few people on this planet are enough lucky to play with. But if you really want to touch it, just drop me an email…

As soon as the next release of Demoniak3D, the 1.24.0 (or better the 1.30.0 because of the huge amount of changes), will be ok, I’ll put online the velvet demo with its nice GLSL shader. And if I’m late, don’t hesitate to post a small message to wake me up!
A user from oZone3D.Net forum asked me some info about the GLSL support of Intel graphics chips. It’s wellknown (sorry Intel) that Intel has a bad OpenGL support in its Windows drivers and even if Intel’s graphics drivers support OpenGL 1.5, there is still a lack of GLSL support. We can’t find the GL_ARB_shading_language_100 extension (this extension means the graphics driver supports the OpenGL shading language) and this extension should be supported by any OpenGL 1.5 compliant graphics driver. You can use GPU Caps Viewer to check for the avaibility of GL_ARB_shading_language_100 (in OpenGL Caps tab).
Here is an example of a Intel’s graphics driver that support openGL 1.5 without supporting GLSL:
- Mobile IntelR 965 Express Chipset Family
For more examples, look at users’s submissions here: www.ozone3d.net/gpu/db/
Okay this is my analysis, but what is the Intel point of view? Here is the answer:
- x3100 & OpenGL Shader (GLSL) thread
- Intel’s answer
I think GLSL support with Windows is not a priority for Intel…
Packing a [0-1] float value into a 4D vector where each component will be a 8-bits integer:
vec4 packFloatToVec4i(const float value)
{
const vec4 bitSh = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);
const vec4 bitMsk = vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);
vec4 res = fract(value * bitSh);
res -= res.xxyz * bitMsk;
return res;
}
Unpacking a [0-1] float value from a 4D vector where each component was a 8-bits integer:
float unpackFloatFromVec4i(const vec4 value)
{
const vec4 bitSh = vec4(1.0/(256.0*256.0*256.0), 1.0/(256.0*256.0), 1.0/256.0, 1.0);
return(dot(value, bitSh));
}
Source of these codes: Gamedev forums
Je viens de m’amuser un peu avec Lumina. C’est un petit environnement de mise au point de shader GLSL. Le projet demarre et il y a encore pas mal de petites coquilles (essayez de charger plusieurs projets les uns à la suite des autres ou plus simplement chargez le projet de test deferred3.lum: l’interface graphique aime moyennement!) qui trainent mais le concept est bon. En regardant de plus prêt, cela ressemble fortement à une interface graphique posé sur un soft comme Demoniak3D. Il y a des scripts (écrits dans un language basé sur ECMA)pour mettre en place les éléments de la scene 3d et les controler. Il y a aussi les scripts GLSL (vertex, pixel et geometry). Si on analyse un fichier de projet on découvre une structure similaire à une démo Demoniak3D: un script XML, des nodes <script>, <shader>, etc.
Maintenant que le tour du proprio est fait, voilà mon premier projet de test ultra simple: afficher un torus jaune qui tourne le tout utilisant un vertex et un pixel shader pour le rendu. J’ai pu coder ce projet rapidement avec une analyse rapide des fichiers de projets *.lum.
Le projet est téléchargeable ici: lumina_jegx_test_01.zip
Globalement c’est sympa mais l’interêt de l’interface graphique est discutable. Dans ce type de soft (Lumina ou Demoniak3D) soit l’interface graphique est de haut niveau et simple à utiliser soit vaut mieux s’en passer. Je vais quand même étudier plus en détail le fonctionnement de Lumina ne serait-ce que pour améliorer Demoniak3D et son successeur…
Dans le même esprit que lumina il y a aussi FX Composer (NVIDIA) et RenderMonkey (ATI).
While I was releasing the Julia’s Fractal demo, I tested it on NVIDIA and ATI (as usual before releasing a demo). And as usual, a new difference appeared in the way the GLSL is supported on ATI and on NVIDIA. On NVIDIA the following is line is ok but produces an error on ATI (Catalyst 8.1):
gl_FragColor = texture1D(tex, (float)(i == max_i ? 0 : i) / 100);
To be ATI Radeon-compliant, this instruction must be split in two:
if( i == max_i )
{
gl_FragColor = texture1D(tex, 0.0);
}
else
{
gl_FragColor = texture1D(tex, i/100.0);
}
I can’t immagine a world with more than two major graphics cards manufacturers. But if such a world exists, I stop 3d programming… Fortunately, NVIDIA accepts ATI GLSL syntax so there is only one code at the end. Conlusion: always check your GLSL shaders on ATI and NVIDIA before releasing a demo…
The previous catalyst (7.11 / 7.12) had a nasty bug in dynamic lights management in GLSL.
I’ve just tested the latest Catalyst 8.1 WHQL with the Demoniak3D demo I coded for, and the bug has been fixed. In the release notes, there is no trace of this bug and its correction. Anyway, now this bug is fixed and this is the important thing.
