Topic: Maratis shader syntax question?

Hi, im learning glsl. I want to create a water ripple on the plane, but in maratis it looks just white color. Can someboady tell me whats wrong with this code:

VERT shader
attribute vec3 Vertex;
//attribute vec3 Color;

uniform mat4 ProjModelViewMatrix;
 
void main()
{
    gl_Position    = ProjModelViewMatrix * vec4(Vertex, 1.0);
    gl_FrontColor  = gl_Color;
    gl_TexCoord[0] = gl_MultiTexCoord0;
}

FRAG shader

uniform float time;

uniform sampler2D Texture[8];

float radius = .5;

void main()
{
    float t = clamp(time / 6., 0., 1.);

    vec2 coords = gl_TexCoord[0].st;
    vec2 dir = coords - vec2(.5);
   
    float dist = distance(coords, vec2(.5));
    vec2 offset = dir * (sin(dist * 80. - time*15.) + .5) / 30.;

    vec2 texCoord = coords + offset;
    vec4 diffuse = texture2D(Texture[0], texCoord);

    //vec4 mixin = texture2D(Texture[1], texCoord);

    gl_FragColor = diffuse * (1. - t);
}

Re: Maratis shader syntax question?

Hi,
I will have a look at your shader and come back to you.
for now, please look at these shader examples : http://www.maratis3d.org/?p=548

Maratis doesn't use gl_Color, gl_MultiTexCoord0 or gl_TexCoord (they are deprecated)

here is a basic shader from the link above :

VERT:

attribute vec3 Vertex;
attribute vec2 TexCoord0;
uniform mat4 TextureMatrix[8];
uniform mat4 ProjModelViewMatrix;
varying vec2 texCoord[1];
                            
void main(void)
{
    gl_Position = ProjModelViewMatrix * vec4(Vertex, 1.0);
    texCoord[0] = (TextureMatrix[0] * vec4(TexCoord0, 1.0, 1.0)).xy;
}

FRAG:

uniform bool AlphaTest;
uniform float MaterialOpacity;
uniform sampler2D Texture[8];
varying vec2 texCoord[1];
void main(void)
{
    float w = texture2D(Texture[0], texCoord[0]).w;
    if(AlphaTest)
        if(w < 0.5) discard;
    gl_FragColor = vec4(1.0, 1.0, 1.0, w * MaterialOpacity);
}

Re: Maratis shader syntax question?

Hi anael. I'm totaly new to shaders. How else i can write this code?

    gl_FrontColor  = gl_Color;
    gl_TexCoord[0] = gl_MultiTexCoord0;

Another question would be, why shaders not working on fixed renderer?

Last edited by Skywriter (2014-07-16 19:16:22)

Re: Maratis shader syntax question?

the fixed renderer use the 3d card fixed pipeline, that was before the invention of shaders (mostly deprecated on desktop)
Wikipedia : https://en.wikipedia.org/wiki/Fixed-function

the standard renderer uses the 3d card shader pipeline.

Re: Maratis shader syntax question?

use this as a vert shader :

// engine default attributes and uniforms
attribute vec3 Vertex;
attribute vec3 Normal;
attribute vec3 Tangent;
attribute vec3 Color;

attribute vec2 TexCoord0;
attribute vec2 TexCoord1;
attribute vec2 TexCoord2;
attribute vec2 TexCoord3;

uniform mat4 TextureMatrix[4];
uniform mat4 ModelViewMatrix;
uniform mat4 ProjectionMatrix;
uniform mat4 NormalMatrix;
uniform mat4 ProjModelViewMatrix;

// custom varyings interpolated to the pixel shader
varying vec2 texCoord;
varying vec4 position, color;

// vert main
void main(void)
{
    position = ModelViewMatrix * vec4(Vertex, 1.0);
    texCoord = (TextureMatrix[0] * vec4(TexCoord0, 1.0, 1.0)).xy;
    color = vec4(Color, 1.0);

    gl_Position = ProjModelViewMatrix * vec4(Vertex, 1.0);
}

Re: Maratis shader syntax question?

Thanks anael. Code worked. Had to make small changes. Thats the code that worked:


VERT:

attribute vec3 Vertex;
attribute vec3 Normal;
attribute vec3 Tangent;
attribute vec3 color;

attribute vec2 TexCoord0;
attribute vec2 TexCoord1;
attribute vec2 TexCoord2;
attribute vec2 TexCoord3;

uniform mat4 TextureMatrix[4];
uniform mat4 ModelViewMatrix;
uniform mat4 ProjectionMatrix;
uniform mat4 NormalMatrix;
uniform mat4 ProjModelViewMatrix;

// custom varyings interpolated to the pixel shader
varying vec2 texCoord;
varying vec4 position, Color;

// vert main
void main(void)
{
    position = ModelViewMatrix * vec4(Vertex, 1.0);
    texCoord = (TextureMatrix[0] * vec4(TexCoord0, 1.0, 1.0)).xy;
    Color = vec4(color, 1.0);

    gl_Position = ProjModelViewMatrix * vec4(Vertex, 1.0);
}

FRAG:

uniform float time;
uniform sampler2D Texture[8];

float radius = .5;
varying vec2 texCoord;

void main()
{
    float t = clamp(time / 6., 0., 1.);

    vec2 coords = texCoord.st;
    vec2 dir = coords - vec2(.5);
   
    float dist = distance(coords, vec2(.5));
    vec2 offset = dir * (sin(dist * 80. - time*15.) + .5) / 30.;

    vec2 texCoord = coords + offset;
    vec4 diffuse = texture2D(Texture[0], texCoord);


    gl_FragColor = diffuse * (1. - t);
}