Sign in to follow this  
genesys

HLSL & image filtering

Recommended Posts

Can someone explain me how to perform imagefiltering with HLSL? I couldn't get the informations from the manual... to apply a texture I use for example float4 textureoutput = tex2D(texturesampler, uvcoordinates); but where and how do i specify the imagefiltering? Thx!

Share this post


Link to post
Share on other sites
Quote:
Original post by genesys
no FX file!! pure HLSL...

I'm using the irrlicht engine, which isn't able to load .fx files but it can read HLSL code and use it


Well, you must be declaring texturesampler SOMEWHERE if you're using HLSL.

Share this post


Link to post
Share on other sites
Quote:
Original post by genesys
no FX file!! pure HLSL...

I'm using the irrlicht engine, which isn't able to load .fx files but it can read HLSL code and use it

I'm not familiar with that particular engine, but in normal D3D, you can call SetSamplerState to specify different filtering modes along with other properties.

neneboricua

Share this post


Link to post
Share on other sites
im declaring the sampler in the HLSL code . . .

for example HLSL pixelshader:


sampler tex0;

struct PS_INPUT
{
float2 uv1 : TEXCOORD0;
};

float4 ps_main(PS_INPUT Input) : COLOR
{
float4 diffuse = tex2D(tex0,Input.uv1);
return diffuse;
}



here i declared the sampler at the beginning . . . how must i alter the code to activate filtering?

Share this post


Link to post
Share on other sites
You should declare samplers like so:

texture diffuseTexture : Diffuse;

sampler TextureSampler = sampler_state
{
texture = <diffuseTexture>;
AddressU = CLAMP;
AddressV = CLAMP;
AddressW = CLAMP;
MIPFILTER = LINEAR;
MINFILTER = LINEAR;
MAGFILTER = LINEAR;
};




[edit] Too bad there isn't code recognition for hlsl :(. [/edit]

Share this post


Link to post
Share on other sites
Quote:
Original post by sirob
You should declare samplers like so:
*** Source Snippet Removed ***

[edit] Too bad there isn't code recognition for hlsl :(. [/edit]

Remember that this only works if you're using .fx files. The OP stated that he was just using HLSL and was not using the Effect interface.

In that situation, you can't set the filtering properties from shader code. You have to do it from the application using SetSamplerState. That's basically what the ID3DXEffect interface is doing behind the scenes for you anyway.

neneboricua

Share this post


Link to post
Share on other sites
hum . . . ok - but i can set the renderstates only by object (or rather by material which is applied to the object) . . . so - what do i have to do if i'm using multiple textures in one shader for one object - but i want one texture to be filtered and another to be unfiltered?

Share this post


Link to post
Share on other sites
Quote:
Original post by genesys
hum . . . ok - but i can set the renderstates only by object (or rather by material which is applied to the object) . . . so - what do i have to do if i'm using multiple textures in one shader for one object - but i want one texture to be filtered and another to be unfiltered?


As neneboricua19 said, you have to use the IDirect3DDevice9::SetSamplerState() function before calling the draw call with your shader to configure the sort of sampling (linear/anisotropic/point etc..)

If you notice from the SDK documentation, the first parameter is a texture index (0 based). By changing this (as appropriate for your shader) you can have one texture linear-filtered and another point-filtered (for example). You could even have different addressing/wrapping modes for each stage if you desire...

In your application:
pDev->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
pDev->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );

pDev->SetSamplerState( 1, D3DSAMP_MAGFILTER, D3DTEXF_ANISOTROPIC );
pDev->SetSamplerState( 1, D3DSAMP_MINFILTER, D3DTEXF_ANISOTROPIC );

pDev->SetSamplerState( 2, D3DSAMP_MAGFILTER, D3DTEXF_POINT );
pDev->SetSamplerState( 2, D3DSAMP_MINFILTER, D3DTEXF_POINT );

pDev->SetTexture( 0, pSome_Linear_Filtered_Texture_Here );
pDev->SetTexture( 1, pAn_Anisotropic_Texture );
pDev->SetTexture( 2, a_HDR_point_filtered_texture );


In your pure HLSL shader file:
sampler tex0 : register( s0 );
sampler tex1 : register( s1 );
sampler tex2 : register( s2 );
//...
float4 a = tex2D( tex0, uv ); // Read from a linear-filtered texture
float4 b = tex2D( tex1, uv ); // Read from a anisotropic filtered texture
float4 c = tex2D( tex2, uv ); // Read from a point-filtered texture
//...


hth
Jack

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this