Shaders implementation

Started by
24 comments, last by Yura 11 years, 4 months ago

I've figured out with transparency. Problem was in my ViewPort. I've enabled ZBuffering and change the ViewPort MinZ and MaxZ values and it worked!) If someone interested in code, let me know, I can share.

Now, over the triangles I want to draw Lines from the same vertex buffer but with different color (white, for example). Drawing lines is not a problem, but how can I ignore their color, declarated in vertex buffer?

Advertisement

I still don't get it.

Why are you passing this --> PixelShaderInput input

when you should be passing this --> VertexShaderOutput input

Also, please post your final code with the current status of problem.

I still don't get it.

Why are you passing this --> PixelShaderInput input

when you should be passing this --> VertexShaderOutput input

Also, please post your final code with the current status of problem.

Maybe you're right. It's not logical. But problem is not here.

I have VertexBuffer filled with this struct:


[StructLayout(LayoutKind.Sequential)]
    struct Vertex
    {
        public Vector3 Position;
        public Color Color;
    }

How can I draw primitives, using this struct, but skipping it's color?

For better understanding what I'm Trying to do: over the TriangleList primiteves I want to draw LineList from the same vertex buffer but with different color (white, for example). Drawing lines is not a problem, but how can I ignore their color, declarated in vertex buffer? Is it possible to do it without using shaders?

For that your need to set your D3DFVF flags right.

Basically, without shaders your CUSTOMVERTEX structure needs to be setup with FVFs in such a manner that the color associated with that vertex gets bypassed.

Check this out for further reference --> http://msdn.microsoft.com/en-us/library/windows/desktop/bb172559(v=vs.85).aspx

For that your need to set your D3DFVF flags right.
Basically, without shaders your CUSTOMVERTEX structure needs to be setup with FVFs in such a manner that the color associated with that vertex gets bypassed.
Check this out for further reference --> http://msdn.microsoft.com/en-us/library/windows/desktop/bb172559(v=vs.85).aspx


It's it! Setting
d3dDevice.VertexFormat = VertexFormat.Position;
is skipping the color and making lines white.

I don't want to trouble you more, but is it possible to make this lines thicker? They are very thin and when i use rotation they are partly absorbed by color triangles:


d3dDevice.SetStreamSource(0, vertices, 0, Marshal.SizeOf(typeof(Vertex)));            d3dDevice.VertexFormat = VertexFormat.Position | VertexFormat.Diffuse;            
d3dDevice.Indices = triangles;            
d3dDevice.DrawIndexedPrimitive(PrimitiveType.TriangleList, 0, 0, totalPointsCount, 0, totalPointsCount / 2);            
d3dDevice.VertexFormat = VertexFormat.Position;          
d3dDevice.Indices = lines;            
d3dDevice.DrawIndexedPrimitive(PrimitiveType.LineList, 0, 0, totalPointsCount, 0, totalPointsCount);

Look at the green side of picture, some lines are missing. They are absorbed

I think you're troubled by aliasing right now. Put a basic sampler state with min,mag,mip all LINEAR, in your shader, and then see if something changes.

Nice to see you're making progress.

No, he does not use texturing, so it's not a sampling artifact. I suspect something with the depth test (z-fighting): Lines and Quads are approximately at the same depth, but only approximately. Play around with the DepthBias render state .

Nice to see you're making progress.

No, he does not use texturing, so it's not a sampling artifact. I suspect something with the depth test (z-fighting): Lines and Quads are approximately at the same depth, but only approximately. Play around with the DepthBias render state .

They are realy at the same depth. I'm drawing it from 1 vertexBuffer, just with different indexes. Their position is the same. I'm drawing tringles at first, then lines over them.


d3dDevice.SetStreamSource(0, vertices, 0, Marshal.SizeOf(typeof(Vertex)));            
d3dDevice.VertexFormat = VertexFormat.Position | VertexFormat.Diffuse;            
d3dDevice.Indices = triangles;            
d3dDevice.DrawIndexedPrimitive(PrimitiveType.TriangleList, 0, 0, totalPointsCount, 0, totalPointsCount / 2);            
d3dDevice.VertexFormat = VertexFormat.Position;          
d3dDevice.Indices = lines;            
d3dDevice.DrawIndexedPrimitive(PrimitiveType.LineList, 0, 0, totalPointsCount, 0, totalPointsCount);

Playing with DepthBias render state do not give any results...

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.

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!

This topic is closed to new replies.

Advertisement