Jump to content

ShaderBuilder with dynamicTexture


Dad72
 Share

Recommended Posts

@NasimiAsl,

I use your ShaderBuilder, and I need advice please:

BABYLONX.ShaderBuilder.InitializeEngine();
var terrainMaterial = new BABYLONX.ShaderBuilder()            
.Map({ path: textureGround })
.Reference(1).Map({ path: 'images/textures/ground_0.png' , uv:'vec2(vuv*10.)' })
.Blue(1, BABYLONX.Helper().Map({ path: 'images/textures/grass_4.jpg' , uv:'vec2(vuv*10.)' }).Build(), {rangeStep:-0.05,rangePower:0.05})
.Red(1, BABYLONX.Helper().Map({ path: 'images/textures/rock_4.jpg' , uv:'vec2(vuv*10.)' }).Build(), {rangeStep:-0.05,rangePower:0.05}) 
.BuildMaterial(global.scene);		

terrain.material = terrainMaterial;
terrain.material.specularColor = new BABYLON.Color3(0.5, 0.5, 0.5);
terrain.material.specularPower = 64;

In line 3: .Map({ path: textureGround })

I would like to use a dynamic texture instead of a path.

var textureGround = new BABYLON.DynamicTexture("DynamicTexture", 1024, scene, true);				
var textureSize = textureGround.getSize();			
var textureContext = textureGround.getContext();

How can I do ?

Thanks

Link to comment
Share on other sites

9 hours ago, Dad72 said:

@NasimiAsl,

I use your ShaderBuilder, and I need advice please:


BABYLONX.ShaderBuilder.InitializeEngine();
var terrainMaterial = new BABYLONX.ShaderBuilder()            
.Map({ path: textureGround })
.Reference(1).Map({ path: 'images/textures/ground_0.png' , uv:'vec2(vuv*10.)' })
.Blue(1, BABYLONX.Helper().Map({ path: 'images/textures/grass_4.jpg' , uv:'vec2(vuv*10.)' }).Build(), {rangeStep:-0.05,rangePower:0.05})
.Red(1, BABYLONX.Helper().Map({ path: 'images/textures/rock_4.jpg' , uv:'vec2(vuv*10.)' }).Build(), {rangeStep:-0.05,rangePower:0.05}) 
.BuildMaterial(global.scene);		

terrain.material = terrainMaterial;
terrain.material.specularColor = new BABYLON.Color3(0.5, 0.5, 0.5);
terrain.material.specularPower = 64;

In line 3: .Map({ path: textureGround })

I would like to use a dynamic texture instead of a path.


var textureGround = new BABYLON.DynamicTexture("DynamicTexture", 1024, scene, true);				
var textureSize = textureGround.getSize();			
var textureContext = textureGround.getContext();

How can I do ?

Thanks

http://www.babylonjs-playground.com/#E6OZX#89

hi

you can use SetUniform for define your new texture or any new uniform

and with .material.setTexture you can set your wanted texture (any kind of texture ) 

and for use This material in Shader Builder use .Map function 

sample

        .SetUniform('dyTexture1','sampler2D')          
        .Map({ index: 'dyTexture1',bias : 2.})
        .Reference(1)
         ...
        .BuildMaterial(scene);


//  set dynamic texture

        var textureGround = new BABYLON.DynamicTexture("DynamicTexture", 1024, scene, true);				
         ground.material.setTexture('dyTexture1',textureGround);
       

 

Link to comment
Share on other sites

I have another Nasimi question. I would like to be able to modify the textures after loading and the uvscale. How do you do it please.

I put in bold what I would like to be able to modify after the loading of the ground.

.Blue(1, BABYLONX.Helper().Map({ path: global.elevation.texture1, uv:'vec2(vuv*'+global.elevation.uvScale+')' }).Build(), {rangeStep:-0.48,rangePower:0})
.Red(1, BABYLONX.Helper().Map({ path: global.elevation.texture2, uv:'vec2(vuv*'+global.elevation.uvScale+')' }).Build(), {rangeStep:-0.48,rangePower:0})   
.Green(1, BABYLONX.Helper().Map({ path: global.elevation.texture3, uv:'vec2(vuv*'+global.elevation.uvScale+')' }).Build(), {rangeStep:-0.48,rangePower:0})

