Topic: Shaders question

Hello !

Into another net-wandering session i found an old program who almost dissappeared from the face of the net :
http://mew.cx/glsl/shadergen/ShaderGen.jpg
Its main use was to generate vert and frag shaders easly, it does the job but for some reason when i try to use
them in maratis, the object is just invisible (standard renderer) or unaffected at all (fixed renderer)

From the same devs, another program named "GLSL demo" :
PunBB bbcode testPunBB bbcode test

There's alot of shaders in it, below, a glass shader and a toon-like shader, but its the same problem than ShaderGen,
object is invisble.

Here's the link of the "site" (The official site is dead and the compagny too, its a backup site maintained by someone)
http://mew.cx/glsl/

And a sample of the shaders from GLSL demo program :
vert shader : http://dl.dropbox.com/u/19970067/Questions/Glass.vert
frag shader : http://dl.dropbox.com/u/19970067/Questions/Glass.frag

and a copy of the license, just in case : http://dl.dropbox.com/u/19970067/Questi … icense.txt

Theres some amazing shaders in this, that would be awesome if they works in maratis,
but i dont know if its possible to adapt them ?

Last edited by Vegas (2011-09-24 02:39:21)

Re: Shaders question

Hi, it looks interesting,
the software generate glsl shaders, so it's possible to adapt them,
there is just some difference that make them incompatible as-it :

The difference is mainly the use of the data (vertex, normal, uv...) and the matrices.

This software use fixed functions that are now deprecated and that Maratis doesn't use to be sure that the shaders will be compatible with openglES and future versions of openGL. I should make a doc about it.

Mesh data :

attribute vec3 Vertex;
attribute vec3 Normal;
attribute vec3 Tangent;
attribute vec3 Color;

Matrices :

- "gl_ModelViewMatrix" is replaced by "ModelViewMatrix" (declared on top with "uniform mat4 ModelViewMatrix;")
- "gl_NormalMatrix" is replaced by "NormalMatrix" (declared on top with "uniform mat4 NormalMatrix;")
- "gl_ModelViewProjectionMatrix" is replaced by "ProjModelViewMatrix"
etc

exemple :

varying vec3  Normal;
varying vec3  EyeDir;
varying vec4  EyePos;
varying float LightIntensity;

uniform vec3  LightPos;

void main(void) 
{
    gl_Position    = ftransform();
    Normal         = normalize(gl_NormalMatrix * gl_Normal);
    vec4 pos       = gl_ModelViewMatrix * gl_Vertex;
    EyeDir         = pos.xyz;
    EyePos           = gl_ModelViewProjectionMatrix * gl_Vertex;
    LightIntensity = max(dot(normalize(LightPos - EyeDir), Normal), 0.0);
}

Will be :

varying vec3  Normal;
varying vec3  EyeDir;
varying vec4  EyePos;
varying float LightIntensity;

// Maratis Mesh data
attribute vec3 Vertex;
attribute vec3 Normal;

// Maratis standard matrices
uniform mat4 ModelViewMatrix;
uniform mat4 ProjModelViewMatrix;
uniform mat4 NormalMatrix;

// 4 nearest Maratis lights
uniform vec4 LightPosition[4];

void main(void) 
{
    gl_Position = ProjModelViewMatrix * vec4(Vertex, 1.0);
    Normal = normalize((NormalMatrix * vec4(Normal, 1.0)).xyz);
    vec4 pos = ModelViewMatrix * vec4(Vertex, 1.0);
    EyeDir = pos.xyz;
    EyePos = ProjModelViewMatrix * vec4(Vertex, 1.0);
    LightIntensity = max(dot(normalize(LightPosition[0] - EyeDir), Normal), 0.0);
}

Re: Shaders question

Great to know they can be used smile

About that doc, maybe i can find something on the net or its maratis-specific changes ?