I am working on environment mapping my objects from a skybox and I am getting an unexpected result, the final output is nothing, yet all the components that are used in created the final output are correct.

This is my reflective factor

this is my base colour

Here is the environment mapped to the object

This is the final output from a mix() function, but I also tried just using the standard lerp (I wrote myself), which is all mix is.

As you can see, all of the inputs are visible, but the output color is blank.

This is the combination line.

finalColor = vec4(mix(baseColour.rgb,cubeColor,reflectiveFactor),1.0);

I did the math by hand as well, and I do not get this result. Any help would be great.

Edit Attaching Shaders:

Vertex Shader

#version 330 layout(location = 0) in vec3 vertex; layout(location = 1) in vec2 uv; layout(location = 2) in vec3 normal; layout(location = 3) in vec3 tangent; layout(location = 4) in vec3 bitangent; out vec2 uv0; out vec3 uv1; out vec3 normal0; out vec3 tangent0; out vec3 bitangent0; out vec3 worldPos0; uniform mat4 mvp; uniform mat4 world; uniform vec3 cameraEyeWorldPosition; void main() { gl_Position = mvp * vec4(vertex,1.0); uv0 = uv; normal0 = (world * vec4(normal,1.0)).xyz; tangent0 = (world * vec4(tangent,1.0)).xyz; worldPos0 = (world * vec4(vertex,1.0)).xyz; bitangent0 = (world * vec4(bitangent,1.0)).xyz; vec3 E = normalize(worldPos0 - cameraEyeWorldPosition); uv1 = reflect(E,normal0); }

Fragment Shader

#version 330 struct Attenuation { float constant; float linear; float exponential; }; struct BaseLight { vec4 colour; float ambientIntensity; float diffuseIntensity; }; struct DirectionalLight { BaseLight base; vec3 direction; }; struct PointLight { BaseLight base; vec3 position; Attenuation attenuation; }; struct SpotLight { PointLight base; vec3 direction; float cutoff; }; vec3 CalcBumpedNormal(); vec4 CalcLightInternal(BaseLight _light, vec3 _lightDirection, vec3 _normal); vec4 CalcDirectionalLight(vec3 _normal); vec4 CalcPointLight(PointLight _light, vec3 _normal); vec4 CalcSpotLight(SpotLight _light, vec3 _normal); const int MAX_POINT_LIGHTS = 10; const int MAX_SPOT_LIGHTS = 5; in vec2 uv0; in vec3 uv1; in vec3 normal0; in vec3 tangent0; in vec3 bitangent0; in vec3 worldPos0; out vec4 finalColor; uniform DirectionalLight directionalLight; uniform PointLight pointLights[MAX_POINT_LIGHTS]; uniform SpotLight spotLights[MAX_SPOT_LIGHTS]; uniform int numPointLights = 0; uniform int numSpotLights = 0; uniform vec3 cameraEyeWorldPosition = vec3(0.0,0.0,0.0); uniform sampler2D diffuseTexture; uniform sampler2D ambientTexture; uniform sampler2D normalTexture; uniform sampler2D specularTexture; uniform sampler2D glossTexture; uniform sampler2D reflectiveTexture; uniform samplerCube cubeMapTexture; void main() { finalColor = vec4(1.0,1.0,1.0,1.0); vec4 MaterialDiffuseColor = texture2D(diffuseTexture, uv0); vec3 Normal = CalcBumpedNormal(); vec4 TotalLight = vec4(0.0,0.0,0.0,1.0); TotalLight = CalcDirectionalLight(Normal); for (int i = 0; i < numPointLights; i++) { TotalLight = TotalLight + CalcPointLight(pointLights[i], Normal); } for (int i = 0 ; i < numSpotLights ; i++) { TotalLight += CalcSpotLight(spotLights[i], Normal); } float reflectiveFactor = texture2D(reflectiveTexture, uv0).r; vec3 cubeColor = texture(cubeMapTexture, uv1.xyz).rgb; finalColor = MaterialDiffuseColor * TotalLight; finalColor = vec4(mix(finalColor.rgb,cubeColor,reflectiveFactor),1.0); } vec3 CalcBumpedNormal() { vec3 Normal = normalize(normal0); vec3 Tangent = normalize(tangent0); vec3 Bitangent = normalize(bitangent0); Tangent = normalize(Tangent - dot(Tangent, Normal) * Normal); vec3 BumpMapNormal = texture(normalTexture, uv0).xyz; BumpMapNormal = 2.0 * BumpMapNormal - vec3(1.0, 1.0, 1.0); vec3 NewNormal; mat3 TBN = mat3(Tangent, Bitangent, Normal); NewNormal = TBN * BumpMapNormal; NewNormal = normalize(NewNormal); return NewNormal; } vec4 CalcLightInternal(BaseLight _light, vec3 _lightDirection, vec3 _normal) { vec3 VertexToEye = vec3(0.0, 0.0, 0.0); VertexToEye = normalize(cameraEyeWorldPosition - worldPos0); vec4 AmbientColor = vec4(0.0, 0.0, 0.0, 0.0); AmbientColor = _light.colour * (texture2D(ambientTexture, uv0)); float DiffuseFactor = 1.0; DiffuseFactor = dot(normalize(_normal), _lightDirection); DiffuseFactor = max(0.0,DiffuseFactor); vec4 DiffuseColor = vec4(0.0, 0.0, 0.0, 0.0); vec4 SpecularColor = vec4(0.0, 0.0, 0.0, 0.0); DiffuseColor = _light.colour * _light.diffuseIntensity * DiffuseFactor; vec3 LightReflect = vec3(0.0, 0.0, 0.0); float SpecularFactor = 0.0; LightReflect = 2.0 * dot(_lightDirection, normal0) * normal0 - _lightDirection; SpecularFactor = dot(VertexToEye, LightReflect);; SpecularFactor = max(0.0,SpecularFactor); float specularPower = (texture2D(glossTexture, uv0).r); float specularIntensity = texture2D(specularTexture, uv0).r; SpecularFactor = pow(SpecularFactor, specularPower); SpecularColor = _light.colour * specularIntensity * SpecularFactor; return (AmbientColor /*+ RimColor*/ + DiffuseColor + SpecularColor); } vec4 CalcDirectionalLight(vec3 _normal) { return CalcLightInternal(directionalLight.base, directionalLight.direction, _normal); } vec4 CalcPointLight(PointLight _light, vec3 _normal) { vec3 LightDirection = vec3(0.0, 0.0, 0.0); float Distance = 0.0; LightDirection = worldPos0 - _light.position; Distance = length(LightDirection); LightDirection = normalize(LightDirection); vec4 Color = vec4(0.0, 0.0, 0.0, 0.0); float Attenuation = 1.0; Color = CalcLightInternal(_light.base, LightDirection, _normal); Attenuation = _light.attenuation.constant + _light.attenuation.linear * Distance + _light.attenuation.exponential * Distance * Distance; return Color/Attenuation; } vec4 CalcSpotLight(SpotLight _light, vec3 _normal) { vec3 LightToPixel = vec3(0.0,0.0,0.0); float SpotFactor = 0.0; LightToPixel = normalize(worldPos0 - _light.base.position); SpotFactor = dot(LightToPixel, _light.direction); if (SpotFactor > _light.cutoff) { vec4 Color = CalcPointLight(_light.base, _normal); return Color * (1.0 - (1.0 - SpotFactor) * 1.0/(1.0 - _light.cutoff)); } else { return vec4(0.0, 0.0, 0.0, 0.0); } }

This issue is now solved, I had two textures using the same texture unit.

**Edited by harshman_chris, 17 March 2013 - 06:28 PM.**