Jump to content

How to change mesh material to gray


HenryPeng
 Share

Recommended Posts

Hi, people. I have two problems.

(1) I want to make a mesh change its material color for gray, As a colorful person is changed to gray one. Maybe "Dude" can be used to be an example. I hope to change him .:P

(2)I want to put another material with a texture on a mesh, fix the material or add it?

Should I write a shader for it? then how should I do?

Link to comment
Share on other sites

55 minutes ago, aWeirdo said:

Hi @HenryPeng

if the mesh doesn't have a material,

do;

mesh.material = new BABYLON.StandardMaterial('myMaterial', scene);

then;

mesh.material.diffuseColor = BABYLON.Color3.Grey();

 

More information can be found in the docs: http://doc.babylonjs.com/tutorials/Materials

Hi, @aWeirdo,

haha, I hnow that , I want to make a mesh with material gray.  Dude is given out, change him<_<

Link to comment
Share on other sites

@HenryPeng Sorry, i forgot babylon spells it with an a, not an e. e.g. Gray instead of Grey.

But the dude is also made out of child meshes, the parent mesh is "empty".

here you go;

http://www.babylonjs-playground.com/#11BH6Z#105

 

If you want another shade of grey, you can change;

"BABYLON.Color3.Gray();"

to

"new BABYLON.Color3(0.2, 0.2, 0.2);"

//How it works; ( Red, Green, Blue)  Ranges from 0 to 1, so 0 = 0 in rgb value, 1 = 255 in rgb value.

http://www.babylonjs-playground.com/#11BH6Z#106

Link to comment
Share on other sites

13 hours ago, aWeirdo said:

@HenryPeng Sorry, i forgot babylon spells it with an a, not an e. e.g. Gray instead of Grey.

But the dude is also made out of child meshes, the parent mesh is "empty".

here you go;

http://www.babylonjs-playground.com/#11BH6Z#105

 

If you want another shade of grey, you can change;

"BABYLON.Color3.Gray();"

to

"new BABYLON.Color3(0.2, 0.2, 0.2);"

//How it works; ( Red, Green, Blue)  Ranges from 0 to 1, so 0 = 0 in rgb value, 1 = 255 in rgb value.

http://www.babylonjs-playground.com/#11BH6Z#106

Hi, @aWeirdo,

The example you gived has lost its texture, I hope it can save its texture and change gray to let it looks like a Black and white photo but not only one color photo.

Link to comment
Share on other sites

for that you need make Custom Shader and you lost auto generated standard shader

but it is possible with postprocess too (it is not optimized plan )

http://www.babylonjs-playground.com/#11BH6Z#143

the other plan is you clone standard material (with all uniform and attribute ) and create a custom shader exactly like standard material and change your last color  ( need complicated hack code for this time ) 

Link to comment
Share on other sites

@HenryPeng 

In that case, you want to change the color saturation of the texture, not the color of the material :P 

Which is currently not possible to do live, without using a shader, as NasimiAsl did above.

The simplest solution however would be to change the saturation of the texture files in a image editor and use those texture.

Link to comment
Share on other sites

as i say just have 2 plan :

1 : Postprocess with Rendertarget

2. : Clone standard material (with all uniform and attribute ) and create a custom shader exactly like standard material and change your last color  

 or make new Changes in standard Material ;) 

if i wrong  i like to know more about that 

 

Link to comment
Share on other sites

http://www.babylonjs.com/cyos/#1EDLOM#1

    float luminance = dot(texture2D(textureSampler, vUV).rgb, vec3(0.3, 0.59, 0.11));
    gl_FragColor = vec4(luminance, luminance, luminance, 1.0);

would prolly work as well though...


Actually we are dumb... the black and white shader already does this, a dot product is the way to go... thats so simple and fast, and you could easily add color shifts.

Link to comment
Share on other sites

@HenryPeng If you don't like shaders you could modify the texture that the object uses. Just use your PhotoShop or wahtever you like to use and greyscale the textures. Then load the grey textures instead of the original ones. Of course you can switch textures at runtime, too (if you need the have it colored at one time and grey at another). 

And if you don't have the textures prepared yet (for what so ever reason) you can convert them to a dynamic texture and grey scale it on runtime:

http://www.html5canvastutorials.com/advanced/html5-canvas-grayscale-image-colors-tutorial/
https://doc.babylonjs.com/classes/2.4/DynamicTexture
http://p215008.mittwaldserver.info/space_paint/
http://www.babylonjs-playground.com/#9U086#4

Good luck! :D

 

Link to comment
Share on other sites

No need for devs here :-)

Color Curves have been added in the standard material for such cases:

http://www.babylonjs-playground.com/#11BH6Z#158

Lookup table are also available if preferred in a special channel called cameraColorGradingTexture (I did not have black and white so I used red for demo purpose):

http://www.babylonjs-playground.com/#11BH6Z#159

The documentation for curves and LUT is working for both standard and PBR and is available here : http://doc.babylonjs.com/overviews/Physically_Based_Rendering_Master#camera-controls-color-grading-and-color-curves

 

Link to comment
Share on other sites

On 2016/10/28 at 4:14 PM, Sebavan said:

No need for devs here :-)

Color Curves have been added in the standard material for such cases:

http://www.babylonjs-playground.com/#11BH6Z#158

Lookup table are also available if preferred in a special channel called cameraColorGradingTexture (I did not have black and white so I used red for demo purpose):

http://www.babylonjs-playground.com/#11BH6Z#159

The documentation for curves and LUT is working for both standard and PBR and is available here : http://doc.babylonjs.com/overviews/Physically_Based_Rendering_Master#camera-controls-color-grading-and-color-curves

 

I think ColorCurves mybe a good way,

But I try to change it between color and black-and-white. it doesn't work wel, just change once..:( And it also brings some errors

http://www.babylonjs-playground.com/#11BH6Z#163

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...