Jump to content

  • Log In with Google      Sign In   
  • Create Account

hellishdude

Member Since 04 Nov 2012
Offline Last Active Private

Posts I've Made

In Topic: Multiple Render Target shader question.

05 November 2012 - 06:44 AM

Max that makes sense! Thank you very much for sticking with me m8. Really appriciate the explanation.

In Topic: Multiple Render Target shader question.

05 November 2012 - 06:09 AM

I think I got it.

Vertex Shader:

#version 410 core
uniform mat4 MVP;
uniform mat4 WV;
in vec3 VertexPosition;
in vec2 VertexTexCoord;
in vec3 VertexNormal;
out vec3 WorldPos;
out vec2 TexCoord;
out vec3 Normal;

void main()
{
    gl_Position = MVP * vec4(VertexPosition, 1.0);
    TexCoord = VertexTexCoord;
    Normal = (WV * vec4(VertexNormal,0.0)).xyz;
    WorldPos = (WV * vec4(VertexPosition, 1.0)).xyz;
}


Fragment Shader:

#version 410 core
in vec3 WorldPos;
in vec2 TexCoord;
in vec3 Normal;
out vec3 FragWorldPos;
out vec3 Diffuse;
out vec3 FragmentNormal;
out vec3 FragTexCoord;
uniform sampler2D gColorMap;
void main (void)
{
    FragWorldPos = WorldPos;
    Diffuse = texture2D(gColorMap, TexCoord).xyz;
    FragmentNormal = normalize(Normal);
    FragTexCoord = vec3(TexCoord, 0.0);
}

Although I don't get any output yet (something is going on in the context probably) the shaders compile and link without compile errors.

In Topic: Multiple Render Target shader question.

05 November 2012 - 04:33 AM

Just reread (to be sure) and haven't seen such statement. Besides, it has always worked for me ;)


http://www.opengl.org/wiki/GLSL_Interface_Block

"Interface blocks can only be used to aggregate data interfaces between shaders. Vertex shaders cannot declare an input interface block, and fragment shaders cannot declare an output interface block.
If the input interface uses a block, then the corresponding output must also be a block that uses the same block name and members (though not necessarily the same instance name)."

yep, if I declare input block in the vertex shader I get a complile error:
OpenGL does not allow Input Blocks in vertex shaders.

Maybe in the end I need to declare each variable with in and out seperate...

In Topic: Multiple Render Target shader question.

04 November 2012 - 11:48 AM

As for your second question, you can declare interface blocks for output/input.
They work pretty much like structs, except you can define qualifiers on the passed variables.


Well now I'm a bit confused because I've read the glsl specification and it states that in/out block decleration can not pass from the vertex to the fragment shader. They only use it for the geometry shader.

From my understanding it should be something along this lines:

Vertex Shader:
#version 410 core
uniform mat4 MVP;
uniform mat4 WV;
struct VertexInput
{
    vec3 Position;
    vec2 TexCoord;
    vec3 Normal;
};
out VertexOutput
{
    vec3 WorldPos;
    vec2 TexCoord;
    vec3 Normal;
};
void main()
{
    gl_Position = MVP * vec4(VertexInput.Position,1.0);
    VertexOutput.TexCoord = VertexInput.TexCoord;
    VertexOutput.Normal = (WV*vec4(VertexInput.Normal,0,0)).xyz;
    VertexOutput.WorldPos = (WV * vec4(VertexInput.Position)).xyz;
}


Fragment Shader:
#Version 410 core

in VertexOutput
{
    vec3 WorldPos;
    vec3 Diffuse;
    vec3 Normal;
    vec2 TexCoord;
};
struct FSOutput
{
    vec3 WorldPos;
    vec3 Diffuse;
    vec3 Normal;
    vec3 TexCoord;
};
uniform sampler2D gColorMap;
void main (void)
{
    FSOutput.WorldPos = VertexOutput.WorldPos;
    FSOutput.Diffuse = texture2D(gColorMap, VertexOutput.TexCoord).xyz;
    FSOutput.Normal = normalize(VertexOutput.Normal);
    FSOutput.TexCoord = vec3 (VertexOutput.TexCoord, 0.0);
}

what do I do wrong?

PARTNERS