Search Unity

unity 5.1 GL.Clear not working with 3d RenderTextures

Discussion in 'Shaders' started by CKahler, Jun 29, 2015.

  1. CKahler

    CKahler

    Joined:
    May 6, 2013
    Posts:
    149
    Hi,
    his was working in unity5.0 :

    Graphics.SetRenderTarget(volumeTexture3D); //(volumeTexture3D == int, 512x512x512)
    GL.Clear(false,true,new Color(-1,0,0,0));

    now unity5.1 clamps it to zero...but I really need this to work...and the only workaround I can think of is doing it in a dispatch function, but this would be much slower than just using GL.Clear().

    Any ideas, suggestions, help? (Btw. Graphics.Blit also clamps to zero and my values are in a range of -1 till 134217728)
     
    Last edited: Jun 29, 2015
  2. CKahler

    CKahler

    Joined:
    May 6, 2013
    Posts:
    149
    Ok, I just rewrote all the shaders that were affected and added -1 where needed...so it works now, but it would be nice if the unity devs bring the feature back... if possible.
     
  3. Plutoman

    Plutoman

    Joined:
    May 24, 2013
    Posts:
    257
    As far as I know, all color values are clamped. I thought texture values were clamped, too, which is why normal maps are not encoded from -1 to 1, but rather 0 to 1, and then mapped back to -1 to 1.

    That would be my suggestion; I encode world position into an ARGBFloat texture by mapping the positions from a range of -400 to +400 back to a range of 0 to 1, and then when I read the data back in I re-map it to the -400 to +400 range again.

    If the extra few instructions to do that are possible, that would be my recommendation, but you will also get floating point issues on large values if you need pinpoint accuracy (for my world position, that is why I required float textures, as I needed 32-bit values to actually store accurate decimals in those ranges).
     
  4. CKahler

    CKahler

    Joined:
    May 6, 2013
    Posts:
    149
    Well I solved the negative issue with adding/subtracting 1 in the later process, but now after I reinstalled 5.1 again.... I found out that GL.Clear is not working at all with my 3dtexture.... maybe it's the format (RInt) however that should not be a problem normally... maybe it's a bug after all, can you try to clear a 3d texture (RInt) with GL.Clear in unity 5.1?
     
    Last edited: Jun 29, 2015
  5. CKahler

    CKahler

    Joined:
    May 6, 2013
    Posts:
    149
    Last edited: Jun 29, 2015
  6. TacticalDan

    TacticalDan

    Joined:
    Jan 1, 2013
    Posts:
    35
    Yep, looks like GL.Clear just stopped working for volume render textures when I imported an old Unity 4 project into 5.1. I guess I'll have to custom do this with a compute shader?
     
  7. jfshshnsd

    jfshshnsd

    Joined:
    Apr 28, 2017
    Posts:
    1
    Resurrecting this because it seems to still be the case that GL.Clear has no effect on 3d (volume) textures.
     
    Daerst likes this.
  8. Daerst

    Daerst

    Joined:
    Jun 16, 2016
    Posts:
    275
    +1, currently there seems to be no simple way to clear a volume texture.
    Using a compute shader as a workaround for now.