Search Unity

Command Buffer depth

Discussion in 'Image Effects' started by Avol, Jun 17, 2016.

  1. Avol

    Avol

    Joined:
    May 27, 2016
    Posts:
    95
    Hi there guys,
    So I've been working on this volumetric solution and I've encountered a problem on Nvidia cards, could be a bug, could be me doing something wrong. So here's the scenario:

    This is how I store lights depth map to global texture
    Code (CSharp):
    1.         RenderTargetIdentifier RTI = BuiltinRenderTextureType.CurrentActive;
    2.         ShadowMap = new RenderTexture (512, 512, 0);
    3.  
    4.         CommandBuffer cb = new CommandBuffer();
    5.         cb.SetShadowSamplingMode(RTI, ShadowSamplingMode.RawDepth);
    6.         cb.Blit(RTI, new RenderTargetIdentifier(ShadowMap));
    7.         lightComponent.AddCommandBuffer(LightEvent.AfterShadowMap, cb);
    8.  
    9.         _depthSampler.SetGlobalTexture("shadowMap" + lightId.ToString(), new RenderTargetIdentifier(BuiltinRenderTextureType.CurrentActive));
    10.  
    11.         if (lightComponent)
    12.             lightComponent.AddCommandBuffer(UnityEngine.Rendering.LightEvent.AfterShadowMap, _depthSampler);
    This is how I sample depth:
    Code (CSharp):
    1. lDepth = tex2Dlod(shadowMap4, float4(sp.xy, 0, 0)).r;
    On AMD cards as expected the values returned are inbetween 0 and 1, while on NVidia cards I get either 0 or 1, but nothing in between. Tried with unity 5.4.0B18, 5.4.0B20 versions. Any ideas? thanks in advance.

    sdfgsdfdfgh.png
     
  2. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Have you checked in the frame debugger to see what the texture looks like and if it's bound properly?

    You can also use render doc to get some more information about what is happening closer to the metal.
     
  3. Avol

    Avol

    Joined:
    May 27, 2016
    Posts:
    95
    Thanks for the pointers! I will take a look at those, wasn't aware that such features exist :p
    The depth map is properly stored to RT, since Graphics.Blit prints it correctly, only having the problem of passing it to the shader using global texture / sampling it in the shader on nvidia cards, whilst all the amd cards I tried work just fine. Avoiding global texture might solve my issue.