Friday, April 5, 2013

GR Graphics GL - The first shaders


In its initial creation, the GrGraphicsGl used client memory to store per-vertex attributes and uniform buffers for the per-object attributes.

Using just the positions and the normals plugins, the first toy example (PerVertexLighting_vs.glsl + PerVertexLighting_ps.glsl) were created.



The first shaders created were

PerVertexLighting_vs.glsl + PerVertexLighting_ps : Using positions, normals, lights
Toy example for the first runs


PerVertexLighting_vs.glsl + PerVertexLighting_ps : Using positions, normals, lights, materials Trying out the materials model
Per - pixel diffuse (Lambert)

PerVertexLighting_vs.glsl + PerVertexLighting_ps : Using positions, normals, lights, materials
Per pixel diffuse (Screenshot 1)


I only post a screenshot for the three per-pixel models, as the differences are too slight.
PerPixelLighting_vs.glsl + PerPixelLighting_Phong_ps : Using positions, normals, lights, materials
Classic per pixel shader, Lambert diffuse + Phong specular

PerPixelLighting_vs.glsl + PerPixelLighting_BlinnPhong_ps : Using positions, normals, lights, materials
Slightly improved specular model of the same per pixel shader

Per pixel Lambert diffuse + Gaussian specular
PerPixelLighting_vs.glsl + PerPixelLighting_Gaussian_ps : Using positions, normals, lights, materials. Improved Here, the material struct had to be modified to add the Gaussian specular exponent, as I would need to use both in the same run if I wanted to showcase shader differences in the same run.


With the complete toy-examples out of the way, it was time for textures.





The shaders used are pretty basic. An example Vertex shader is


#version 330
//Make the uniforms have a well-defined structure and paddings
layout(std140) uniform;

layout(location = 0) in vec4 position;
layout(location = 1) in vec3 normal;

//I like prepending the space that each attribute is defined in
out vec3 eyeVertexPos;
out vec3 eyeVertexNormal;
out vec4 eyeLightPos;
out vec3 eyeSpotDir;

//Pragma include is a custom directive that I detect in the file-parsing phase
#pragma include lightuniform.glsl
#pragma include matricesuniform.glsl

void main()
{
    vec4 eyePosition4 = modelToEye*position;

    //Just classic transformations to move everything to view space
    //OUT
    eyeVertexPos = eyePosition4.xyz/eyePosition4.w;
    eyeVertexNormal = modelToEye_norm*normal;
    //TODO: This is just for prototyping, light should be transformed to view space outside the shader since it does not change per-object.
    eyeLightPos = worldToEye*light[0].position;
    eyeSpotDir = normalize(worldToEye_norm*light[0].direction);

    //SYSTEM
    gl_Position = eyeToClip*eyePosition4;
}

No comments:

Post a Comment