ShaderBuilder Starter

make easy and fast ShaderMaterial or PostProcess

documents : ShaderBuilder Docs

code : Extensions/ShaderBuilder at master · BabylonJS/Extensions · GitHub

cdn reference : https://cdn.rawgit.com/BabylonJS/Extensions/master/ShaderBuilder/Babylonx.ShaderBuilder.js

PG : Babylon.js Playground

6 Likes

How do you add a texture2D using your shader builder?

g1.material = new BABYLONX.ShaderBuilder()

        .Solid({r:1.})

        .InLine(`

        

        float uvx = mod(vuv.x*(float(`+grass_set.seg*grass_set.seg+`)),1.); 

        float ind = floor(vuv.x*(float(`+grass_set.seg*grass_set.seg+`)) );  

        float gs = 1.-pow(uvx+(1.-uvx) *abs(sin(vuv.y*float(`+grass_set.width+`)*float(`+grass_set.countPerFace+`) ) ),2.15);

        if(gs<0.28)discard;

        result  = texture2d??

        

        `)

        .VertexShader(`

        float uvx = mod(vuv.x*(1.0*1.0),1.); 

        float ind = floor(vuv.x*(1.0*1.0) );  

        pos = pos  ;

    result = vec4(pos,1.);

        `)

        .Back()

        .BuildMaterial(scene);

        return g1;

hey
i am so glad you use shaderBuilder let me know how i can help you
but about textures
way 1 : use shader Builder Functions

.Map({ path:’/textures/ground.jpg’, uv:‘vec2(vuv)’ })

way 2 : use new uniform

.SetUniform(‘txtref1’,‘sampler2D’)
.Map({index:‘txtref1’,uv:‘vec2(vuv)’})

** after First load you can use the shader base code too

Thanks for the examples. Im just looking for some help to draw some grass on terrain. Your examples i thought were quite good.

ive got a mesh, and i want to draw grass all over it.

Following along with this one but not able to see how i can put each grass exactly on the terrain height

how you wanna make height map?
are you have any height map texture
??

2 Likes

Yes so I was going to generate the ground using a custom mesh with a heightmap and then get the normal positions and draw the grass on top.

so far i had just used a custom mesh with no heightmap but was having trouble drawing the actual grass meshes on the correct positions
thanks

2 Likes

you need define you height_map function in this example i have h_map

2 Likes

That is brilliant! Thanks v much.

1 Like