Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1]
  Print  
Author Topic: mini mesh shaders  (Read 1714 times)
arnienet
Customers
Community Member
*****
Posts: 253


WWW
« on: June 03, 2009, 09:18:41 AM »

Hi,

Does anyone have a working example for a minimesh shader? I am currently trying to implement a vertex shader for grass blowing in the wind. I have had success with meshes and duplicates using the 'Windy Trees' demo downloaded from the Instruction Limit (thanks Zaknafein). I am having trouble with rendering mini meshes with a shader though, many randomly appear and disappear as the camera is moved. I've started with the shader for mini meshes, provided by Sylvain at http://francis.dupont.free.fr/shaders/CustomMinimesh.fx, which I think people have had success with. Image 1 shows the result without the shader, and image 2 is with the same code but using the shader. It would be great if someone could point me to a working example or explain anything I might be doing wrong, cheers.

The code (vb.net 2005):
Code:

    Private Shader As TVShader
    Private texGrass As Single
    Private mGrass As TVMiniMesh

    Public Sub def_Tree()
   
texGrass = TexFactory.LoadTexture("Media\sTree\grass_billWhiF_256.dds", "texGrass")

Shader = Scene.CreateShader
Shader.CreateFromEffectFile("Media\sTree\miniGrass.fx")

mGrass = New TVMiniMesh
mGrass = Scene.CreateMiniMesh(1000)

With mGrass

    .CreateBillboard(1, 1, False)
    .SetRotationMode(CONST_TV_BILLBOARDTYPE.TV_BILLBOARD_YAXIS)
    '.SetMaterial(sngGenMat)
    .SetTexture(texTree)
    .SetBlendingMode(CONST_TV_BLENDINGMODE.TV_BLEND_ALPHA)
    .SetAlphaTest(True, 96)
    .Enable(True)
    '.SetShader(Shader)

End With

For ix As Integer = 1 To 10
    For iz As Integer = 1 To 10
mGrass.EnableMiniMesh(ix * 10 + ix, True)
mGrass.SetPosition(420 + ix, Land.GetHeight(420 + ix, 2200 + iz), 2200 + iz, ix * 10 + iz)
    Next
Next
    End Sub

   
« Last Edit: June 03, 2009, 09:21:00 AM by arnienet » Logged

Total Dev time = 50% to code, 50% to test, 50% to find errors, 50% to fix, that's why it takes twice as long.

Dawn World MMO
AriusEso
Customers
Community Member
*****
Posts: 940

Esoteric


« Reply #1 on: June 03, 2009, 10:24:27 AM »

That custom shader is outdated. Iirc the Index value is now on TC3.

Code:
//Change this.
struct VS_STANDARD_VERTEX
{
    float4 position : POSITION;
    float3 normal : NORMAL;
    float2 tex : TEXCOORD0;
    float2 index : TEXCOORD1;
};

//To this:
struct VS_STANDARD_VERTEX
{
    float4 position : POSITION;
    float3 normal : NORMAL;
    float2 tex : TEXCOORD0;
    float2 index : TEXCOORD3;
};

Getting that wrong will cause the issue you are experiencing. Wink
Logged

-...-

arnienet
Customers
Community Member
*****
Posts: 253


WWW
« Reply #2 on: June 03, 2009, 12:38:33 PM »

Fantastic and cheers indeed,

That worked perfectly, TEXCOORD3 instead of TEXCOORD1. I can now render 2500 grass mini meshes (w *h = 0.5 by 0.7) on a large landscape of medium density foliage at 200 to 250 fps in windowed 1024 * 768 (Intel Dual Core 2Ghz, 1 Gbyte Ram, nVidia 8500GT, 512Ram). I shall now go on to animate the trees and bushes as in the windy trees sample,

all the best.


   
« Last Edit: September 19, 2009, 08:44:40 AM by arnienet » Logged

Total Dev time = 50% to code, 50% to test, 50% to find errors, 50% to fix, that's why it takes twice as long.

Dawn World MMO
Bogy
Community Member
*
Posts: 94


« Reply #3 on: October 04, 2009, 10:35:52 AM »

how do you use that CustomMinimesh.fx shader in your program?

i have something like:
            Shader2 = Scene.CreateShader("windyGrass");
            Shader2.CreateFromEffectFile("Media\\Shaders\\CustomMinimesh.fx");


            grassMesh = Scene.CreateBillboard(Globals.GetTex(billboardname.ToString()), 0, 0, 0, 1f, 1f, "thicky", false);
            grassMesh.SetMaterial(idNormal, -1);
            grassMesh.SetLightingMode(CONST_TV_LIGHTINGMODE.TV_LIGHTING_NORMAL, 1, 0);

            Instancer = Scene.CreateMiniMesh(number, "thickGrass");
            Instancer.CreateFromMesh(grassMesh, false);
            Instancer.SetAlphaTest(true, 128, true);
            Instancer.SetColorMode(true);
            Instancer.SetFadeOptions(true, 1500, 500);
            Instancer.SetMaterial(idNormal);
            Instancer.SetShader(Shader2);
           
            Random rand = new Random();           
            for (int i = 0; i < number; i++)
            {
                    int x = rand.Next((int)minPosX, (int)maxPosX);
                    int z = rand.Next((int)minPosZ, (int)maxPosZ);
                    float y = Land.GetHeight(x, z);

                    Instancer.EnableFrustumCulling(true, false, true);                   
                    Instancer.SetScale(scale, scale, scale, i);
                    Instancer.SetPosition(x, y, z, i);
                    Instancer.EnableMiniMesh(index, true);
                    Instancer.SetColor(new TV_COLOR(1, 1, 1, 0.9f).GetIntColor(), i);                                                           
            }

the result is that nothing changes in the minimeshes. they are in the same place, staying still, not moving in the wind or something.
how can i make them move in the wind based on this CustomMinimesh.fx shader?
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.3 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks