-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Recreate a standard material with NME #7405
Comments
+ a PBR material if possible? :D |
Not for 4.1 as some blocks will be missing but this is the goal for 4.2 |
I assume that the #ifdef parts of the shaders should be treated as regular "if" when converting to nme? So, for something like: #ifdef MULTIVIEW
if (gl_ViewID_OVR == 0u) {
gl_Position = viewProjection * worldPos;
} else {
gl_Position = viewProjectionR * worldPos;
}
#else
gl_Position = viewProjection * worldPos;
#endif we would create a Side question: I don't think gl_ViewID_OVR is available in the nme? And what about |
So we should not treat ALL the special cases. Multiview for instance is out of the equation. Let's chat here of the special cases but most of the time we will either ignore them or add special blocks later |
Ok, going for the vertex shader first. Should we support:
Here are all the defines we should handle:
Thanks! |
The reflectionMap should already be done by the reflection texture block No support for all the xxxDirectUV. the texture node handle that differently |
Ok thanks. I have an error I don't understand: https://nme.babylonjs.com/#JDCSVX#2 This one does work. Now, link the output of the normalWorld block to the
https://nme.babylonjs.com/#JDCSVX#3 It seems it should work? |
Here are my comments after creating the vertex shader:
#ifdef NONUNIFORMSCALING
normalWorld = transposeMat3(inverseMat3(normalWorld));
#endif as there are no
vTBN = mat3(finalWorld) * mat3(tbnTangent, tbnBitangent, tbnNormal); we can't construct a matrix based on 3 vectors? More generally, I think we need a special block in the nme for bump, as there are a number of specific functions called in the fragment code (cotangent_frame, parallaxOcclusion, etc)? If it can help: https://nme.babylonjs.com/#JDCSVX#4 |
|
Thanks. https://nme.babylonjs.com/#JDCSVX#5 It happened when connecting the output from "Perturb normal" to the input of "Reflection texture". If I connect the output from "Normal world" to the input of "Reflection texture", it does work. |
I also have an error with this one that uses morph targets: PG: https://www.babylonjs-playground.com/#HPV2TZ#41 |
Can you create an issue for each? |
Ok I fixed the #JDCSVX#5 |
And I fixed the second :) Nightly incoming |
Cool, thanks! |
I think there are too many calculations done in the vertex shader for the reflection part compared to the existing standard shaders because I get this error when wiring the two sided lighting calculation (which uses gl_frontFacing):
https://nme.babylonjs.com/#6E8GQ2#1 In the existing standard vertex shader, there is only this code related to reflection: #if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)
vDirectionW = normalize(vec3(finalWorld * vec4(positionUpdated, 0.0)));
#endif |
Did you tried with the latest fix I did? I should have moved the bump computation to fragment only (like frontFacing block which is fragment only) |
Is the online nme updated with your changes? It still does not work for me:
|
Yes apparently we are facing a deployment issue (cc @sebavan ) |
This happens when you click on which node? |
Hum, I think it happened when I bound:
but I don't have the error anymore... Maybe it was a transient error.
I can't see the option in my local nme, have you already committed it? |
I added it in the list of tasks :D |
It should be the case: https://nme.babylonjs.com/#C39T6E |
It's a problem with the #define NORMAL / UV / ... not being set correctly I think.
var scrambleUp = function(data) {
for (index = 0; index < data.length; index ++) {
data[index] += 0.4 * Math.random();
}
}
var scrambleDown = function(data) {
for (index = 0; index < data.length; index ++) {
data[index] -= 0.4 * Math.random();
}
}
var createScene = function () {
// This creates a basic Babylon Scene object (non-mesh)
var scene = new BABYLON.Scene(engine);
// This creates and positions a free camera (non-mesh)
var camera = new BABYLON.ArcRotateCamera("camera1", 1.14, 1.13, 10, BABYLON.Vector3.Zero(), scene);
// This targets the camera to scene origin
camera.setTarget(BABYLON.Vector3.Zero());
// This attaches the camera to the canvas
camera.attachControl(canvas, true);
// This creates a light, aiming 0,1,0 - to the sky (non-mesh)
var light = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0, 1, 0), scene);
// Default intensity is 1. Let's dim the light a small amount
light.intensity = 0.7;
// Our built-in 'sphere' shape. Params: name, subdivs, size, scene
var sphere = BABYLON.Mesh.CreateSphere("sphere1", 16, 2, scene, true);
var materialSphere = new BABYLON.StandardMaterial("mat", scene);
materialSphere.diffuseTexture = new BABYLON.Texture("textures/misc.jpg", scene);
var nodeMaterial = new BABYLON.NodeMaterial("node material", scene, { emitComments: true });
scene.debugLayer.show({
embedMode: true
});
scene.debugLayer.select(nodeMaterial);
sphere.material = nodeMaterial;
var sphere2 = BABYLON.Mesh.CreateSphere("sphere2", 16, 2, scene);
sphere2.setEnabled(false);
sphere2.updateMeshPositions(scrambleUp);
/*var manager = new BABYLON.MorphTargetManager();
sphere.morphTargetManager = manager;
var target0 = BABYLON.MorphTarget.FromMesh(sphere2, "sphere2", 0.25);
manager.addTarget(target0);
angle = 0;
scene.registerBeforeRender(function() {
target0.influence = Math.sin(angle)*Math.sin(angle);
angle += 0.01;
})*/
return scene;
};
|
Also, I can't clamp a vector, the Clamp block assumes the input/output to be float: it should be like multiply and adapt to its input. |
Some comments/questions:
|
Another one: At the end of the fragment shader there is: #ifdef IMAGEPROCESSINGPOSTPROCESS
color.rgb = toLinearSpace(color.rgb);
#else
#ifdef IMAGEPROCESSING
color.rgb = toLinearSpace(color.rgb);
color = applyImageProcessing(color);
#endif
#endif We do have a ImageProcessing node but I can't see a node for "toLinearSpace"? |
Not required for stdmaterial
Correct
We need to create the block
We need to create the block |
Thanks for your answers. This one is annoying:
Do you think you can so something for it, or should I create 3 clamps, one for each component? (will need to do a Vector Splitter, 3 clamps and a Vector Merger). Going to bed now, so no hurry ;) |
The clamp is now autodetect ;D |
I LOVE THIS! I have always split and multi-clamped but consolidation for the win!! |
Also, it seems the alpha value of a |
Well can you please create one issue by problem? The discussion here makes it really complicated to track :) |
Thanks for creating the issues! |
All done ! |
Here it is: https://nme.babylonjs.com/#PRXLT5 PG to test with: https://playground.babylonjs.com/#ZCJ2QX I tried to make things as clearer as possible by making frames and moving them to limit line crossings, but I'm sure it's still possible to do better. I added a number of float-const-boolean to enable/disable some parts of the rendering (corresponding to I hope I did not make mistakes, I tried to closely follow the shader code and used namings as found in the code. I think the single most important thing to explain to people about this material is that it is a transparency material by defaut (so, don't write in the zbuffer - only sorted / don't cast shadows by default), because something is connected to |
This is PERFECT!!!! Here are the next steps for me:
|
Is it expected that to get the same texture orientation in the nme compared to using a StandardMaterial we have to rotate U and V coordinates by 180°? |
we should have the same orientation out of the box |
Also, if I'm not mistaken, there's no equivalent of the glossPower input of the Lights block in the standard material, so I must set it to 1 to be able to compare. |
Correct |
sure! just do a PR to add it |
Done. |
Here is the PG: |
This is PERFECT!!!! Thanks a lot buddy!!! Now a good doc explaining all of that and we call it done |
PR done for the updated doc. |
Congratulation buddy! this is perfect! Closing now! |
Just to bring you up to date: I've modify your opacity.png to make it more "realtime" compliant ;) |
Thanks, I'm working exclusively on desktop and 100ko is small for me :p |
it was more about power of two width & height, plus make it tiling ^^ |
Would be a fantastic demo for 4.1
The text was updated successfully, but these errors were encountered: