Hello!
I am trying to get my engine running on ATI/AMD(previously i only ran it on NVIDIA).
My shader uses diffuse lighting to render a sphere and a plane(both with same material).
This works totally fine on NVIDIA graphics cards.
On ATI it compiles, but shows really weird results when executed.
The sphere appears to have some issue with fetching texture and the plane does not appear at all.
I also tried compiling it with AMDs Shader Analyzer and it did compile without errors or warnings.
Here is the vertex shader:
uniform mat4 gWVP;
uniform mat4 gNormalMatrix;
uniform mat4 gModelViewMatrix;
in vec3 inPosition;
in vec3 inNormal;
in vec2 inTexcoord;
in vec3 inTangent;
out vec2 vTexcoord;
//all of these are in eyespace
out vec3 vPosition;
out vec3 vNormal;
out vec3 vTangent;
void main()
{
gl_Position = gWVP * vec4(inPosition,1.0);
vNormal = normalize((gNormalMatrix * vec4(inNormal,0.0)).xyz);
vTangent = normalize((gNormalMatrix * vec4(inTangent,0.0)).xyz);
vPosition = (gModelViewMatrix * vec4(inPosition,1.0)).xyz;
vTexcoord = inTexcoord;
}
and fragment shader:
#version 130
const int LIGHT_TYPE_NONE = 0;
const int LIGHT_TYPE_DIRECTIONAL = 1;
const int LIGHT_TYPE_POINT = 2;
struct Light{
int lightType;
vec3 position;
vec4 diffuse;
float intensity;
float constantAttenuation;
float linearAttenuation;
float quadraticAttenuation;
};
const int NUM_LIGHTS = 4;
uniform Light gLights[NUM_LIGHTS];
uniform vec4 gGlobalAmbient;
vec4 calculateDiffuse(Light light, vec4 surfaceColor, vec3 normal, vec3 lightDir)
{
vec4 outColor = vec4(0.0);
vec3 normalizedLightDir = normalize(lightDir);
float NdotL = max(dot(normal,normalizedLightDir),0.0);
if(light.lightType == LIGHT_TYPE_DIRECTIONAL)
{
if (NdotL > 0.0) {
outColor += surfaceColor * light.diffuse * light.intensity * NdotL;
}
}else if(light.lightType == LIGHT_TYPE_POINT)
{
float dist = length(lightDir);
if (NdotL > 0.0) {
float attenuation = 1.0 / (light.constantAttenuation +
light.linearAttenuation * dist +
light.quadraticAttenuation * dist * dist);
outColor += surfaceColor * light.diffuse * light.intensity * attenuation * NdotL;
}
}
return outColor;
}
uniform sampler2D gMainTexture;
in vec2 vTexcoord;
in vec3 vPosition;
in vec3 vNormal;
in vec3 vTangent;
out vec4 outColor;
void main (void)
{
vec4 texDiffuse = texture(gMainTexture,vTexcoord);
vec3 normal = normalize(vNormal);
vec3 tangent = normalize(vTangent);
vec3 bitangent = cross(normal, tangent);
mat3 tangentSpaceMatrix = mat3(
tangent.x, bitangent.x, normal.x,
tangent.y, bitangent.y, normal.y,
tangent.z, bitangent.z, normal.z
);
//ambient
outColor = texDiffuse * gGlobalAmbient;
for(int i = 0;i<NUM_LIGHTS;i++)
{
vec3 lightDir = vec3(0.0);
if(gLights[i].lightType == LIGHT_TYPE_DIRECTIONAL)
{
lightDir = normalize(tangentSpaceMatrix * gLights[i].position);
}else if(gLights[i].lightType == LIGHT_TYPE_POINT)
{
lightDir = tangentSpaceMatrix * (gLights[i].position - vPosition);
}
if(gLights[i].lightType != LIGHT_TYPE_NONE)
{
outColor += calculateDiffuse(gLights[i],texDiffuse,vec3(0.0,0.0,1.0),lightDir);
}
}
}
I hope someone can point out the issue to me or help me find a solution to debug it(since its no compiler error).
Thanks in advance!