Sign in to follow this  

Interpolating data using sampling in a pixel shader

Recommended Posts

I'm sending a array of data to the GPU (as a 1D texture) that I sample in my pixel shader. I use the data to draw a figure onto a quad in the PS. Everything's kosher until I zoom in. After getting very close, my figure is highly aliased with large stair-steps, even though I believe my sampler's filtering is set up correctly.
What part of the equation am I missing here? I appreciate the suggestions! The following code is SharpDX, but the important parts should be easy to read.
[source lang="csharp"]
Texture1DDescription textureDesc = new Texture1DDescription();
t1dDesc.ArraySize = 1;
t1dDesc.Usage = ResourceUsage.Immutable;
t1dDesc.Width = dataArray.Length;
t1dDesc.Format = Format.R32_Float;
t1dDesc.BindFlags = BindFlags.ShaderResource;
t1dDesc.CpuAccessFlags = CpuAccessFlags.None;
t1dDesc.OptionFlags = ResourceOptionFlags.None;
t1dDesc.MipLevels = 1;

DataStream ds = DataStream.Create(dataArray, false, false, false);
dataTexture = new Texture1D(d3dDevice, textureDesc, ds);

this.dataTextureView = new ShaderResourceView(d3dDevice, dataTexture);

this.dataSampler = new SamplerState(d3dDevice, new SamplerStateDescription()
Filter = Filter.MinMagMipLinear,
AddressU = TextureAddressMode.Clamp,
AddressV = TextureAddressMode.Clamp,
AddressW = TextureAddressMode.Clamp

float4 PS(PixelShaderInput input) : SV_TARGET
float4 color = float4(0,0,0,0);
float dataValue = data.Sample(dataSampler, input.texcoord.x);
if(input.texcoord.y <= dataValue)
color = dataValue;

return color;

[attachment=9452:Awful.jpg] Edited by SquirrelPop

Share this post

Link to post
Share on other sites
[quote name='xoofx' timestamp='1339643393' post='4949024']
Keep in mind that SamplerStateDescription (like in C++) is not initialized, so you should probably better set min/max lod...

I cut out those values to make the code paste shorter, but I do have them in there.
[source] ComparisonFunction = Comparison.Never,
MaximumAnisotropy = 16,
MipLodBias = 0,
MinimumLod = 0,
MaximumLod = 16[/source]

I didn't expect any difference, but I did try deleting them and I didn't see any effect, since I don't think those settings apply.

Share this post

Link to post
Share on other sites
[quote name='Dawoodoz' timestamp='1339621560' post='4948937']
I would run the executable from PIX to see step by step where things go wrong. I would start by confirming that the texture contain what I expect.

I will give that a shot. Visual Studio 12 doesn't seem to be able to do any graphics debugging when DX is embedded in a Metro app, which is what I am doing. I'll give PIX a shot, but I'm not hopeful. I will probably need to extract this from the Metro container and just do a vanilla DirectX version in order to use the tools.

Thank you.

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