Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I get the shaders to work
#18
(08-13-2015, 02:01 PM)CHmSID Wrote:
(08-13-2015, 11:53 AM)tomaszkax86 Wrote: I honestly don't know what you're expecting.
Special effects and such xD

When I was first getting into modern opengl I was disappointed how mundane the shaders are. I used to think it's all about post processing(night vision, static noise etc), now I know shaders are used for such boring things as positioning entities Tongue The occasional post-process effect is the cream at the top of the whole pipeline.

Colobot doesn't have any post-processing effects and for now doesn't need any. I added mipmapped texturing, anisotropic filtering, MSAA and dynamic shadows to the game and it feels rather heavy. Rendering needs to be optimized in the future.

Shaders are more than just boring positioning of entities. But it's unlikely you can find interesting examples on the Internet. People post rather mundane stuff. So here's something I was doing in OpenGL 3.3: stereoscopic rendering using geometry shaders and array textures. Rather than rendering entire world twice, you setup array textures to store 2 screens. Geometry shader duplicates geometry, one part uses left camera, other part uses right camera. Fragments are output to their own layers within array textures and that gives you 2 rendered scenes from two different cameras.

Code:
// VERTEX SHADER

#version 330

uniform mat4 uni_ModelMatrix;

layout(location = 0) in vec4 in_VertexCoord;
layout(location = 1) in vec4 in_Color;

out VertexData
{
    vec4 Color;
} data;

void main()
{
    gl_Position = uni_ModelMatrix * in_VertexCoord;
    
    data.Color = in_Color;
}


// GEOMETRY SHADER

#version 330

layout(triangles) in;
layout(triangle_strip, max_vertices = 6) out;

uniform mat4 uni_ProjectionMatrix;
uniform mat4 uni_LeftCameraMatrix;
uniform mat4 uni_RightCameraMatrix;

in VertexData
{
    vec4 Color;
} dataIn[];

out VertexData
{
    vec4 Color;
} dataOut;

void main()
{
    for(int i=0; i<3; i++)
    {
        gl_Position = uni_ProjectionMatrix * uni_LeftCameraMatrix * gl_in[i].gl_Position;
        gl_Layer = 0;
        dataOut.Color = dataIn[i].Color;
        
        EmitVertex();
    }
    
    EndPrimitive();
    
    for(int i=0; i<3; i++)
    {
        gl_Position = uni_ProjectionMatrix * uni_RightCameraMatrix * gl_in[i].gl_Position;
        gl_Layer = 1;
        dataOut.Color = dataIn[i].Color;
        
        EmitVertex();
    }
    
    EndPrimitive();
}


// FRAGMENT SHADER

#version 330

in VertexData
{
    vec4 Color;
} data;

out vec4 out_FragColor;

void main()
{
    out_FragColor = data.Color;
}

After that you can do whatever you want with the result. Below is the code that creates red-cyan anaglyph for use with simple 3D glasses.

Code:
// VERTEX SHADER

#version 330

layout(location = 0) in vec4 in_VertexCoord;
layout(location = 1) in vec2 in_TexCoord;

out VertexData
{
    vec2 TexCoord;
} data;

void main()
{
    gl_Position = in_VertexCoord;
    
    data.TexCoord = in_TexCoord;
}


// FRAGMENT SHADER

#version 330

uniform sampler2DArray uni_Texture;

const vec4 const_Red = vec4(1.0f, 0.0f, 0.0f, 1.0f);
const vec4 const_Cyan = vec4(0.0f, 1.0f, 1.0f, 1.0f);

in VertexData
{
    vec2 TexCoord;
} data;

out vec4 out_FragColor;

void main()
{
    out_FragColor = const_Red * texture(uni_Texture, vec3(data.TexCoord, 0.0f))
            + const_Cyan * texture(uni_Texture, vec3(data.TexCoord, 1.0f));
}

This can be easily combined with deferred rendering and make it even better.

PS. We can implement red-cyan anaglyph rendering in Colobot. It doesn't require too much work, although it wouldn't be as optimized as in my example.
"After three days without programming, life becomes meaningless."
~The Tao of Programming


Messages In This Thread
RE: How do I get the shaders to work - by krzys_h - 06-29-2015, 07:00 AM
RE: How do I get the shaders to work - by CHmSID - 08-13-2015, 02:01 PM
RE: How do I get the shaders to work - by tomaszkax86 - 08-13-2015, 05:05 PM
RE: How do I get the shaders to work - by CHmSID - 08-13-2015, 07:49 PM
RE: How do I get the shaders to work - by krzys_h - 08-13-2015, 08:39 PM
RE: How do I get the shaders to work - by krzys_h - 08-13-2015, 10:07 PM
RE: How do I get the shaders to work - by krzys_h - 08-14-2015, 10:18 AM

Forum Jump:


Users browsing this thread: 8 Guest(s)