siddharth.cmdz

11-17-2014, 01:33 PM

hi all,

I'm trying to chain my fragment and vertex shaders. Its just a simple lighting shader. Below is the resulting chained vertex shader. When I try to get the location of the uniform "enableNormalColor", i get a -1. Should all the uniforms be at the top of the shader?

#version 440 compatibility

layout(location = 0) in vec4 vPosition;

layout(location = 1) in vec4 vColor;

layout(location = 2) in vec4 vNormal;

uniform mat4 mvp;

uniform mat4 mv;

uniform mat4 colorMat;

uniform mat4 normalMat;

vec4 getVertexColor() {

return vColor;

}

vec4 getVertexNormal() {

return vNormal;

}

vec4 getVertexPosition() {

return vPosition;

}

mat4 getMVPMatrix() {

return mvp;

}

mat4 getMVMatrix() {

return mv;

}

mat4 getMVITMatrix() {

return normalMat;

}

mat4 getColorMatrix() {

return colorMat;

}

uniform vec4 solidColor;

uniform int enableGradientColor = 0;

uniform int enableNormalColor = 0;

uniform int enableSolidColor = 0;

vec4 getSolidColor() {

return solidColor;

}

int getEnableGradientColor() {

return enableGradientColor;

}

int getEnableNormalColor() {

return enableNormalColor;

}

int getEnableSolidColor() {

return enableSolidColor;

}

vec4 getColor() {

vec4 color = vec4(1f, 0f, 0f, 1f);

if(enableGradientColor == 1) {

color = colorMat * getVertexPosition();

color.x = abs(color.x);

color.y = abs(color.y);

color.z = abs(color.z);

} else if(enableNormalColor == 1) {

mat4 scaleBias = mat4(0.5f, 0f, 0f, 0.5f,

0f, 0.5f, 0f, 0.5f,

0f, 0f, 0.5f, 0.5f,

0f, 0f, 0f, 1f);

color = normalize(scaleBias * getVertexNormal());

} else if(enableSolidColor == 1) {

color = solidColor;

} else {

color = vColor;

}

return color;

}

out vec4 normal;

out vec4 eye;

void main() {

gl_Position = getMVPMatrix()* getVertexPosition();

normal = normalize(getMVITMatrix() * getVertexNormal());

eye = -(getMVMatrix() * getVertexPosition());

}

thanks

I'm trying to chain my fragment and vertex shaders. Its just a simple lighting shader. Below is the resulting chained vertex shader. When I try to get the location of the uniform "enableNormalColor", i get a -1. Should all the uniforms be at the top of the shader?

#version 440 compatibility

layout(location = 0) in vec4 vPosition;

layout(location = 1) in vec4 vColor;

layout(location = 2) in vec4 vNormal;

uniform mat4 mvp;

uniform mat4 mv;

uniform mat4 colorMat;

uniform mat4 normalMat;

vec4 getVertexColor() {

return vColor;

}

vec4 getVertexNormal() {

return vNormal;

}

vec4 getVertexPosition() {

return vPosition;

}

mat4 getMVPMatrix() {

return mvp;

}

mat4 getMVMatrix() {

return mv;

}

mat4 getMVITMatrix() {

return normalMat;

}

mat4 getColorMatrix() {

return colorMat;

}

uniform vec4 solidColor;

uniform int enableGradientColor = 0;

uniform int enableNormalColor = 0;

uniform int enableSolidColor = 0;

vec4 getSolidColor() {

return solidColor;

}

int getEnableGradientColor() {

return enableGradientColor;

}

int getEnableNormalColor() {

return enableNormalColor;

}

int getEnableSolidColor() {

return enableSolidColor;

}

vec4 getColor() {

vec4 color = vec4(1f, 0f, 0f, 1f);

if(enableGradientColor == 1) {

color = colorMat * getVertexPosition();

color.x = abs(color.x);

color.y = abs(color.y);

color.z = abs(color.z);

} else if(enableNormalColor == 1) {

mat4 scaleBias = mat4(0.5f, 0f, 0f, 0.5f,

0f, 0.5f, 0f, 0.5f,

0f, 0f, 0.5f, 0.5f,

0f, 0f, 0f, 1f);

color = normalize(scaleBias * getVertexNormal());

} else if(enableSolidColor == 1) {

color = solidColor;

} else {

color = vColor;

}

return color;

}

out vec4 normal;

out vec4 eye;

void main() {

gl_Position = getMVPMatrix()* getVertexPosition();

normal = normalize(getMVITMatrix() * getVertexNormal());

eye = -(getMVMatrix() * getVertexPosition());

}

thanks