Sign in to follow this  
wmonash

why sampler can't work?

Recommended Posts

The DiffuseSampler always wrong here is code extern float4x4 WorldViewMatrix; extern float4x4 WorldViewProjMatrix; extern float4 Color; extern vector LightDirection; extern texture ShadeTex; extern float4 EyePosition; // // Structures // struct VS_INPUT { vector position : POSITION; vector normal : NORMAL; }; struct VS_OUTPUT { vector position : POSITION; float diffuseLight : TEXCOORD0; float specularLight : TEXCOORD1; float edge : TEXCOORD2; }; // // Main // VS_OUTPUT Main(VS_INPUT input) { VS_OUTPUT output = (VS_OUTPUT)0; output.position = mul(input.position, WorldViewProjMatrix); float3 N = normalize(input.normal); float3 L = normalize(LightDirection.xyz - input.position.xyz); output.diffuseLight = max(0, dot(L,N)); float3 V = normalize(EyePosition.xyz - input.position.xyz); float3 H = normalize(L + V); // output.specularLight = pow(max(0, dot(H,N),8); // if(output.specularLight<=0) output.specularLight = 0; output.edge = max(0, dot(V,N)); return output; } sampler ShadeSampler = sampler_state { Texture = <ShadeTex>; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; }; sampler DiffuseSampler = sampler_state { Texture = <DiffuseTex>; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; }; struct PS_OUTPUT { float4 RGBColor : COLOR0; // Pixel color }; PS_OUTPUT RenderScenePS( VS_OUTPUT In ) { PS_OUTPUT Output; // In.edge = tex1D(ShadeSampler, In.edge).x; // In.diffuseLight = tex1D(DiffuseSampler, In.diffuseLight).x; In.edge = tex1D(ShadeSampler, In.edge).x; // Compute the final color float4 Kd={0.0,1.0,0.5,1.0}; float4 Ks={0.5,0.2,1.0,1.0}; // Output.RGBColor = In.edge;// * (Kd * In.diffuseLight);// + Ks * In.specularLight); Output.RGBColor = In.edge + In.diffuseLight; return Output; } // // Effect // technique Toon { pass P0 { vertexShader = compile vs_2_0 Main(); //Sampler[0] = (ShadeSampler); PixelShader = compile ps_2_0 RenderScenePS(); } }

Share this post


Link to post
Share on other sites
I've also been having problems with sampler_state. I don't know if it's related to your problem. reading the byte size of my shader values works fine for all types EXCEPT the sampler types. I don't know much about shaders yet but I thought it was unusual.

C# Code
===================================================================

EffectHandle handleParam = effect.GetParameter(null, j);
ParameterDescription desc = effect.GetParameterDescription(handleParam);

Debug.WriteLine("name: " + desc.Name);
Debug.WriteLine("type: " + desc.Type);
Debug.WriteLine("usage: " + desc.Semantic);
Debug.WriteLine("flags: " + desc.Flags);
Debug.WriteLine("byte size: " + desc.Bytes); //<-- CRASHES HERE


Share this post


Link to post
Share on other sites
it only work right with
sampler ShadeSampler = sampler_state
{
Texture = <ShadeTex>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
};
wrong with
sampler DiffuseSampler = sampler_state
{
Texture = <DiffuseTex>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
};
or both of them

Share this post


Link to post
Share on other sites
Quote:
Original post by wmonash
The DiffuseSampler always wrong
here is code

Please be more specific. Why is "the DiffuseSampler always wrong"? What are the results? What do you expect them to be? Saying something like "it doesn't work" and dumping a bunch of code for other people to figure out doesn't really help much.

In any case, I don't see where you're declaring the DiffuseTex in your shader. Assuming that's just a typo, are you calling ID3DXEffect::SetTexture for the diffuse sampler? Are you sure the texture coordinates you're using to access the texture are correct? Can you see your mesh if you just output a constant color from your pixel shader (like white or something)?

neneboricua

Share this post


Link to post
Share on other sites
Quote:
Original post by neneboricua19
Quote:
Original post by wmonash
The DiffuseSampler always wrong
here is code

Please be more specific. Why is "the DiffuseSampler always wrong"? What are the results? What do you expect them to be? Saying something like "it doesn't work" and dumping a bunch of code for other people to figure out doesn't really help much.

In any case, I don't see where you're declaring the DiffuseTex in your shader. Assuming that's just a typo, are you calling ID3DXEffect::SetTexture for the diffuse sampler? Are you sure the texture coordinates you're using to access the texture are correct? Can you see your mesh if you just output a constant color from your pixel shader (like white or something)?

neneboricua

First plase forgive me my poor english, I just don't know how to say it in detail in english.
Yes , i call the SetTexture
m_pEffect->SetTexture( m_hMeshDiffuseTexture, m_pMeshDiffuseTexture );

Can you see your mesh if you just output a constant color from your pixel shader ?
Yes,I can ,if I am only use this sampler
sampler ShadeSampler = sampler_state
{
Texture = <ShadeTex>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
};

Share this post


Link to post
Share on other sites
What happens if you do something like this?

m_pEffect->SetTexture( m_hMeshShadeTexture, m_pMeshDiffuseTexture );


Even though the primary language spoken on these forums is English, a large number of users do speak other languages as well. For example, I can speak Spanish, and know of others who can speak German, French, Arabic, Farsi, and a number of other languages.

If you do post something in another language, try to translate as much as you can of it into English so that no users are left out of the discussion.

neneboricua

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