Original Post
I'm editing the cloth shader from the game Crysis. Specifically I'm trying to get a chameleon effect like what they were originally planning for it back in its alpha days. The problem is that the backbuffer texture I'm using shows up as black from certain camera angles, mostly when looking upwards. This seems to happen to any of the fragment shaders that I try this effect with. Here's some of the code:
sampler2D chameleonMapSampler
{
Texture = $SceneTarget;
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = LINEAR;
AddressU = Clamp;
AddressV = Clamp;
sRGBLookup = true;
};
float2 vScreenProj = pPass.IN.screenProj.xy / (pPass.IN.screenProj.w );
cChameleon.xyz = tex2D( chameleonMapSampler, ((vScreenProj.xy - hexTC) + (samples[0] + vDither.xy)) ).xyz;
cChameleon.xyz += tex2D( chameleonMapSampler, ((vScreenProj.xy - hexTC) + (samples[1] + vDither.xy)) ).xyz;
cChameleon.xyz += tex2D( chameleonMapSampler, ((vScreenProj.xy - hexTC) + (samples[2] + vDither.xy)) ).xyz;
cChameleon.xyz += tex2D( chameleonMapSampler, ((vScreenProj.xy - hexTC) + (samples[3] + vDither.xy)) ).xyz;
cChameleon.xyz += tex2D( chameleonMapSampler, ((vScreenProj.xy - hexTC) + (samples[4] + vDither.xy)) ).xyz;
cChameleon.xyz += tex2D( chameleonMapSampler, ((vScreenProj.xy - hexTC) + (samples[5] + vDither.xy)) ).xyz;
cChameleon.xyz += tex2D( chameleonMapSampler, ((vScreenProj.xy - hexTC) + (samples[6] + vDither.xy)) ).xyz;
cChameleon.xyz /= 7.0;
float fEffectMask = pPass.cDiffuseMap.w;
#if %OPACITY_MAP
fEffectMask = tex2D(opacityMapSampler, pPass.IN.baseTC.xy).w;
#endif
half3 cDesaturatedDiffuse = dot(pPass.cDiffuseMap.xyz, float3(0.75,0.75,0.75));
pPass.cDiffuseMap.xyz = cDesaturatedDiffuse * cChameleon.xyz;
pPass.cGlossMap.xyz += (cChameleon.xyz * 0.25f );
So basically it's just doing several screenspace lookups and applying the average to the diffuse channel. Later down the line it all gets combined along with the other fragments in the pixel shader. FWIW, I've tried bypassing all that in the pixel shader by doing a single lookup on the chameleon texture there and applying that as my final pixel color. Same results. There's a Refractive keyword I can use that gets rid of this problem but then I have blending or z buffer problems. (anything shaded with this looks like it's in front of any transparent or blended object, which is really annoying with smoke grenades or fog) Where does this problem likely lie, and is this something I can fix, given that I can only edit things in the HLSL shader files?