Search Unity

Resolved Tex2Dlod not LODing when I change the bias ...

Discussion in 'Shaders' started by neoshaman, Jul 1, 2022.

  1. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    Hello

    I'm using Built in, 2020.3.23f1 personal

    And when I change the LOD in the shader, it doesn't reflect the change in playmode.

    I'm sampling an octohedron cubemap atlas using a spatial hash, then using passed light direction I sample the pixel of that map. I want to use mip sampling as a way to sample the contribution of multiple pixel in that direction. But changing the LOD value don't seem to change anything.

    Everything is handled through code, there is no assets like material.
    - I first generate the atlas using low level call
    - I call generate mip map on the resulting texture
    - I pass the texture to the shader for sampling
    - I render the result in another texture
    - the texture is used on a mesh at runtime

    The prototype with regular material and no result on texture used to work, I don't see any reason for the shift in behavior per see, except maybe the setting of the atlas parameters. But I doubled checked, and I can't see what's wrong.


    float4 directlight = tex2Dlod( _Atlas, float4(shadowdirect,0,7));
    return directlight;

    upload_2022-7-1_3-33-40.png
    The atlas is a 16² tile with each tile being 64² for a total texture of 1024, the scene is covered by 16x16 cube zone, that hash the mesh position to a specific cubemap, there is a L shape roof single sided shown above as the red area, blue represent clear sky visibility in the direction of sampling, while red and green represent UV position of occluding point in that direction. Because of hash, the sampling data is shared across a square area of the mesh surface.

    - By sampling LOD at 7, I should have the whole cubemap contribution as a single color
    - By sampling beyond 7 I should have bleeding effects.

    upload_2022-7-1_3-41-51.png

    Unfortunately, the effect are the same for some reason. In theory I should have different bleeding even between 0 and 7 too, but nothing change.

    The set up of the texture
    Code (CSharp):
    1.   //set rendertexture
    2.         sceneCapture = new RenderTexture(cubemapSize, cubemapSize, 24);
    3.         sceneCapture.dimension = UnityEngine.Rendering.TextureDimension.Cube;
    4.         sceneCapture.antiAliasing = 1;
    5.         sceneCapture.filterMode = FilterMode.Point;
    6.         sceneCapture.graphicsFormat = UnityEngine.Experimental.Rendering.GraphicsFormat.R8G8B8A8_UNorm;
    7.         sceneCapture.depth = 16;
    8.         sceneCapture.useMipMap = true;
    9.         sceneCapture.autoGenerateMips = false;
    10.  
    11.         sceneCapture.Create();
    Code (CSharp):
    1.  public void initAtlas(){
    2.         setCameraData();
    3.         SetAtlas();
    4.         updateAll();
    5.         sceneCapture.GenerateMips();
    6.  
    7.         //destroyCamera();
    8.     }
    Is there something I miss?