Jump to content

  • Log In with Google      Sign In   
  • Create Account

Pixelshader with texture, no sampler 'struct'?


Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
5 replies to this topic

#1   Members   

4623
Like
0Likes
Like

Posted 06 August 2014 - 08:55 AM

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


#2   Members   

1698
Like
4Likes
Like

Posted 06 August 2014 - 11:11 AM

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, 06 August 2014 - 11:12 AM.


#3   Members   

4623
Like
0Likes
Like

Posted 06 August 2014 - 01:08 PM

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, 06 August 2014 - 01:15 PM.

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

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


#4   Members   

4623
Like
0Likes
Like

Posted 07 August 2014 - 08:20 AM

Anyone?

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

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


#5   Members   

1698
Like
0Likes
Like

Posted 07 August 2014 - 12:53 PM

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, 07 August 2014 - 03:00 PM.


#6   Members   

4623
Like
0Likes
Like

Posted 07 August 2014 - 01:00 PM

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





Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.