Pages: 1
  Print  
Author Topic: Example Shaders  (Read 1941 times)
Offline (Male) Goombert
Posted on: August 28, 2013, 05:36:08 AM

Developer
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 3108

View Profile
This topic is a collection of various shaders that can be used in your game. You are free to use them and can also post your own in this topic.

Cartoon Shader


Language: GLSL

Vertex Shader
Code: (glSlang) [Select]
varying vec3 normal;

void main()
{
        normal = gl_NormalMatrix * gl_Normal;
        gl_Position = ftransform();
}

Fragment Shader
Code: (glSlang) [Select]
varying vec3 normal;

void main()
{
        float intensity;
        vec4 color;
        vec3 n = normalize(normal);
        intensity = dot(vec3(gl_LightSource[0].position),n);

        if (intensity > 0.95)
                color = vec4(1.0,0.5,0.5,1.0);
        else if (intensity > 0.5)
                color = vec4(0.6,0.3,0.3,1.0);
        else if (intensity > 0.25)
                color = vec4(0.4,0.2,0.2,1.0);
        else
                color = vec4(0.2,0.1,0.1,1.0);
        gl_FragColor = color;
}

Perpixel


Language: GLSL

Vertex Shader
Code: (glSlang) [Select]
void main()
{
        vec3 normal, lightDir;
        vec4 diffuse, ambient, globalAmbient;
        float NdotL;
               
        normal = normalize(gl_NormalMatrix * gl_Normal);
        lightDir = normalize(vec3(gl_LightSource[0].position));
        NdotL = max(dot(normal, lightDir), 0.0);
        diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse;
               
        /* Compute the ambient and globalAmbient terms */
        ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient;
        globalAmbient = gl_LightModel.ambient * gl_FrontMaterial.ambient;
               
        gl_FrontColor =  NdotL * diffuse + globalAmbient + ambient;
               
        gl_Position = ftransform();
}

Fragment Shader
Code: (glSlang) [Select]
void main()
{
        gl_FragColor = gl_Color;
}
Logged
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.

Offline (Male) time-killer-games
Reply #1 Posted on: August 28, 2013, 04:14:45 PM

Contributor
Location: Virginia Beach
Joined: Jan 2013
Posts: 1164

View Profile Email
What does the per pixel shader do? I won't have access to my PC for testing for a while so I'm asking this for my convenience. :-)
Logged
Offline (Male) Goombert
Reply #2 Posted on: September 02, 2013, 02:21:18 AM

Developer
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 3108

View Profile
The per pixel one is just a basic regular per pixel black and white shader, just meant to be the most basic.
Logged
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.

Pages: 1
  Print