Skip to main content
GameDev.net gamedev.net
🔒 Locked 🤖 Godot

HLSL: back buffer texture black from certain angles

Started by Starwaster Mar 2, 2009 at 10:34 AM 0 replies 1.3k views
Original Post
Starwaster
Starwaster
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?
MJP
MJP
Unfortunately it's a bit hard to know what's going on since you're working in the context of a big huge complex game that could be doing all kinds of crazy stuff in the app code or in other shaders. You could try to debug things in PIX...but it would probably be very difficult to find what you're looking for. It's also likely that PIX would kick the bucket with such a complex project.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.