Order of Tex2D in shader

That makes sense.
I tried all different methods of assignment after reading your gist about that topic and none of them worked. Tried both samplers using the registers (0 and 1), tried named textures, didn’t work either.
Of course I always read from the second texture (displacement map) before reading from the one assigned by mg. So that suspicion here seemed to explain a lot.
I try to do a sample project the next few days but no promises…

I have also tried using the registers but it didnt solve the problem.
Only changing the order of my calls to tex2d has shown me that the order of the calls must match the declaration of the samplers at the top of the hlsl.
The register 0 is used by draw as you said. But if i call tex2d on another sampler before the one set on s0 it ignores the first call as if the second texture was just black. From what i noticed thanks to copypaste fail.

You mean you explicitly declare textures and set their registers? Because that should really work. Note that sampler registers and texture registers are not really bound together. I.e. the sampler at register s0 does not necessarily sample from the texture at t0.

This is the explanation. I will investigate if i have time and come back to confirm

So.
Sorry it took so long but I was sick… Again…

@Jjagg as promised:
Here is a small project I created to showcase the whole thing.

Maybe that helps.
None of the shaders work with the exception of the shader titled ‘new’ that uses the ‘new’ way of addressing the sampler (not tex2D).
There seems to be no difference if you use ps_4_0_level_9_1 or ps_4_0 at all.

Please feel free to prove me wrong; Point out that I made grave mistakes when writing the shaders; etc…
Always striving to learn :slight_smile:

Thanks, this makes testing easy. I’ll give this a try tonight.

Thx.

That’s why I made it :smile:

Bumpedidump…
Anyone?

Oops, I completely forgot about this. I’m short on time now though :confused:

I’m currently using this kind of declaration to avoid the problem

Texture2D brightpass;
SamplerState blurSampler
{
    Texture = <brightpass>;
    MinFilter = LINEAR;
    MagFilter = LINEAR;
    MipFilter = LINEAR;
	AddressU = CLAMP;
	AddressV = CLAMP;
};

But it forces to use ps_5_0 :confused: which limits compatibily with older systems.

hmmm

Texture2D FirstTexture;
SamplerState FirstSampler
{
    Texture = <FirstTexture>;
	MinFilter = Linear;
	MagFilter = Linear;
	MipFilter = Linear;
	AddressU = Wrap;
	AddressV = Wrap;
};

actually works with ps_4_0 and ps_4_0_level_9_1. Look at my code in the repo linked in an older post…
(at least with DX)

When i downgrade to ps_4_0_level_9_1 or ps_4_0_level_9_3, and build the shader, I get:

texlod not supported on this target

(HIDef profile) so i always use SM5 when declaring to avoid this :confused:

What the…???
Check out the repo and hit F5.
It has to be something else you use in the shader…

don’t use texlod,

use SampleLevel

(same as don’t use tex, use Sample)

Oh. Tex2dlod. Shame on me. :blush:

The thing is I use SampleLevel not tex2D nor texlod.

I’ve just made some tests:
ps_4_0 -> No error
ps_4_0_level_9_1 -> texlod not supported on this target
ps_4_0_level_9_3 -> texlod not supported on this target
ps_5_0 -> No error

At least I can use ps_4_0 :slight_smile: (as i was using ps_4_0_level_9_1 before, I went only up in the shadermodels, what can the most can the least, seems false now)

The declaration is the same as above:

Texture2D brightpass;
SamplerState downsampler
{
    Texture = <brightpass>;
    MinFilter = LINEAR;
    MagFilter = LINEAR;
    MipFilter = LINEAR;
    AddressU = CLAMP;
    AddressV = CLAMP;
};

and in the code (this is the ONLY texture sampling use in the whole code):

...
result += brightpass.SampleLevel(downsampler, input.tex + texOffset, 0).rgba;
...

So… would it be MojoShader that translates SampleLevel to texlod with ps_4_0_level_9_1 and ps_4_0_level_9_3 internally ?

4_0 is much, much higher level than 4_0_level_9_1 (… and 9_3 etc.), not sure if that came across in case someone is reading this.

The 4_0_level_9_1 level is basically 2002 or so, 4_0 is proper directx 9.0.

Might be confusing to newbies.

Hum. I’ve always thought level_x was adding more features to 4_0. I admit I’ve never read all the details in directx doc.
Never noticed until you wrote it, the “9” :slight_smile: Now it makes sense.

Nonetheless, this doesn’t explain why the error is talking about texlod() instead of samplelevel() :confused:

Is there any documentation about this somewhere with a bit of background information?

You can start here:


Further links are at the bottom.

1 Like