Jump to content

StandardMaterial and ShaderMaterial Texture Color show different brightness.


klaude
 Share

Recommended Posts

Hello!

I'm upgrading my code, StandardMaterial to ShaderMeterial.

my scene colors are

scene.clearColor = new BABYLON.Color3(0,0,0);
scene.ambientColor = new BABYLON.Color3(1,1,1);

and before standardMaterial  initializing is like

mat = new BABYLON.StandardMaterial('material', scene);
mat.ambientColor = new BABYLON.Color3(1,1,1);
mat.diffuseTexture = texture.texture;
mat.opacityTexture = texture.texture;
 

and new shaderMeterial initializing is like

var route = {
	vertex: "custom",
	fragment: "custom",
};
var options = {
	needAlphaBlending : true,
	needAlphaTesting: true,
	attributes: ["position", "normal", "uv"],
	uniforms: ["world", "worldView", "worldViewProjection", "view", "projection"]
};
mat = new BABYLON.ShaderMaterial('shader', scene, route, options);
mat.backFaceCulling = false;
mat.setTexture('map', texture.texture);
 

shader code is below

BABYLON.Effect.ShadersStore["customVertexShader"]=                "precision highp float;\r\n"+
    "// Attributes\r\n"+
    "attribute vec3 position;\r\n"+
    "attribute vec2 uv;\r\n"+
    "attribute vec4 color;\r\n"+

    "// Uniforms\r\n"+
    "uniform mat4 worldViewProjection;\r\n"+

    "// Varying\r\n"+
    "varying vec2 vUv;\r\n"+
    "varying vec4 vColor;\r\n"+

    "void main() {\r\n"+
    "    vUv = uv;\r\n"+
    "    vColor = color;\r\n"+
    "    vec4 p = vec4( position, 1. );\r\n"+
    "    gl_Position = worldViewProjection * p;\r\n"+
    "}\r\n";

  BABYLON.Effect.ShadersStore["customFragmentShader"]=                "precision highp float;\r\n"+

    "varying vec2 vUv;\r\n"+
    "varying vec4 vColor;\r\n"+

    "uniform sampler2D map;\r\n"+

    "void main(void) {\r\n"+
    "    gl_FragColor = texture2D(map, vUv)*vColor;\r\n"+
    "}\r\n";

but results are different.

before vs after

611568086_2018-10-319_26_55.png.bf5d2257da99725c24ec0028273a9b0a.png297484443_2018-10-319_27_19.png.0f5a0edd4ea707c920c2d71b95832059.png

how to make shaderMaterial color like standardMaterial color?

Link to comment
Share on other sites

Hi, @Blax

My project is not usual. mixing 2d and 3d.

so entire meshes use only diffuseTexture, opacityTexture and ambientColor without light.

basically, meshes use StandardMaterial.

and now shaderMaterial is used only for character.

but new trial of shaderMaterial shows lighter color than before.

 

Link to comment
Share on other sites

I'm using ImageProcessingPostProcess for brightness of scene.

and configure it with .exposure property.

by default, ImageProcessingPostProcess makes brighter than non-use even set exposure to 1.

in my case it does not affect meshes with ambientColor, under exposure value 1 of postprocess.

and it does affect with exposure less than 1.

it works well before.

but now, shaderMaterial is affected by ImageProcessingPostProcess exposure 1.

https://playground.babylonjs.com/#H05KJ1#3

so, please let me know if there are any method to change brightness of entire scene.

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