Pixelshader with texture, no sampler 'struct'?

Started by
4 comments, last by cozzie 9 years, 8 months ago

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?

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

Advertisement

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);

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


Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

Anyone?

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

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).


Thanks, no problem. I hoped there was some secret magic :)

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

This topic is closed to new replies.

Advertisement