Jump to content

[SOLVED] - BABYLON.SimpleMaterial Ligting


MackeyK24
 Share

Recommended Posts

Hey @Deltakosh, @Sebavan or @RaananW can i pick you guys brains for a sec...

I am trying to use the Simple Material with lighting support. But for some reason the 'BACK-SIDE' of the lighted surface is really black. This is the simple code i use to create a SimpleMaterial:

var tester:BABYLON.AbstractMesh = this.scene.getMeshByName("Tester Cube 3");
var material:BABYLON.SimpleMaterial = new BABYLON.SimpleMaterial("simpleMaterial", this.scene);
material.diffuseColor = BABYLON.Color3.White();
material.diffuseTexture = new BABYLON.Texture("/scenes/amiga.png", this.scene);
tester.material = material;

 

But take a look a t the Cube on the LEFT... That is using the BABYLON.SimpleMaterial and the Cube on the right with looks perfect is using a standard shader and material.

58b65fd9484ec_ScreenShot2017-02-28at7_40_43PM.thumb.png.e16d0fdd2d5b101f5c646f2d84a56bbf.png

 

Why is the back side too black when i thought SimpleMaterial supports the basic lighting workflow???

 

 

Note the Beautiful shadows ... One is BAKED using Lightmaps and the Other is realtime ... But the look beautiful :)

 

Link to comment
Share on other sites

3 hours ago, Sebavan said:

Check the ambient value, this does not exist on a simple mat. I guess you might have some in the standard

No Ambient values in Simple Material... Should i COPY/IMPLEMENT Ambient from default shader... Do i need the the AmbientTexture or would a base ambient color do??

 

I tried something like this already, where i tried to use a white hard coded baseAmbientColor of white... I DONT multiply baseAmbientColor.rgb *= LEVEL cause LEVEL is always 1 on texture by default... i think... Anyways i tried to include a white baseAmbientColor in the final composition but looks like the picture above... Black on backside:

 

void main(void)
			{
				#include<clipPlaneFragment>
				vec3 viewDirectionW = normalize(vEyePosition - vPositionW);

				// Base color
				vec4 baseColor = vec4(1., 1., 1., 1.);
				vec3 diffuseColor = _Color.rgb;

				// Alpha
				float alpha = _Color.a;

				#ifdef _MainTexDef
					baseColor = texture2D(_MainTex, _MainTexUV);
					#ifdef ALPHATEST
						if (baseColor.a < 0.4)
							discard;
					#endif
					baseColor.rgb *= _MainTexInfos.y;
				#endif

				#ifdef VERTEXCOLOR
					baseColor.rgb *= vColor.rgb;
				#endif

				// Ambient color
				vec3 baseAmbientColor = vec3(1., 1., 1.);

				// Normal
				#ifdef NORMAL
					vec3 normalW = normalize(vNormalW);
				#else
					vec3 normalW = vec3(1.0, 1.0, 1.0);
				#endif

				// Lighting
				vec3 diffuseBase = vec3(0., 0., 0.);
				lightingInfo info;
				float shadow = 1.;
				float glossiness = 0.;
				#include<lightFragment>[0..maxSimultaneousLights]

				#ifdef VERTEXALPHA
					alpha *= vColor.a;
				#endif

				// Final Composition
				vec3 finalDiffuse = clamp(diffuseBase * diffuseColor + vAmbientColor, 0.0, 1.0) * baseColor.rgb;
				vec4 color = vec4(finalDiffuse * baseAmbientColor, alpha);
				#include<fogFragment>
				gl_FragColor = color;
			}
			#endif //FRAGMENT-END 

 

Here is my who;e shader file with VERTEX and FRAGMENT sections:

 

AmigaShader.shader

 

Link to comment
Share on other sites

42 minutes ago, RaananW said:

Might be a shadow issue as well? I assume the shadow generated is the left one. Can you try disabling the shadow and see what happens?

Without static or realtime shadow... I think @Sebavan is right about the ambient but I'm not too sure how to best include AMBIENT support in the simple shader...

 

But here is shot with out ANY shadows:

58b6b4c96df49_ScreenShot2017-03-01at1_45_44AM.thumb.png.6b2ac5e007a534d166d235b0311f616a.png

Link to comment
Share on other sites

1 hour ago, Deltakosh said:

This is because the simplematerial is only about diffuse. It is not really intended to be used. It is here mostly for educational purposes.

 

If you want you can as @Sebavan mentioned add code for ambient lightning

 Found and Fixed issue... First of all my Toolkit uses a new BABYLON.UniversalMateral for use as general purpose CYOS type deal...

The UnivseralShader is basically a copy of Standard Material merged with the Custom property map features from the shader material with the component life cycle to control you shader from tiny little shader controller scripts (just like the mesh, light and camera scripts from toolkit)...  I can now pickup the entire standard (default.fx) shader pipeline for all unity supported material  property like _MainTex, _BumpMap etc... that map to the UniversalMaterial diffuse bump etc... PLUS all the custom property map features from the shader material.. so can easily add runtime properties using UniversalMaterial.setfloat setTexture etc...

Now i am picking up everything from standard shader pipeline ... Also Unity was using a very dark Ambient Specular Color... Had to change because babylon we want color like white for HemisphericLight specular color... Fixed that too... Now is working great so far :)

 

 

Link to comment
Share on other sites

7 hours ago, Deltakosh said:

This is because the simplematerial is only about diffuse. It is not really intended to be used. It is here mostly for educational purposes.

 

If you want you can as @Sebavan mentioned add code for ambient lightning

hey @Deltakosh

After fixing lighting issues and use Ambient Light (Hemispheric Light) diffuse color to white the lighting shows up on cubes but as a side affect since the ambient diffuse color is white the shadows LIGHTEN up quite a bit... If i go darker ambient diffuse color the shadows are richer nut dark on cubes...

Should the Shadow color take into ambient diffuse since we have shadow generator to control the darkness of shadow... Should the shadow part AFTER the ambient part in the shader fragment section??? 

take a look at the very light shadows now with ambient diffuse color set to white:

 

58b75e6edf508_ScreenShot2017-03-01at1_50_47PM.thumb.png.e668a48837ac46ab7633a4bc29ad5c3a.png

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