Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 11 Dec 2012
Offline Last Active May 06 2013 09:27 AM

#5035323 Adding thickness of plane figures

Posted by Yura on 22 February 2013 - 02:20 AM

Sorry, but I don't see any easy way to get around the issue...  Is it possible to move the geometry that can be enabled / disabled to another vertex buffer - or even to a special portion of the vertex buffer that would help you keep the indices manageable?


If the plane pieces are normally the same size, you could also try using instancing to render the expandable parts.  When thickness is disabled, you render using a thin plane as your per vertex data, and when it is enabled, you could switch the data to include the thicker version.  That would actually work out pretty easy I think...  Does that sound possible?


I figured out with this by adding extra points in the end of my vertexBuffer and build 2 indexbuffers: first without additional points - normal model, second with additional points - thick figures. Using ON/OFF thickness I'm just changing index buffers and render model.


Thanks for help Jason! smile.png

#5024692 Textures

Posted by Yura on 23 January 2013 - 06:35 AM

You were damn right!! The problem was in TexCoords! 

Thank you EPPO,

Thank you all for helping!

#5015387 DirectX 9 Instancing (with SharpDX)

Posted by Yura on 29 December 2012 - 04:35 AM

I think your problem is in VertexDeclaration.

When you are creating new VertexElement, second parameter in it's constructor is short offset - you set its wrong here

 new VertexElement(0, 0, DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.Position, 0),
		 new VertexElement(0, 12, DeclarationType.Color, DeclarationMethod.Default, DeclarationUsage.Color, 0),



float4 = 4 float * 4 bites = 16

and you make offset 12 in Color declaration

#5015072 Shaders implementation

Posted by Yura on 28 December 2012 - 08:26 AM

Hi, please help me resolve next problems:


1) how to draw triangle list and line list (like this http://imageshack.us...capture2pu.png/)

with different colours from one vertex buffer? I have 1 buffer which contains points and colors. I have 2 index buffers for it (for line list and triangle list). I want to draw triangles with color from buffer and white (or black or whatever) lines.

2) I've tried to implement shaders to make different front and back triangle colors, but it doesn't work:

//drawing function:


private void RedrawPrimitives()

            var effect = Effect.FromFile(d3dDevice, "Shader.fx", ShaderFlags.None);
            var technique = effect.GetTechnique(0);
            var pass = effect.GetPass(technique, 0);
            d3dDevice.VertexFormat = myVertexFormat;
            d3dDevice.VertexDeclaration = vertexDecl;

            d3dDevice.Clear(ClearFlags.Target, SharpDX.Color.White, 1.0f, 0);

            effect.Technique = technique;

            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;          
            d3dDevice.SetStreamSource(0, vertices, 0, Marshal.SizeOf(typeof(Vertex)));
            d3dDevice.DrawIndexedPrimitive(PrimitiveType.LineList, 0, 0, totalPointsCount, 0, totalPointsCount);





//and shader (which doesn't work)


sampler s0;

struct VertexShaderInput
    float4 Position : POSITION0;
	float4 Color : COLOR0;
	float4 face : VFACE;

    // TODO: add input channels such as texture
    // coordinates and vertex colors here.

struct VertexShaderOutput 
    float4 Position : POSITION0;
	float4 Color : COLOR0;

    // TODO: add vertex shader outputs such as colors and textureasdfasd
    // coordinates here. These values will automatically be interpolated
    // over the triangle, and provided as input to your pixel shader.

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
	VertexShaderOutput output;
	output.Position = mul(input.Position, input.Color);
    // TODO: add your vertex shader code here.

    return output;

float4 PixelShaderFunction(float2 coords: TEXCOORD0) : COLOR0
    float4 color = tex2D(s0, coords);
	color.rgb = color.r;

    return color;

technique Technique1
    pass Pass1
		VertexShader = compile vs_2_0 VertexShaderFunction();
        PixelShader = compile ps_2_0 PixelShaderFunction();