Shaders implementation

Started by
24 comments, last by Yura 11 years, 3 months ago
Playing with DepthBias render state do not give any results...

I still assume it's a z-fighting problem. And I assume you're already using LessEqual for the ZFunc (this should be the default).

Oh my, I just realized this: Depth Bias (Direct3D 9). The devil's in the details:
The bias is not applied to any line and point primitive. However, this bias needs to be applied to triangles drawn in wireframe mode.

Alternative: Setup your WorldViewProjection to manually create a depth bias, e.g. use WVP * Matrix.Translation(0,0,-0.001f) or something. Edit: For the lines only!

Nice suggestion, but not executable in my case. I draw lines and triangles from 1 buffer and WVP matrix is the same for both. I can't change something only for lines or only for triangles. Changes will affect on all primitives.

Advertisement
In addition to trying out suggestions from this, like I said before, you should also try to introduce some sampler state in your shader now.

My shader is the same. I didn't change anything.
Your suggestion about using VertexShaderOutput instead PixelShaderInput not approached because of VFACE semantic. It is usable only like an input parameter to PixelShader. It cannot be defined in VertexShaderOutput struct

[quote name='Yura' timestamp='1357203186' post='5017018']
My shader is the same. I didn't change anything.
[/quote]

That's why I was saying that please change it a bit and use a sampler state with some basic filtering, like LINEAR.

The way I see that area is going white around your lines is most probably because of aliasing. So once aliasing is out of the way a clearer picture should come out.

And my bad that I kept overlooking the VFACE comment of yours. It makes sense now, why to use one kind of input than the other.

My shader is the same. I didn't change anything.

That's why I was saying that please change it a bit and use a sampler state with some basic filtering, like LINEAR.

The way I see that area is going white around your lines is most probably because of aliasing. So once aliasing is out of the way a clearer picture should come out.

And my bad that I kept overlooking the VFACE comment of yours. It makes sense now, why to use one kind of input than the other.

With sampler state I have some problems. I have no idea how to implement it. I found some basic information about samplers, filters etc, but I didn't get it... Maybe you have some useful links or code samples?

I can't change something only for lines or only for triangles. Changes will affect on all primitives.
You have two draw calls, so in-between you can change render states and shader constants:

effect.SetValue("worldViewProj", worldViewProj);
effect.BeginPass(0);

    d3dDevice.Indices = triangles;
    d3dDevice.SetStreamSource(0, vertices, 0, Marshal.SizeOf(typeof(Vertex)));
    d3dDevice.DrawIndexedPrimitive(PrimitiveType.TriangleList, 0, 0, totalPointsCount, 0, totalPointsCount / 2);
    
    d3dDevice.Indices = lines;          
    effect.SetValue("worldViewProj", slightlyCloserWorldViewProj);
    effect.CommitChanges();    // <- needed when changing shader constants during a running pass	!
    d3dDevice.DrawIndexedPrimitive(PrimitiveType.LineList, 0, 0, totalPointsCount, 0, totalPointsCount);

effect.EndPass();
I can't change something only for lines or only for triangles. Changes will affect on all primitives.
You have two draw calls, so in-between you can change render states and shader constants:

effect.SetValue("worldViewProj", worldViewProj);
effect.BeginPass(0);

    d3dDevice.Indices = triangles;
    d3dDevice.SetStreamSource(0, vertices, 0, Marshal.SizeOf(typeof(Vertex)));
    d3dDevice.DrawIndexedPrimitive(PrimitiveType.TriangleList, 0, 0, totalPointsCount, 0, totalPointsCount / 2);
    
    d3dDevice.Indices = lines;          
    effect.SetValue("worldViewProj", slightlyCloserWorldViewProj);
    effect.CommitChanges();    // <- needed when changing shader constants during a running pass	!
    d3dDevice.DrawIndexedPrimitive(PrimitiveType.LineList, 0, 0, totalPointsCount, 0, totalPointsCount);

effect.EndPass();

slightlyCloserWorldViewProj is working with formula WVP * Matrix.Translation(0, 0, -0.001f);

Thanks a lot!

But, If I'll change my surface to another one, which has Z values with opposite sign, does it mean that my line grid will become invisible (will be absorbed)?

This topic is closed to new replies.

Advertisement