Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Applying a spcular material to a mesh node has limited effect
#1
Hi. Really impressed with what I'm seeing with this.

I'm trying to apply lighting to my view. It has one point light in it. A sphere node with a specular material will reflect the light correctly. 

How do I do this with a standard mesh? If I create a cube, with all the texture normals facing the correct way, the colour of the mesh is uniform no matter which direction I view it from. The light has no effect on the texture colour. There is no ambient light in my view. What am I missing?

            StandardMesh? standardMesh = new StandardMesh(ArrayPositionNormalTextureVertex, ArrayVertexInts, name: "StandardMesh");

            var specularMaterial = new StandardMaterial(Colors.Silver)
            {
                SpecularPower = 16,
                SpecularColor = Colors.Silver
            };
            MeshModelNode? roofMeshModelNode = new MeshModelNode(standardMesh, specularMaterial, name: "SampleMeshModel");
            roofMeshModelNode.BackMaterial = specularMaterial;
            sharpEngineSceneView.Scene.RootNode.Add(roofMeshModelNode);
#2
I am glad to hear that you are impressed with the Ab4d.SharpEngine.

I tried to reproduce your problem, but in my case, the specular material was correctly rendered.

For example, I opened the Materials/MaterialsSample.cs file in the Ab4d.SharpEngine.Samples.Common project and added the following into the OnCreateScene method after the _boxMesh initialization:

PHP Code:
        
        
var specularMaterial = new StandardMaterial(Colors.Silver)
        {
            SpecularPower 16,
            SpecularColor Colors.Silver
        
};
        MeshModelNoderoofMeshModelNode = new MeshModelNode(_boxMeshspecularMaterialname"SampleMeshModel");
        roofMeshModelNode.BackMaterial specularMaterial;
        scene.RootNode.Add(roofMeshModelNode);

        
        scene
.Lights.Clear();
        scene.Lights.Add(new PointLight(new Vector3(05000)));

        if (targetPositionCamera != null)
            targetPositionCamera.ShowCameraLight ShowCameraLightType.Never;
        
        
return; 

I also commented the whole OnCreateLights method a few lines below.

This correctly renders the box with specular light:
   
   

The code above is almost the same as yours, except that it uses the MeshFactory.CreateBoxMesh to create the StandardMesh.

Therefore, I assume that the normals in your mesh are not correctly defined.

You can test that by stopping at a breakpoint after the standardMesh is initialized and then in the Visual Studio immediate window run the following:
standardMesh.DumpDetails();


Please check your mesh. If you cannot find the cause of the problem, then please try to update one of the samples (for example MaterialsSample.cs) and attach the updated source code to this post so I can reproduce the problem.
Andrej Benedik
#3
Thankyou for that quick and helpful response. I am having to both learn C# and 3D graphics. I am finding ab4d easier than Helix. I can't see what is wrong with my normals, though that probably is the issue, so I shall export the mesh as an STL into a design program to make sure it is not displayed correctly there either.
  


Forum Jump:


Users browsing this thread:
1 Guest(s)