why sampler can't work?

Started by
4 comments, last by neneboricua19 19 years ago
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(); } }
Advertisement
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


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

This topic is closed to new replies.

Advertisement