Sign in to follow this  

Pixelshader with texture, no sampler 'struct'?

This topic is 1259 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

I was just wondering, if you don't set states in an effect but do it using your code (statemanager), why would you need a sampler 'struct' then in your FX/ shader file.

 

For example, I do this now:

sampler2D textureSampler = sampler_state
{
	Texture		= (DiffuseTex0);
};


// and in the PixelShader

	float4 textureColor = tex2D(textureSampler, input.TexCoord);


Is there a way to skip the sampler 'struct' and access the texture directly, something like:

	float4 textureColor = tex2D(sampler(DiffuseTex0), input.TexCoord);

// error: (168) X3037: constructors only defined for numeric bases

Any thoughts?

Share this post


Link to post
Share on other sites

You don't need to use the structure, you can define sampler just like this:

sampler DiffuseTex0;

And then use it:

float4 textureColor = tex2D(DiffuseTex0, input.TexCoord);

You can even say:

sampler DiffuseTex0 : register(ps, s0);

Which will allow you to simply set the texture from c++ code by directly using the particular sampler register:

device->SetTexture(0, d3dTexture);
Edited by Tom KQT

Share this post


Link to post
Share on other sites

Thanks Tom.

I tried it, but I don't know how to 'link' the uniform extern texture (constant) to the sampler.

 

Update: it compiles (was a problem with the annotation), but when I set the texture I get this error:

D3DX: ID3DXEffect::SetTexture: Handle was incompatible with TEXTURE type

// I tried this:

uniform extern texture	DiffuseTex0		: DIFFUSE_TEXTURE0;
sampler DiffuseTex0;

// not possible, because DiffuseTex0 is then created twice.
// if I just try this:

sampler DiffuseTex0;

// then I don't have a uniform input (constant) anymore for the texture


Edited by cozzie

Share this post


Link to post
Share on other sites

Well, to be honest I'm not sure, I haven't used the Effect Framework for ages. I guess you would still need to assign the texture by

sampler textureSampler = sampler_state
{
    Texture = <DiffuseTex0>;
};

I'm using the version with a fixed register number which allows me to set the texture simply by SetTexture(register, texture).



Edited  by Tom KQT

Share this post


Link to post
Share on other sites
Sign in to follow this