Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

how do you use 3D Textures?

Discussion in 'Shaders' started by ryand-unity, May 2, 2011.

  1. ryand-unity

    ryand-unity

    Joined:
    Jan 21, 2011
    Posts:
    547
    hi. i was wondering how you use 3D texture and if you have photos of you useing 3D texture i wood like to see what thay look like.
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Unity does not support 3D textures so the answer would be: you can't.

    also 3D photos (given I understand the true meaning right) wouldn't work with 3D textures, 3D photos are dual 2d images and require special rendering to work as "3d". 3D textures are real 3d textures o not 2d images but 3 dimensional things where pixels also have a depth in the volume or better where you have a fixed number of pixels in depth an all pixels are always occupied (as with a 2d texture) so in stead of 512x512 it then would be 512x512x64 and alike. (though 64x64x64 is already quite heavy)
     
    Last edited: May 2, 2011
  3. ryand-unity

    ryand-unity

    Joined:
    Jan 21, 2011
    Posts:
    547
    ok if unity dosint suport 3D texture then y can you do this

    i moded this a little it won't work but unity will recednizit

    test it in unity the bump map texture spot looks diffrent

    Code (csharp):
    1. Shader "Bumped Specular" {
    2. Properties {
    3.     _Color ("Main Color", Color) = (1,1,1,1)
    4.     _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1)
    5.     _Shininess ("Shininess", Range (0.03, 1)) = 0.078125
    6.     _MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
    7.     _BumpMap ("Normalmap", 3D) = "bump" {}
    8. }
    9. SubShader {
    10.     Tags { "RenderType"="Opaque" }
    11.     LOD 400
    12.    
    13. CGPROGRAM
    14. #pragma surface surf BlinnPhong
    15.  
    16. sampler2D _MainTex;
    17. sampler3D _BumpMap;
    18. fixed4 _Color;
    19. half _Shininess;
    20.  
    21. struct Input {
    22.     float2 uv_MainTex;
    23.     float2 uv_BumpMap;
    24. };
    25.  
    26. void surf (Input IN, inout SurfaceOutput o) {
    27.     fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
    28.     o.Albedo = tex.rgb * _Color.rgb;
    29.     o.Gloss = tex.a;
    30.     o.Alpha = tex.a * _Color.a;
    31.     o.Specular = _Shininess;
    32.     o.Normal = UnpackNormal(tex3D(_BumpMap, IN.uv_BumpMap));
    33. }
    34. ENDCG
    35. }
    36.  
    37. FallBack "Specular"
    38. }
     
  4. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    bumpmap / normal map / parallax map / relief map has nothing to do with 3d textures etc at all.

    3D textures are normally used for volumetric lights, volumetric fog or generally stuff that tend to start with "volumetric" ie where you need to store pixel informations in more than a plane to interpolate over a depth volume
     
  5. ryand-unity

    ryand-unity

    Joined:
    Jan 21, 2011
    Posts:
    547
    do you know how to do this
     
  6. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    As Dreamora already said, Unity does not support 3D textures. That Shaderlab recognizes the keyword does not mean Unity supports them.
     
  7. ryand-unity

    ryand-unity

    Joined:
    Jan 21, 2011
    Posts:
    547
    volumetric that what i mean i know what volumetric are but can you make a shader that uses is
     
  8. ryand-unity

    ryand-unity

    Joined:
    Jan 21, 2011
    Posts:
    547
    look up volumetric in unity
     
  9. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Could you describe the situation in which you need them perhaps?
    Terms is one thing (but as mentioned, 3D textures ie volumetric are not supported by unity at all), but perhaps you require something totally different than what you might think
     
  10. ryand-unity

    ryand-unity

    Joined:
    Jan 21, 2011
    Posts:
    547
    Last edited: May 2, 2011
  11. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    it does not support nor render them.

    Thats why we asked you about what you want to do as you don't seem to be familiar with the terms (bump mapping has nothing to do with volumetric for example, more or less nothing that has to do with look of a surface is volumetric)
     
  12. ryand-unity

    ryand-unity

    Joined:
    Jan 21, 2011
    Posts:
    547
    i know that but can it do it for clouds or smoke or fog can unity do that. sorry if i sound angry im not
     
  13. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,878
    The best usage possibility for a 3d texture is for calculating 3d noise, and there are alternate and better ways of calculating that anyhow. Other uses are generally useless when considering you are trying to make a game.
     
  14. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    as for your edited in link: thats not volumetric textures, that are either specially setup 2D that do a pseudo volumetric or really 2D and post fx and alike for example

    there are many ways to fake volumetric textures without 3D textures (and most of them are normally used and wanted even in $$$$$$ engines, cause volumetrics are still pretty heavy and wasting all that performance for clouds just isn't that smart)
     
  15. ryand-unity

    ryand-unity

    Joined:
    Jan 21, 2011
    Posts:
    547
    but can you do it and do you have a volumetric shader
     
  16. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,628
    AFAIK There is no game right now that uses real volumetric anything. It's either some geometry with shaders, or particles, or post process effects made to look volumetric-y or a combination of all those things. None of these need or could use a 3d Texture.

    In short, tell us what you want to achieve so we can help you, because I'm pretty sure no-one here has a proper "volumetric shader".
     
  17. ryand-unity

    ryand-unity

    Joined:
    Jan 21, 2011
    Posts:
    547
    can you do somthing like this

    $180px-Planet1.png $180px-Planet2.png
     
  18. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,628
  19. ryand-unity

    ryand-unity

    Joined:
    Jan 21, 2011
    Posts:
    547
    but can you make it to were the blue surrounds the planet
     
  20. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,878
    yes
     
  21. increpare

    increpare

    Joined:
    Nov 17, 2010
    Posts:
    151
    Ryan. Look at the shader source code - do you see any reference to 3d texture data? (hint: the answer is "no"). There are a number of ways to manipulate surfaces in 3d in unity - using lighting (as normal/bump maps do), generating meshes in script, or using vertex shaders/shaderlab (as the environment shader above does). 3D texture data isn't used in any of them (it could be, but it's, as said above, used for stuff like lighting and terrain texturing - though not supported in unity in any event).
     
  22. ryand-unity

    ryand-unity

    Joined:
    Jan 21, 2011
    Posts:
    547
    @Aubergine how
     
  23. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    2nd mesh thats larger than the planed and inward directed for example (thats been done since DX7 days a decade ago)

    It would be best if you start with the basics, thats learn how shaders work, what they do and how effect trickeries were done for the past 15+ years so you get an idea how most of these effects could have worked and replicate them.

    The way you are trying to approach it isn't going to work out for you and will only ensure that people stop answering you or start flaming you due to your lack of interest in the basics and a totally unrealistic assumption on how the stuff works at all ... At the current knowledge level you are where it seems that even basic knowledge isn't present, its extremely hard to even advice you for directions.

    And in addition you asked about 7 different things in this thread now, refering to them as if they were even remotely the same, while showing that you don't understand how any single of them works although bump mapping is "trivial" for example
    Focus on achieving one effect and once you have done that and understood how you got there, go on to the next. Will help you learn and understand 100 times more than what you do here with "I don't care, takes more than 5 mins, next topic"
     
    Last edited: May 3, 2011
  24. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,878
    By reading the manual, studying some shader language and examples which can be found all over the internet and some additional determination.
     
  25. Dreamerm6

    Dreamerm6

    Joined:
    Jan 7, 2011
    Posts:
    13
    Can Unitys terrain editor "paint" a texture that has normal map? Lets say for example I have created a terrain like a volcano full of cracks etc.. So i will have my main texture call it Cracks.psd and I have a normal map call it Cracks_normal.psd. I now want to combine the two textures to make 1 texture that i can use to paint the area with unity so that the surface looks 3d?

    If so, how do i do this?
     
  26. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    You should start a new thread since your question has nothing to do with this train wreck. That will help people who are searching for the same thing in the future.
     
  27. ryand-unity

    ryand-unity

    Joined:
    Jan 21, 2011
    Posts:
    547
    yes there is a Game that Uses volumetric Lost Planet 2 Dos
     
  28. vruslan

    vruslan

    Joined:
    May 25, 2011
    Posts:
    10
    Dear friends,

    I am looking for the platform for developing and vizualization in browser medical data based on DICOM format (stack of the 2D images, please see an example http://www.slicer.org/publications/bitstream/viewbiglogo/1941/Elhawary-Neurosurgery2010-fig4). It is convenient to do one through the 3D_TEXTURE in OpenGL or DirectX.

    Are there any solutions in Unity3D applicable to my tasks?

    Nevertheless, is it possible to create a shader for hardware visualization 3D textures?

    Thank you!
     
  29. sawfish

    sawfish

    Joined:
    Feb 12, 2011
    Posts:
    314
    I've used similar applications in the dental field, and as I understand it these are highly optimized, multi-threaded and usually 64-bit applications, running on $5-10k workstations. The data usually ends up being in the gigabytes.

    I wouldn't hold my breath for Unity webplayer to be able to do this.

    But it's worth a shot, right?! :)

    If you're only rendering a few slices at a time, that wouldn't be too difficult to emulate, if you could load in all of the slices dynamically onto planes, and then enable/disable them on demand.
     
  30. vruslan

    vruslan

    Joined:
    May 25, 2011
    Posts:
    10
  31. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Have you asked them? I wouldn't be surprised if it was just a particle system with script-positioned and coloured particles.
     
  32. vruslan

    vruslan

    Joined:
    May 25, 2011
    Posts:
    10
    I still wait a response from the anatomicaltravel.com.

    The similar task of interactive 3D voxel data visualization was also successfully realized on WebGL by vicomtech.org team, presented on the Web3D 2011 conference and here http://demos.vicomtech.org/volren/

    May be some ideas will be generated from the community?
     
  33. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    Ryan for God's sake use real words, punctuation and the rest of it when posting. It took me a whole 30 seconds to work out what "recednizit" meant.
     
  34. femi

    femi

    Joined:
    Dec 16, 2008
    Posts:
    9
    Ryan's shader won't compile because it tries to sample 3D texture using float2.
    Adding `float3 worldPos;` to `Input` and changing the line with `tex3D()` call to

    `o.Normal = UnpackNormal(tex3D(_BumpMap, IN.worldPos));`

    makes the shader to compile, but a material using this shader breaks in inspector (unity reports NullReferenceException). Selecting the shader shows `_BumpMap Volume: Normal map` in inspector. So the 3D textures are supported by the shader lab but not by the engine / editor.
     
  35. einfopedia

    einfopedia

    Joined:
    Apr 4, 2012
    Posts:
    28
    3D textures are not supported by OpenGL-ES. Think about it: A 3D texture requires a lot more memory than a 2D one. And memory is a very scarce resource on embedded/mobile devices, which is what ES is targeted for.i think It's not so much a algorithmic problem but one of limited resources. In theory you could use multiple texture units/samplers to upload layers there, and do interpolation in the shader. But this would lack depth mipmaping.
     
  36. Martin-Kraus

    Martin-Kraus

    Joined:
    Feb 18, 2011
    Posts:
    617
    I understand the posting in the way that they render stacks of semitransparent textured polygons. This technique usually requires three stacks of 2D textures to produce a satisfying image quality for all orientations.

    I'm not sure about 3D textures in OpenGL ES, I thought it was an optional extension of the standard.
     
  37. brianasu

    brianasu

    Joined:
    Mar 9, 2010
    Posts:
    369
  38. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    Hi,
    Thanks for sharing the progress you have on this, it looks very interesting.
    I read the blog post, very interesting too.
    Any suggestions on how to use a 2d texture map to simulate 3d textures ?
    -Ippokratis
     
  39. brn

    brn

    Joined:
    Feb 8, 2011
    Posts:
    320
    One way is to hand create mip map levels on a texture, then use tex2Dlod with trilinear filtering to sample between them. Its an old trick with some resolution drawbacks but it works.
     
  40. brianasu

    brianasu

    Joined:
    Mar 9, 2010
    Posts:
    369
    I used a looong texture.

    Basically you have a for loop in your shader. That loop shoots a ray through a 1x1x1 cube volume. At each iteration you grab the xyz pos of the ray. Then you sample the texture tex2D(_LongTexture, float2(x + xoffset, y + yoffset))
    xoffset and yoffset are calculated using the z coord of the ray. The problem is you don't get nice filtering of a real tex3D. I'm kinda point sampling in the z direction. What brn said sounds interesting. I have yet to try that method it might be easier.

    If you want higher quality volumes you need to break it up into multiple passes. So the first pass just draws depth from 0 -> 0.1 the next pass 0.1 -> 0.2 and so on.

    Doing this is very fill rate heavy because to create a volume you'll need to add transparency. So each pixel can be overdrawing a 100 times. You can optimise by breaking out of the loop if the alpha is too high but not sure how to break out of the multiple passes. Another optimisation is to render your volume half or quarter size then up scale it. This is usually fine since fog and smoke volumes are inherently soft.

    Good luck!
     
  41. jcongote.unity

    jcongote.unity

    Joined:
    Feb 12, 2013
    Posts:
    7

    Volume Rendering is a computer graphics methodology to visualize scalar field bounded by a volume. Several methods exist to visualize the volumes like Raycasting, ShearWarping, etc.

    The demo improve the implementation presen...on of volumetric data with WebGL in real-time

    Volume Ray Casting in WebGL

    It uses shader model 3.0 and only 1 DrawCall for visualization in Unity. It also run in mobile platforms however with a very low frame rate.

    View attachment $MedView_v1.unitypackage
     
    Last edited: Mar 14, 2013
  42. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    Hi,
    Is it possible to reupload the unitypackage? Right now the link is dead.
    Thanks
     
  43. jcongote.unity

    jcongote.unity

    Joined:
    Feb 12, 2013
    Posts:
    7
  44. ChaseRLewis73003

    ChaseRLewis73003

    Joined:
    Apr 23, 2012
    Posts:
    85
    Only thing I know where 3D Textures are particularly nice is in fluid simulations since generally even if particle based the bulk fluid is rendered with a volume method since it gives much better results visually. Also for the simulation set itself it is convenient. However, you can always approximate a 3d texture with a tiled 2D texture. Just when your raycasting you'll have to convert the 3d ray point into 2d uv coordinates based on how you laid it out.
     
  45. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    Thanks a lot :)
     
  46. joel_b

    joel_b

    Joined:
    May 23, 2013
    Posts:
    4
    Very nice jcongote!
     
  47. LiverX!

    LiverX!

    Joined:
    Jan 15, 2013
    Posts:
    11
    Whoa! Guys! I have found what i needed! Thank you for this thread, But only one thing i can't understand - why tex3d is using uv, not uvw (float2, not float3)?
     
  48. SpunLab

    SpunLab

    Joined:
    Aug 1, 2013
    Posts:
    1
    Hello, is it possible to get the package? the links are down. Thank you.
     
  49. ronjart

    ronjart

    Joined:
    May 16, 2013
    Posts:
    100