Sign in to follow this  

HLSL sampler question...

This topic is 4358 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to sample a pixel from a sampler in my effect file. I've declared the sampler in my fx file as... texture GlowMap1; sampler GlowSamp1 = sampler_state { texture = (GlowMap1); AddressU = CLAMP; AddressV = CLAMP; MipFilter = POINT; MinFilter = LINEAR; MagFilter = LINEAR; }; in my c# file I've created a texture render target and rendered something to it (which I verified by saving the texture to disk and viewing it.) Then I assigned the texture to the GlowMap1 variable of my fx file via... effect.SetValue("GlowMap1", myTexture); Next I create a vertexBuffer that is Transformed coordinates of... (0,0), (screenWidth,0), (screenWidth,screenHeight), (0,screenHeight) of which I've assigned texture coordinates... (0,0), (1,0), (1,1), (0,1) Next I start the effect and render my vertexBuffer. meanwhile in my vertex shader passes the data to my pixel shader which attemps to sample colors from the texture coordinates from the GlowMap1 texture... float4 col = tex2D(GlowSamp1, IN.TexCoord); I then simply change the color of the above col and output it. The output gets rendered to a second texture which I've created. I save it to disk and it appears blank! Anyways, my question is really this: Am I setting the sampler correctly to actually sample from it? Thanks in advance, Devin

Share this post


Link to post
Share on other sites
It could be many things - here are some ideas:

(1) You list 4 coordinates in your VB. However, if you want to render a textured quad, you need to render 2 triangles. You may have just emitted this part from your post - I'm just making sure [wink]

(2) Does the GlowMap1 texture have the correct pixel data? It may help to try saving that to file as well.

(3) Are you getting any debug output? If anything is going majorly wrong, you will be informed of it there.

(4) You could try debugging the pixel shader and see exactly what values you get back from the tex2D() call.

Share this post


Link to post
Share on other sites
Quote:
Original post by devronious
effect.SetValue("GlowMap1", myTexture);

I doubt it'll make much difference, but just another suggestion - have you tried using effect.SetTexture("GlowMap1", myTexture) instead? It's not clear from the documentation what (if any) difference there is between SetValue() and SetTexture() when it comes to texture's.

hth
Jack

Share this post


Link to post
Share on other sites
Thanks Guys,

CircleSoft,

(1)Yes, I've ommitted the vertex buffer code that involes the two triangles. I've examined the vertex buffer and all looks good there.

(2)Yes, I've saved the texture to disk and it looks great. The vertex Shader is working properly. (That is the first op that writes to the GlowMap1 texture)

(3)(4)I wish I knew how to debug a shader. This might save me alot of time and trouble. I would like to examine the values in the pixel shader.

Q: How could I debug this shader????


JollyJeffers,

I don't seem to have that method in my effect?

Share this post


Link to post
Share on other sites
Quote:
Original post by devronious
Q: How could I debug this shader????

There are shader debuggers installed into Visual Studio 2003 by the SDK. They sort of appear in VS-2005, but they're a bit broke [smile]

The VStudio shader debuggers should allow you to step through Vertex Shaders if you have a software device, and step through Pixel Shaders if you're using the reference rasterizer. For the latter case (and what you'll be wanting) it's a very tedious affair - I prefer to use PIX myself:

You could consider looking into PIX and a full-stream capture. I've not played with it myself, but I'm pretty sure it's got "Deep Pixel Analysis" now.

Quote:
Original post by devronious
JollyJeffers,

I don't seem to have that method in my effect?

Ah, you using MDX then? it exists in native/C++ ID3DXEffect. I can't get my head around the MDX documentation - I can't even find a list of 'Effect' methods [headshake]

Jack

Share this post


Link to post
Share on other sites
Quote:
Original post by devronious
(3)(4)I wish I knew how to debug a shader. This might save me alot of time and trouble. I would like to examine the values in the pixel shader.

Check these 2 doc pages:

Shader Debugger
Shader Debugging Tutorial

Note that you have to be using VS2003. It has been discontinued in VS2005, IIRC.

Quote:

I don't seem to have that method in my effect?

Check out ID3DXEffect::SetTexture() in the docs. I have used SetValue() for setting textures before, but it doesn't hurt to try.

Share this post


Link to post
Share on other sites
I would really be interested in seeing what your code looks like and I believe that it will enable us to help you more effectively. What we would like to see is how you are rendering to texture and where you saving the texture and how.

One thing does come to mind though.

When you are saving your texture, are you saving it after the present method or before the present method. This might create some anomalies. You might end up with a funny colored saved texture file if you are saving the texture after the present method.

A simple example (Funny colored texture)

Device::Clear(...);
Device::BeginScene(...);
SafeToTexture(...); //Safe the back buffer to a file on disk.
Device::EndScene(...);
Device::Present(...);



A simple example (Correctly safed texture)

Device::Clear(...);
Device::BeginScene(...);
SafeToTexture(...); //Safe the back buffer to a file on disk.
Device::EndScene(...);
Device::Present(...);



I hope this helps.
Take care.

Share this post


Link to post
Share on other sites
Arrrrggghhh, I'm using VS2005 of course :( Is there a simple way to debug in 2005? If not I'll look into the PIX.

Armadon,

Here's my draw method:

[source lang=c#]
public void Draw(MeshObject mesh)
{
//store rendertarget and depthtarget
Surface rt = this.device.GetRenderTarget(0);
Surface dt = this.device.DepthStencilSurface;

//set dynamic values
Effect e = this.effect;
e.SetValue("GlowColor", new float[4] { 0, 1f, 0, 1f });
e.SetValue("Glowness", 1.6f);
e.SetValue("wvp", Matrix.Multiply(Matrix.Multiply(this.device.Transform.World, this.device.Transform.View), this.device.Transform.Projection));

//setup first render target
this.device.SetRenderTarget(0, this.glowMap1.GetSurfaceLevel(0));
this.device.DepthStencilSurface = this.depthBuffer.GetSurfaceLevel(0);
this.device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1, 0);

//render blank image
e.Begin(FX.None);

e.BeginPass(0);
mesh.MeshObj.DrawSubset(0);
e.EndPass();

if (this.doOnce) TextureLoader.Save("c:\\pass0.jpg", ImageFileFormat.Jpg, this.glowMap1);

e.SetValue("GlowMap1", glowMap1);

this.device.SetRenderTarget(0, this.glowMap2.GetSurfaceLevel(0));
this.device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1, 0);

e.BeginPass(1);
this.qtex.Draw();
e.EndPass();

if (this.doOnce) TextureLoader.Save("c:\\pass1.jpg", ImageFileFormat.Jpg, this.glowMap2);

this.doOnce = false;

e.SetValue("GlowMap2", glowMap2);

this.device.SetRenderTarget(0, rt);
this.device.DepthStencilSurface = dt;

e.BeginPass(2);
this.qtex.Draw();
e.EndPass();

e.End();

//restore surfaces
dt.Dispose();
rt.Dispose();

}




Jack,

"Ah, you using MDX then? it exists in native/C++ ID3DXEffect. I can't get my head around the MDX documentation - I can't even find a list of 'Effect' methods"

That's OK, I seem to had the same prob. I bought a book instead :(

Share this post


Link to post
Share on other sites

This topic is 4358 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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