Jump to content
  • Advertisement
Sign in to follow this  

[SlimDX] Instancing? Shader?

This topic is 3015 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

Alright, so I want to do hardware instancing, but my render loop draws nothing. Here's my HLSL code for the instancing thing:
float4x4 world;
struct VS_INPUT {
	float4 Pos : POSITION;
struct VS_OUTPUT {
	float4 Pos : POSITION;
void vs(in VS_INPUT In, out VS_OUTPUT Out) {
technique m {
    pass P0 {
        VertexShader = compile vs_2_0 vs();        
And now, here's my render procedure:
    Public Sub Render()

        If DEVICE Is Nothing OrElse RENDER_PAUSE Then Exit Sub

        DEVICE.Clear(ClearFlags.Target, BACKGROUND_COLOR, 0.0F, 0)




            Dim RandomEngine As New Random
            Dim CoordinateData(10 - 1) As Vector3
            For Index As Integer = 0 To 10 - 1
                CoordinateData(Index) = New Vector3(RandomEngine.NextDouble * VIEWPORT_SIZE.Width, RandomEngine.NextDouble * VIEWPORT_SIZE.Height, ZOOMING)

            Dim Buffer As New VertexBuffer(DEVICE, System.Runtime.InteropServices.Marshal.SizeOf(Vector3.Zero) * 10, Usage.WriteOnly, VertexFormat.Position, Pool.Default)
            Buffer.Lock(0, System.Runtime.InteropServices.Marshal.SizeOf(Vector3.Zero) * 10, LockFlags.None).WriteRange(CoordinateData)

            DEVICE.SetStreamSourceFrequency(0, 10, StreamSource.IndexedData)
            DEVICE.SetStreamSource(0, VIRUS_MESH.VertexBuffer, 0, VIRUS_MESH.BytesPerVertex)

            DEVICE.SetStreamSourceFrequency(1, 1, StreamSource.InstanceData)
            DEVICE.SetStreamSource(1, Buffer, 0, System.Runtime.InteropServices.Marshal.SizeOf(Vector3.Zero))

            Dim Declaration As New VertexDeclaration(DEVICE, VertexDeclaration)

            DEVICE.VertexDeclaration = Declaration
            DEVICE.Indices = VIRUS_MESH.IndexBuffer

            OBJECT_EFFECT.SetValue(New EffectHandle("world"), DEVICE.GetTransform(TransformState.World))

            Dim Passes As Integer = OBJECT_EFFECT.Begin(FX.None)
            For Pass As Integer = 0 To Passes - 1
                DEVICE.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, VIRUS_MESH.VertexCount, 0, VIRUS_MESH.FaceCount)

            DEVICE.SetStreamSourceFrequency(0, 1, 0)
            DEVICE.SetStreamSourceFrequency(1, 1, 0)

        Catch ex As Exception
        End Try


    End Sub
Any ideas to why this isn't working?

Share this post

Link to post
Share on other sites
Original post by Mathy
Any ideas to why this isn't working?

Many reasons.

Going in order, down your post. There may be more.


Your shader input struct is not setup for instancing.

You don't seems to have a pixel shader, "return float4(0,0,0,0);" should suffice.

You've got lots of stuff that looks like FFP code, Materials, Lights etc for the FFP will not work with shaders, you need to write this all yourself.

Where do you define your VertexDeclaration? I imagine it's not setup for instancing.

Share this post

Link to post
Share on other sites
Here is my VertexDeclaration:

Public VertexDeclaration() As VertexElement = New VertexElement() {
New VertexElement(0, 0, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Position, 0),

Share this post

Link to post
Share on other sites
*sigh* I wish I'd never mentioned instancing in the other topic.

You need to understand what you're actually doing when you're drawing one object with a shader before you try to do instancing, and it's clear you don't.

Work on getting a single object drawn in the position of your choice with your shader first, then you can expand it to instancing.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!