- Home /
Shader:DX11 get texture dimensions inside a shader
Hi everybody,
I would love to have a float2 containing a texture's mipmap0-dimensions. But I also rather not want to expose a shader property to achieve that.
DX11 Texture Objects provide the means to do that: Texture2D.GetDimensions()
But - well, the docs are pretty rare on that - how would I implement such a call in my fragment shader? Has anybody already done that successfully?
If I declared a texture/sampler pair via UNITY_DECLARE_TEX2D(name), how would I be able to access the corresponding Texture Object / call GetDimensions on it?
Thanks a lot in advance, St0fF
Answer by iaing · Mar 16, 2017 at 07:08 AM
In order to access DX11 specific language features, you can wrap calls in #if defined(SHADER_API_D3D11). When using UNITY_DECLARE_TEX2D(name), a Texture2D variable with 'name' is created on DX11.
So to use Texture2D.GetDimensions(), the following code would work:
 UNITY_DECLARE_TEX2D(_MainTex);
 #if defined(SHADER_API_D3D11)
             uint width;
             uint height;
             uint levels;
             _MainTex.GetDimensions(0, width, height, levels);
 #endif
To see the implementation of UNITY_DECLARE_TEX2D see HLSLSSupport.cginc
Your answer
 
 
             Follow this Question
Related Questions
Unity 5 tesselation problem 1 Answer
How to tint the specular map in Unity5 0 Answers
glTexSubImage3D in unity 0 Answers
Unity 5: Water Shader and Fog Not Rendering 1 Answer
Adding Outline to a Curved Shader 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                