And another question, can we add another color after loading loading of ground ?

for exemple:

terrainMaterial.Yellow(1, BABYLONX.Helper().Map({ path: global.elevation.texture4, uv:'vec2(vuv*'+global.elevation.uvScale+')' }).Build(), {rangeStep:-0.48,rangePower:0})

or 

terrainMaterial.add(Yellow(1, BABYLONX.Helper().Map({ path: global.elevation.texture4, uv:'vec2(vuv*'+global.elevation.uvScale+')' }).Build(), {rangeStep:-0.48,rangePower:0}))

I start with ShaderBuilder which seems complex, but incredibly powerful. 

Thanks for help

Link to comment
Share on other sites

http://www.babylonjs-playground.com/#E6OZX#90

you need define another Uniform

for example .SetUniform('scaleTxt','vec3')      

i define Vector 3 because we can manage 3 text scale with that

you can def mat4 for manage 12 parameter with one uniform

but if you just wanna manage 1 you use float

anyway you change that with setUniform

 

Link to comment
Share on other sites

about color replace

let me make a sample for explain full color replace in shader Builder in this post

http://www.babylonjs-playground.com/#E6OZX#92

you just have 8 color    [red,green,blue,cyan,pink,yellow,white,black]  in one reference

you can separated any colors to any Step (0-255  recommend use 0-25 in max) 

so if you use separated color  for all you have 80 color in one reference

you can define others pattern in other reference too and use that too

 after loading you can not change base custom shader but you can redifine your shaderBuilder and add your wanted color for that

if you wanna use this stuff you can use ReplaceColor method

ReplaceColor(index: number, color: number, mat: string, option: IReplaceColor)

//

for example .ReplaceColor(reference index, BABYLONX.Helper.Blue, ... , option).

 

this is complicated stuff in ShaderBuilder but try to make sample for fully understand this

 

 

 

Link to comment
Share on other sites

2 hours ago, NasimiAsl said:

you can separated any colors to any Step (0-255  recommend use 0-25 in max) 

I did not understand that. I notice that I have color confusion between blue and cyan that create a mixture of the two textures. I think its two colors are too close.

I also have a confusion between green and black that gives the same texture.

I use all colors disponnible and you can see that the green that should be a texture of rock, gives me sand that is black:

And pink gives a mixture with white.

You can test it here:

http://www.babylon.actifgames.com/TerrainEditor/index.php

58aaff2516893_2017-02-2015_35_13-TerrainEditor.thumb.jpg.8284517e53a4725b98e0d925b6f29c7f.jpgDelos.thumb.png.68c7634399350242df3e566abcf74b4b.png

 

Link to comment
Share on other sites

pink = #FF00FF (= fuchsia) => #ffc0cb = pink

cyan =  #00FFFF => #00ffff

Yellow = #FFFF00 => #ffff00

red = #FF0000 => #ff0000

blue = #0000FF => #0000ff

green = #00FF00 (= lime) => #008000 = green

white = #FFFFFF => #FFFFFF

black = #000000  => #000000

I have a different color for pink and green. But when I create colors by name, it gives me this result for pink and green.

58ab11725f16a_2017-02-2016_54_58-ShaderBuilderwithdynamicTexture-QuestionsAnswers-HTML5GameDevsForum.jpg.294f558e611a505791256c3f341171ae.jpg 58ab1173154fc_2017-02-2016_55_16-ShaderBuilderwithdynamicTexture-QuestionsAnswers-HTML5GameDevsForum.jpg.d5dfcea2ef5069009b9b4ad4d72e3baa.jpg

Link to comment
Share on other sites

@NasimiAslI have one last problem that I do not get. When I load the terrain with the ShaderBuilder material and its 8 defined textures. I can not change textures for one of the 8 textures.

I try to make dispose() on the material, assign another textures and then reload the shaderBuilder, but it does not work.

I would like to be able to redefine a textures after loading, how to do it?

Or how to redefine the path of an image in a SetUniform('pathvar', ???) . sampler2D is for new BABYLON.Texture. But for the "Path", I do not know.

Thanks 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...