I'm sorry, the problem is NOT the same anymore. It just clarified a bit by showing up differently by doing the reflect calculation in the pixel shader, it are no longer triangle-artefacts, but pixel-artefacts now :-).
I checked the normals (looked like one hairy mess :-)) but they looked perfect.
When the distance gets bigger, the reflection gets darker (ie. immediately black (ambient color) at some point but as it grows per pixel as the distance goes bigger, it looks like it's fading, but it isn't).
So after thinking and thinking, it seems that the Reflect vector gets corrupt or something like that, as there are NO black texels in the cubemap. texCube() must be returning black because it can't translate the Reflect vector to the cube map.
Oh, I took your advice and threw away the light (it's not the reason). This is what the code looks like now:
VS:
float4x4 matWorldViewProj;float4x4 matWorld;float3 EyePosition;struct VS_OUTPUT{ float4 Pos: POSITION; float3 Normal: NORMAL; float4 Col: COLOR0; float3 Incident: TEXCOORD0;};VS_OUTPUT vertexMain(float4 Pos: POSITION, float4 Col: COLOR0, float2 Tex: TEXCOORD0, float3 Normal: NORMAL, float3 Tangent: TEXCOORD1, float3 Binormal: TEXCOORD2){ VS_OUTPUT Out = (VS_OUTPUT)0; Out.Pos = mul(Pos, matWorldViewProj); Out.Normal = normalize(mul(Normal, matWorld)); Out.Col = Col; float3 worldPos = mul(Pos, matWorld); Out.Incident = normalize(worldPos - EyePosition); return Out;}
PS:
float ReflectionFactor;float4 AmbientColor;struct VS_OUTPUT{ float4 Pos: POSITION; float3 Normal: NORMAL; float4 Col: COLOR0; float3 Incident: TEXCOORD0;};sampler reflectionMap : register(s2);float4 pixelMain(VS_OUTPUT In) : COLOR{ float4 baseColor = In.Col; float4 Color = AmbientColor * baseColor; float3 Reflect = reflect(In.Incident, In.Normal); Color = Color + ReflectionFactor * texCUBE(reflectionMap, Reflect); return Color;}
(ReflectionFactor is not the reason, I double checked)
So why is Reflect getting corrupted? That can only be because Incident is getting corrupted.
I read that the reflect() function is the same as:
Reflect = In.Incident - 2 * In.Normal * dot(In.Incident, In.Normal)
So this formula must get messed up with the wrong Incident or Normal. But as the Normal has always been fine (I really think so, lighting always seemed to be correct) before, the real trouble must be Incident, which might give strange results with the dot product.
Now, my mathematical skills (though not bad) are not good enough to understand why this happens and what must be happening wrong to mess up this formula.
Is there someone who can?
Thanks,
Dirk.