سؤال

In OpenGL, I am using the following in my pixel shaders to get the correct pixel position, which is used to sample diffuse, normal, position gbuffer textures:

ivec2 texcoord = ivec2(textureSize(unifDiffuseTexture) * (gl_FragCoord.xy / UnifAmbientPass.mScreenSize));

So far, this is what I do in HLSL:

float2 texcoord = input.mPosition.xy / gScreenSize;

Most notably, in GLSL I am using textureSize() to get accurate pixel position. I am wondering, is there a HLSL equivalent to textureSize()?

هل كانت مفيدة؟

المحلول

In HLSL, you have GetDimensions

But it may be costlier than reading it from a constant buffer, even if it looks easier to use at first to do quick tests.

Also, you have alternative, using SV_Position and Load, just use the xy as an uint2, you remove the need of an user interpolator carrying a texture coordinate to index the screen.

Here the full documentation of a TextureObject

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top