1
\$\begingroup\$

That is my question, in SM 3.0 there is the HLSL intrasic function tex2Dlod to pick a color on a texture2d at specified coords and specified level-of-detail.

But after long search on the web, I don't find equivalent in SM 2.0 (ps_4_0_level_9_3)...

\$\endgroup\$
0
\$\begingroup\$

Shader Model 2.0 has no such function, but "tex2Dgrad" can be used to the same effect if your shader has access to the dimensions of the texture.

(Note that tex2Dgrad availability is subject to the caps bit D3DD3DPSHADERCAPS2_0_GRADIENTINSTRUCTIONS, so this isn't a sure thing)

Instead of:

color = tex2Dlod(map, uv, lod);

Do:

float scale = exp2(lod);

color = tex2Dgrad(map, uv, float2(scale/texture_width, 0.0), float2(0.0, scale/texture_height));

\$\endgroup\$
1
  • \$\begingroup\$ tex2Dbias/texldb as suggested by @Babis is in a similar vein, but unfortunately can't be used to sample a specific LOD, as the bias is always relative to the baseline determined by the uv gradient. (Sorry for commenting on that answer over here, but stackexchange doesn't allow newbs to comment on other answers) \$\endgroup\$ – jaybird May 20 '15 at 19:49
1
\$\begingroup\$

Look at the pixel shader instructions in Shader Model 2. I found "texldb" :

Biased texture load instruction. This instruction uses the fourth element (.a or .w) to bias the texture-sampling level-of-detail just before sampling

Syntax

texldb dst, src0, src1

https://msdn.microsoft.com/en-us/library/windows/desktop/bb206217(v=vs.85).aspx

\$\endgroup\$
0
\$\begingroup\$

Thank you a lot, the solution with tex2Dgrad work perfectly ! I don't have tested the solution with texldb, because there use registers and I want to avoid that.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.