예제 #1
0
        GameObject GetPBRModel(string meshFileName, string albedoMapFile, string normalMapFile, string metallicMapFile, string roughnessMapFile)
        {
            DefaultMesh mesh = contentLoader.Load <DefaultMesh>(meshFileName);
            VAO         geom = VAOLoader.FromMesh(mesh, renderer.GetPBRShader());
            GameObject  go   = new GameObject();
            PBRMaterial mat  = new PBRMaterial();

            go.mesh     = geom;
            go.material = mat;
            //mat.metal = 1.0f;
            //mat.metal = 0f;
            mat.roughness = 0;
            if (albedoMapFile != null)
            {
                ITexture2D albedoMap = contentLoader.Load <ITexture2D>(albedoMapFile);
                mat.albedoMap = albedoMap;
            }
            if (normalMapFile != null && normalMapFile != "")
            {
                ITexture2D normalMap = contentLoader.Load <ITexture2D>(normalMapFile);
                mat.normalMap = normalMap;
            }
            if (metallicMapFile != null)
            {
                ITexture2D metallicMap = contentLoader.Load <ITexture2D>(metallicMapFile);
                mat.metallicMap = metallicMap;
            }
            if (roughnessMapFile != null)
            {
                ITexture2D roughnessMap = contentLoader.Load <ITexture2D>(roughnessMapFile);
                mat.roughnessMap = roughnessMap;
            }
            return(go);
        }
예제 #2
0
        private static void CleanUp()
        {
            if (MateriaMainWindow.Instance != null)
            {
                MateriaMainWindow.Instance.CleanUp(null, true);
            }

            //clear material and shader caches
            PBRMaterial.ReleaseBRDF();
            ImageProcessor.ReleaseAll();
            Material.Material.ReleaseAll();

            //release gl view
            if (UI3DPreview.Instance != null)
            {
                UI3DPreview.Instance.Release();
            }

            if (UIPreviewPane.Instance != null)
            {
                UIPreviewPane.Instance.Release();
            }

            ViewContext.Dispose();
        }
예제 #3
0
    public IEnumerator BeCreatedProperly()
    {
        DCLTexture texture =
            TestHelpers.CreateDCLTexture(scene, Utils.GetTestsAssetsPath() + "/Images/atlas.png");

        yield return(texture.routine);

        PBRMaterial matPBR = TestHelpers.CreateEntityWithPBRMaterial(scene,
                                                                     new PBRMaterial.Model
        {
            albedoTexture = texture.id,
            metallic      = 0,
            roughness     = 1,
        },
                                                                     out DecentralandEntity entity);

        yield return(matPBR.routine);

        Assert.IsTrue(entity.meshRootGameObject != null,
                      "Every entity with a shape should have the mandatory 'Mesh' object as a child");

        var meshRenderer = entity.meshRootGameObject.GetComponent <MeshRenderer>();

        Assert.IsTrue(meshRenderer != null, "MeshRenderer must exist");

        var assignedMaterial = meshRenderer.sharedMaterial;

        Assert.IsTrue(meshRenderer != null, "MeshRenderer.sharedMaterial must be the same as assignedMaterial");
        Assert.AreEqual(assignedMaterial, matPBR.material, "Assigned material");

        var loadedTexture = meshRenderer.sharedMaterial.GetTexture("_BaseMap");

        Assert.IsTrue(loadedTexture != null, "Texture must be loaded");
        Assert.AreEqual(texture.texture, loadedTexture, "Texture data must be correct");
    }
예제 #4
0
    public IEnumerator NotDestroySharedTextureWhenDisposed()
    {
        DCLTexture texture =
            TestHelpers.CreateDCLTexture(scene, Utils.GetTestsAssetsPath() + "/Images/atlas.png");

        yield return(texture.routine);

        PBRMaterial mat = TestHelpers.CreateEntityWithPBRMaterial(scene,
                                                                  new PBRMaterial.Model
        {
            albedoTexture = texture.id,
            metallic      = 0,
            roughness     = 1,
        },
                                                                  out DecentralandEntity entity1);

        yield return(mat.routine);

        PBRMaterial mat2 = TestHelpers.CreateEntityWithPBRMaterial(scene,
                                                                   new PBRMaterial.Model
        {
            albedoTexture = texture.id,
            metallic      = 0,
            roughness     = 1,
        },
                                                                   out DecentralandEntity entity2);

        yield return(mat2.routine);

        TestHelpers.SharedComponentDispose(mat);
        Assert.IsTrue(texture.texture != null, "Texture should persist because is used by the other material!!");
    }
예제 #5
0
    public IEnumerator AlphaTextureShouldWork()
    {
        yield return(InitVisualTestsScene("PBRMaterialVisualTests_AlphaTextureShouldWork"));

        DCLTexture texture = TestHelpers.CreateDCLTexture(scene, Utils.GetTestsAssetsPath() + "/Images/alphaTexture.png");

        yield return(texture.routine);

        Vector3 camTarget = new Vector3(5, 2, 5);

        VisualTestHelpers.RepositionVisualTestsCamera(VisualTestController.i.camera, camTarget - new Vector3(2, -1, 2), camTarget);

        PBRMaterial matPBR = TestHelpers.CreateEntityWithPBRMaterial(scene, new PBRMaterial.Model
        {
            albedoTexture    = texture.id,
            transparencyMode = 2,
            albedoColor      = Color.blue
        }, camTarget, out IDCLEntity entity);

        yield return(matPBR.routine);


        yield return(new WaitForAllMessagesProcessed());

        yield return(VisualTestHelpers.TakeSnapshot());
    }
    public IEnumerator AlbedoTexture_AlbedoAlpha(float alpha)
    {
        yield return(InitVisualTestsScene($"PBRMaterialVisualTests_AlbedoTexture_AlbedoAlpha_{alpha.ToString(CultureInfo.InvariantCulture)}"));

        VisualTestHelpers.SetSSAOActive(true);

        Vector3 camTarget = new Vector3(5, 1, 5);

        VisualTestHelpers.RepositionVisualTestsCamera(VisualTestController.i.camera, new Vector3(4.6f, 1.8f, 0.6f), camTarget);

        DCLTexture texture = TestHelpers.CreateDCLTexture(scene, TestAssetsUtils.GetPath() + "/Images/avatar.png");

        yield return(texture.routine);

        PlaneShape plane       = TestHelpers.CreateEntityWithPlaneShape(scene, new Vector3(5, 1, 5), true);
        IDCLEntity planeEntity = plane.attachedEntities.FirstOrDefault();

        TestHelpers.SetEntityTransform(scene, planeEntity, new Vector3(5, 1, 5), Quaternion.Euler(0, 0, 180), Vector3.one * 3);
        PBRMaterial planeMaterial = TestHelpers.AttachPBRMaterialToEntity(scene, planeEntity, new PBRMaterial.Model
        {
            transparencyMode = 2,
            albedoTexture    = texture.id,
            albedoColor      = new Color(1, 1, 1, alpha)
        });

        yield return(plane.routine);

        yield return(planeMaterial.routine);

        yield return(null);

        yield return(VisualTestHelpers.TakeSnapshot());
    }
예제 #7
0
        public static VrmProtobuf.Material PBRToGltf(this PBRMaterial pbr, string name, List <Texture> textures)
        {
            var material = pbr.ToGltf(name, textures);

            // TODO: PBR params
            return(material);
        }
예제 #8
0
        public ForwardPBR(PBRMaterial material)
        {
#if DESKTOP
            MaxLightCount = 8;
#else
            MaxLightCount = 64;
#endif

            _material = material;
        }
예제 #9
0
        public static PBRMaterial PBRFromGltf(GltfMaterial material, List <Texture> textures)
        {
            var self = new PBRMaterial(material.name);

            self.LoadCommonParams(material, textures);

            //
            // pbr
            //
            var pbr = material.pbrMetallicRoughness;

            // metallic roughness
            self.MetallicFactor  = pbr.metallicFactor;
            self.RoughnessFactor = pbr.roughnessFactor;
            var metallicRoughnessTexture = pbr.metallicRoughnessTexture;

            if (metallicRoughnessTexture != null)
            {
                self.MetallicRoughnessTexture = textures[metallicRoughnessTexture.index];
            }
            //
            // emissive
            //
            if (material.emissiveFactor != null)
            {
                self.EmissiveFactor = new Vector3(
                    material.emissiveFactor[0], material.emissiveFactor[1], material.emissiveFactor[2]);
            }
            var emissiveTexture = material.emissiveTexture;

            if (emissiveTexture != null)
            {
                self.EmissiveTexture = textures[emissiveTexture.index];
            }
            //
            // normal
            //
            var normalTexture = material.normalTexture;

            if (normalTexture != null)
            {
                self.NormalTexture = textures[normalTexture.index];
            }
            //
            // occlusion
            //
            var occlusionTexture = material.occlusionTexture;

            if (occlusionTexture != null)
            {
                self.OcclusionTexture = textures[occlusionTexture.index];
            }

            return(self);
        }
예제 #10
0
        public static PBRMaterial CreateEntityWithPBRMaterial(ParcelScene scene, PBRMaterial.Model model, Vector3 position,
                                                              out DecentralandEntity entity)
        {
            InstantiateEntityWithShape <BoxShape, BoxShape.Model>(scene, CLASS_ID.BOX_SHAPE, position,
                                                                  out entity);
            PBRMaterial material =
                SharedComponentCreate <PBRMaterial, PBRMaterial.Model>(scene, CLASS_ID.PBR_MATERIAL, model);

            SharedComponentAttach(material, entity);
            return(material);
        }
예제 #11
0
        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            foreach (UIGraph g in graphs)
            {
                if (g.Modified && !g.ReadOnly)
                {
                    var result = MessageBox.Show(this, g.Graph.Name + " has been modified. Do you want to save the changes?", "Save Changes", MessageBoxButton.YesNoCancel);
                    if (result == MessageBoxResult.Yes)
                    {
                        HandleSave(g);
                    }
                    else if (result == MessageBoxResult.Cancel)
                    {
                        e.Cancel = true;
                        return;
                    }
                }
            }

            //release all opengl content
            foreach (UIGraph g in graphs)
            {
                g.Release();
            }

            graphs.Clear();

            //clear material and shader caches
            PBRMaterial.ReleaseBRDF();
            ImageProcessor.ReleaseAll();
            Material.Material.ReleaseAll();

            //release gl view
            if (UI3DPreview.Instance != null)
            {
                UI3DPreview.Instance.Release();
            }

            if (UIPreviewPane.Instance != null)
            {
                UIPreviewPane.Instance.Release();
            }

            ViewContext.Dispose();

            //save layout
            SaveLayout();
        }
예제 #12
0
    public HelixMeshPoser(RobotSystem robot, PBRMaterial material, ObservableElement3DCollection robotModels)
    {
        _default     = robot.DefaultPose;
        _robotModels = robotModels;

        foreach (var joint in _default.Meshes.SelectMany(m => m))
        {
            var model = new MeshGeometryModel3D
            {
                Geometry         = ToWPF(joint),
                Material         = material,
                Transform        = Transform3D.Identity,
                IsThrowingShadow = true
            };

            robotModels.Add(model);
        }
    }
    [Explicit, Category("Explicit")] //Enable the test once we properly render opaque objects with SSAO behind transparents
    public IEnumerator TransparentObjectsAndSSAO()
    {
        yield return(InitVisualTestsScene("PBRMaterialVisualTests_TransparentObjectsAndSSAO"));

        VisualTestHelpers.SetSSAOActive(true);

        Vector3 camTarget = new Vector3(5, 1, 5);

        VisualTestHelpers.RepositionVisualTestsCamera(VisualTestController.i.camera, new Vector3(4.6f, 1.8f, 0.6f), camTarget);

        PlaneShape plane       = TestHelpers.CreateEntityWithPlaneShape(scene, new Vector3(5, 1, 5), true);
        IDCLEntity planeEntity = plane.attachedEntities.FirstOrDefault();

        TestHelpers.SetEntityTransform(scene, planeEntity, new Vector3(5, 1, 5), Quaternion.identity, Vector3.one * 3);
        PBRMaterial planeMaterial = TestHelpers.AttachPBRMaterialToEntity(scene, planeEntity, new PBRMaterial.Model {
            alphaTest = 1, transparencyMode = 1, albedoColor = Vector4.one
        });

        yield return(plane.routine);

        yield return(planeMaterial.routine);

        BoxShape    box1         = TestHelpers.CreateEntityWithBoxShape(scene, new Vector3(4, 1, 6), true);
        PBRMaterial box1Material = TestHelpers.AttachPBRMaterialToEntity(scene, box1.attachedEntities.FirstOrDefault(), new PBRMaterial.Model {
            transparencyMode = 0, albedoColor = Color.blue
        });

        yield return(box1.routine);

        yield return(box1Material.routine);

        BoxShape    box2         = TestHelpers.CreateEntityWithBoxShape(scene, new Vector3(5, 1, 6.5f), true);
        PBRMaterial box2Material = TestHelpers.AttachPBRMaterialToEntity(scene, box2.attachedEntities.FirstOrDefault(), new PBRMaterial.Model {
            transparencyMode = 0, albedoColor = Color.red
        });

        yield return(box2.routine);

        yield return(box2Material.routine);

        yield return(null);

        yield return(VisualTestHelpers.TakeSnapshot());
    }
예제 #14
0
    public IEnumerator WorkCorrectlyWhenAttachedBeforeShape()
    {
        DecentralandEntity entity = TestHelpers.CreateSceneEntity(scene);

        DCLTexture dclTexture = TestHelpers.CreateDCLTexture(
            scene,
            Utils.GetTestsAssetsPath() + "/Images/atlas.png",
            DCLTexture.BabylonWrapMode.CLAMP,
            FilterMode.Bilinear);

        yield return(dclTexture.routine);

        PBRMaterial mat = TestHelpers.SharedComponentCreate <PBRMaterial, PBRMaterial.Model>(scene,
                                                                                             CLASS_ID.PBR_MATERIAL,
                                                                                             new PBRMaterial.Model
        {
            albedoTexture = dclTexture.id,
            metallic      = 0,
            roughness     = 1,
        }
                                                                                             );

        yield return(mat.routine);

        TestHelpers.SharedComponentAttach(mat, entity);

        SphereShape shape = TestHelpers.SharedComponentCreate <SphereShape, SphereShape.Model>(scene,
                                                                                               CLASS_ID.SPHERE_SHAPE,
                                                                                               new SphereShape.Model {
        });

        yield return(shape.routine);

        TestHelpers.SharedComponentAttach(shape, entity);

        Assert.IsTrue(entity.meshRootGameObject != null);
        Assert.IsTrue(entity.meshRootGameObject.GetComponent <MeshRenderer>() != null);
        Assert.AreEqual(entity.meshRootGameObject.GetComponent <MeshRenderer>().sharedMaterial, mat.material);
    }
예제 #15
0
            internal Material(XmlElement xml)
            {
                id   = xml.GetAttribute("id");
                name = xml.GetAttribute("name");

                var effectId = xml["instance_effect"].GetAttribute("url").TrimStart('#');

                var lambert_xml = xml.OwnerDocument.DocumentElement["library_effects"].SelectSingleNode($"*[@id='{effectId}']")["profile_COMMON"]["technique"]["lambert"];

                vec4 parse_color(string t)
                {
                    var n = t.Split(' ').Select(x => float.Parse(x));

                    return(new vec4(n.ElementAt(0), n.ElementAt(1), n.ElementAt(2), n.ElementAt(3)));
                }

                pbrMaterial = new PBRMaterial {
                    albedo    = parse_color(lambert_xml["diffuse"].InnerText).xyz,
                    emission  = parse_color(lambert_xml["emission"].InnerText).xyz,
                    roughness = 1 - float.Parse(lambert_xml["reflectivity"]?.InnerText ?? "0")
                };
            }
예제 #16
0
    public IEnumerator DefaultMissingValuesPropertyOnUpdate()
    {
        Color color1;

        ColorUtility.TryParseHtmlString("#808080", out color1);

        // 1. Create component with non-default configs
        PBRMaterial PBRMaterialComponent = TestHelpers.SharedComponentCreate <PBRMaterial, PBRMaterial.Model>(scene,
                                                                                                              CLASS_ID.PBR_MATERIAL,
                                                                                                              new PBRMaterial.Model
        {
            albedoColor       = color1,
            metallic          = 0.3f,
            directIntensity   = 0.1f,
            specularIntensity = 3f
        });

        yield return(PBRMaterialComponent.routine);

        // 2. Check configured values
        Assert.AreEqual(color1, PBRMaterialComponent.model.albedoColor);
        Assert.AreEqual(0.3f, PBRMaterialComponent.model.metallic);
        Assert.AreEqual(0.1f, PBRMaterialComponent.model.directIntensity);
        Assert.AreEqual(3f, PBRMaterialComponent.model.specularIntensity);

        // 3. Update component with missing values
        scene.SharedComponentUpdate(PBRMaterialComponent.id, JsonUtility.ToJson(new PBRMaterial.Model {
        }));

        yield return(PBRMaterialComponent.routine);

        // 4. Check defaulted values
        Assert.AreEqual(Color.white, PBRMaterialComponent.model.albedoColor);
        Assert.AreEqual(0.5f, PBRMaterialComponent.model.metallic);
        Assert.AreEqual(1, PBRMaterialComponent.model.directIntensity);
        Assert.AreEqual(1f, PBRMaterialComponent.model.specularIntensity);
    }
예제 #17
0
        public BaseDisposable SharedComponentCreate(string id, string name, int classId)
        {
            SceneController.i.OnMessageDecodeStart?.Invoke("ComponentCreated");
            sharedComponentCreatedMessage.id      = id;
            sharedComponentCreatedMessage.name    = name;
            sharedComponentCreatedMessage.classId = classId;
            SceneController.i.OnMessageDecodeEnds?.Invoke("ComponentCreated");

            BaseDisposable disposableComponent;

            if (disposableComponents.TryGetValue(sharedComponentCreatedMessage.id, out disposableComponent))
            {
                return(disposableComponent);
            }

            BaseDisposable newComponent = null;

            switch ((CLASS_ID)sharedComponentCreatedMessage.classId)
            {
            case CLASS_ID.BOX_SHAPE:
            {
                newComponent = new BoxShape(this);
                break;
            }

            case CLASS_ID.SPHERE_SHAPE:
            {
                newComponent = new SphereShape(this);
                break;
            }

            case CLASS_ID.CONE_SHAPE:
            {
                newComponent = new ConeShape(this);
                break;
            }

            case CLASS_ID.CYLINDER_SHAPE:
            {
                newComponent = new CylinderShape(this);
                break;
            }

            case CLASS_ID.PLANE_SHAPE:
            {
                newComponent = new PlaneShape(this);
                break;
            }

            case CLASS_ID.GLTF_SHAPE:
            {
                newComponent = new GLTFShape(this);
                break;
            }

            case CLASS_ID.NFT_SHAPE:
            {
                newComponent = new NFTShape(this);
                break;
            }

            case CLASS_ID.OBJ_SHAPE:
            {
                newComponent = new OBJShape(this);
                break;
            }

            case CLASS_ID.BASIC_MATERIAL:
            {
                newComponent = new BasicMaterial(this);
                break;
            }

            case CLASS_ID.PBR_MATERIAL:
            {
                newComponent = new PBRMaterial(this);
                break;
            }

            case CLASS_ID.AUDIO_CLIP:
            {
                newComponent = new DCLAudioClip(this);
                break;
            }

            case CLASS_ID.TEXTURE:
            {
                newComponent = new DCLTexture(this);
                break;
            }

            case CLASS_ID.UI_INPUT_TEXT_SHAPE:
            {
                newComponent = new UIInputText(this);
                break;
            }

            case CLASS_ID.UI_FULLSCREEN_SHAPE:
            case CLASS_ID.UI_SCREEN_SPACE_SHAPE:
            {
                if (uiScreenSpace == null)
                {
                    newComponent = new UIScreenSpace(this);
                }

                break;
            }

            case CLASS_ID.UI_CONTAINER_RECT:
            {
                newComponent = new UIContainerRect(this);
                break;
            }

            case CLASS_ID.UI_SLIDER_SHAPE:
            {
                newComponent = new UIScrollRect(this);
                break;
            }

            case CLASS_ID.UI_CONTAINER_STACK:
            {
                newComponent = new UIContainerStack(this);
                break;
            }

            case CLASS_ID.UI_IMAGE_SHAPE:
            {
                newComponent = new UIImage(this);
                break;
            }

            case CLASS_ID.UI_TEXT_SHAPE:
            {
                newComponent = new UIText(this);
                break;
            }

            case CLASS_ID.VIDEO_CLIP:
            {
                newComponent = new DCLVideoClip(this);
                break;
            }

            case CLASS_ID.VIDEO_TEXTURE:
            {
                newComponent = new DCLVideoTexture(this);
                break;
            }

            case CLASS_ID.FONT:
            {
                newComponent = new DCLFont(this);
                break;
            }

            default:
                Debug.LogError($"Unknown classId");
                break;
            }

            if (newComponent != null)
            {
                newComponent.id = sharedComponentCreatedMessage.id;
                disposableComponents.Add(sharedComponentCreatedMessage.id, newComponent);

                if (state != State.READY)
                {
                    disposableNotReady.Add(id);
                }
            }

            return(newComponent);
        }
예제 #18
0
    public IEnumerator AffectDifferentEntitiesCorrectly()
    {
        // Create first entity with material
        PBRMaterial material1 = TestHelpers.CreateEntityWithPBRMaterial(scene,
                                                                        new PBRMaterial.Model
        {
            metallic = 0.3f,
        }, out DecentralandEntity entity1);

        Assert.IsTrue(entity1.meshRootGameObject != null,
                      "Every entity with a shape should have the mandatory 'Mesh' object as a child");

        // Create second entity with material
        PBRMaterial material2 = TestHelpers.CreateEntityWithPBRMaterial(scene,
                                                                        new PBRMaterial.Model
        {
            metallic = 0.66f,
        }, out DecentralandEntity entity2);

        Assert.IsTrue(entity2.meshRootGameObject != null,
                      "Every entity with a shape should have the mandatory 'Mesh' object as a child");

        // Create third entity and assign 1st material
        var boxShape = TestHelpers.CreateEntityWithBoxShape(scene, Vector3.zero);
        var entity3  = boxShape.attachedEntities.First();

        scene.SharedComponentAttach(
            entity3.entityId,
            material1.id
            );

        Assert.IsTrue(entity3.meshRootGameObject != null,
                      "Every entity with a shape should have the mandatory 'Mesh' object as a child");

        // Check renderers material references
        var firstRenderer  = entity1.meshRootGameObject.GetComponent <MeshRenderer>();
        var secondRenderer = entity2.meshRootGameObject.GetComponent <MeshRenderer>();
        var thirdRenderer  = entity3.meshRootGameObject.GetComponent <MeshRenderer>();

        Assert.IsTrue(firstRenderer.sharedMaterial != secondRenderer.sharedMaterial,
                      "1st and 2nd entities should have different materials");
        Assert.IsTrue(firstRenderer.sharedMaterial == thirdRenderer.sharedMaterial,
                      "1st and 3rd entities should have the same material");

        // Check material properties before updating them
        Assert.AreApproximatelyEqual(0.3f, firstRenderer.sharedMaterial.GetFloat("_Metallic"));
        Assert.AreApproximatelyEqual(0.66f, secondRenderer.sharedMaterial.GetFloat("_Metallic"));

        // Update material properties
        scene.SharedComponentUpdate(material1.id, JsonUtility.ToJson(new PBRMaterial.Model
        {
            metallic = 0.95f
        }));

        Assert.IsTrue(firstRenderer.sharedMaterial != null);

        yield return(material1.routine);

        Assert.IsTrue(firstRenderer.sharedMaterial != null);
        // Check material properties after updating them
        Assert.AreApproximatelyEqual(0.95f, firstRenderer.sharedMaterial.GetFloat("_Metallic"));
        Assert.AreApproximatelyEqual(0.66f, secondRenderer.sharedMaterial.GetFloat("_Metallic"));
    }
예제 #19
0
        public override void Initialize()
        {
            base.Initialize();

            Destroy(_directionalLight);

            // Light
            var padding = 5;
            var colors  = new Color[] {
                Color.Red,
                Color.Green,
                Color.Blue,
                Color.Yellow,
                Color.Pink,
                Color.Cyan,
                Color.Purple,
                Color.Olive
            };

            var pos = new Vector3[]
            {
                new Vector3(padding, 16, padding),
                new Vector3(padding, 16, -padding),
                new Vector3(-padding, 16, padding),
                new Vector3(-padding, 16, -padding),
                new Vector3(0, 16, -padding * 2),
                new Vector3(0, 16, padding * 2),
                new Vector3(-padding * 2, 16, 0),
                new Vector3(padding * 2, 16, 0)
            };

            for (var i = 0; i < 8; i++)
            {
                var lightGo = GameObjectFactory.CreateLight(LightType.Point, colors[i], 0.5f, 1024);
                lightGo.Transform.LocalRotation = new Vector3(0.0f, 0.5f, 0);
                lightGo.Transform.LocalPosition = pos[i];

                var light = lightGo.GetComponent <Light>();
                light.Radius = 25;
                light.ShadowGenerator.ShadowStrength = 1;
                light.ShadowGenerator.ShadowBias     = 0.01f;

                if (i == 0)
                {
                    light.AddComponent <ShadowMapViewer>();
                }
                else
                {
                    light.ShadowEnabled = false;
                }

                var ligthSphere = lightGo.AddComponent <MeshRenderer>();
                ligthSphere.Mesh = new SphereMesh(0.5f, 16);
                ligthSphere.Mesh.Build();
                ligthSphere.CastShadow    = true;
                ligthSphere.ReceiveShadow = false;

                var sphereMaterial = new StandardMaterial();
                sphereMaterial.DiffuseColor    = colors[i];
                sphereMaterial.EmissiveColor   = colors[i];
                sphereMaterial.EmissiveEnabled = true;
                ligthSphere.Material           = sphereMaterial;

                ligthSphere.AddComponent <LightMover>();
                ligthSphere.AddComponent <LightSwitcher>();
                ligthSphere.AddComponent <SinMovement>();
            }

            // Terrain
            var terrainMaterial = new StandardMaterial();

            terrainMaterial.MainTexture   = Application.Content.Load <Texture2D>("Textures/Terrain/Sand");
            terrainMaterial.NormalTexture = Application.Content.Load <Texture2D>("Textures/Terrain/Sand_Normal");
            terrainMaterial.Shininess     = 500;
            terrainMaterial.Tiling        = new Vector2(32);

            var terrainGo = GameObjectFactory.CreateTerrain();
            var terrain   = terrainGo.GetComponent <Terrain>();

            terrain.Geometry.Size = new Vector3(4);
            terrain.Geometry.Build();
            terrain.Flatten();
            terrain.Renderer.Material      = terrainMaterial;
            terrain.Renderer.ReceiveShadow = false;
            terrain.Renderer.CastShadow    = false;

            // Model
            var model = Application.Content.Load <Model>("Models/Quandtum/Quandtum");
            var mesh  = model.ToMeshRenderers(this);

            mesh.Transform.LocalScale = new Vector3(0.25f);
            mesh.Transform.Rotate(0, 0, -MathHelper.PiOver2);

            var renderer = mesh.GetComponentInChildren <MeshRenderer>();

            renderer.CastShadow           = true;
            renderer.ReceiveShadow        = true;
            renderer.Transform.LocalScale = new Vector3(0.035f);
            renderer.Transform.Rotate(0, -MathHelper.PiOver2, 0);
            renderer.Transform.Translate(-0.1f, 0, 0);

            var pbrMaterial = new PBRMaterial()
            {
                MainTexture = Application.Content.Load <Texture2D>("Models/Quandtum/textures/Turret-Diffuse"),
                NormalMap   = Application.Content.Load <Texture2D>("Models/Quandtum/textures/Turret-Normal"),
                EmissiveMap = Application.Content.Load <Texture2D>("Models/Quandtum/textures/Turret-Emission")
            };

            pbrMaterial.CreateRMSFromValues(0.1f, 0.7f);

            renderer.Material = pbrMaterial;

            _camera.AddComponent <VRPlayerEnabler>();
        }
예제 #20
0
        public static PBRMaterial PBRFromGltf(VrmProtobuf.Material material, List <Texture> textures)
        {
            var self = new PBRMaterial(material.Name);

            self.LoadCommonParams(material, textures);

            //
            // pbr
            //
            var pbr = material.PbrMetallicRoughness;

            // metallic roughness
            self.MetallicFactor = pbr.MetallicFactor.HasValue
                ? pbr.MetallicFactor.Value
                : 1.0f // gltf default
            ;
            self.RoughnessFactor = pbr.RoughnessFactor.HasValue
                ? pbr.RoughnessFactor.Value
                : 1.0f // gltf default
            ;
            var metallicRoughnessTexture = pbr.MetallicRoughnessTexture;

            if (metallicRoughnessTexture != null &&
                metallicRoughnessTexture.Index.TryGetValidIndex(textures.Count, out int metallicRoughnessTextureIndex))
            {
                self.MetallicRoughnessTexture = textures[metallicRoughnessTextureIndex];
            }
            //
            // emissive
            //
            if (material.EmissiveFactor.Count > 0)
            {
                self.EmissiveFactor = new Vector3(
                    material.EmissiveFactor[0],
                    material.EmissiveFactor[1],
                    material.EmissiveFactor[2]);
            }
            var emissiveTexture = material.EmissiveTexture;

            if (emissiveTexture != null &&
                emissiveTexture.Index.TryGetValidIndex(textures.Count, out int emissiveTextureIndex))
            {
                self.EmissiveTexture = textures[emissiveTextureIndex];
            }
            //
            // normal
            //
            var normalTexture = material.NormalTexture;

            if (normalTexture != null &&
                normalTexture.Index.TryGetValidIndex(textures.Count, out int normalTextureIndex))
            {
                self.NormalTexture = textures[normalTextureIndex];
            }
            //
            // occlusion
            //
            var occlusionTexture = material.OcclusionTexture;

            if (occlusionTexture != null &&
                occlusionTexture.Index.TryGetValidIndex(textures.Count, out int occlusionTextureIndex))
            {
                self.OcclusionTexture = textures[occlusionTextureIndex];
            }

            return(self);
        }
예제 #21
0
        public void CleanUp(System.ComponentModel.CancelEventArgs e = null, bool crash = false)
        {
            if (!crash)
            {
                for (int i = 0; i < graphs.Count; i++)
                {
                    UIGraph g = graphs[i];
                    if (g.Modified && !g.ReadOnly)
                    {
                        var result = MessageBox.Show(this, g.GraphName + " has been modified. Do you want to save the changes?", "Save Changes", MessageBoxButton.YesNoCancel);
                        if (result == MessageBoxResult.Yes)
                        {
                            HandleSave(g);
                        }
                        else if (result == MessageBoxResult.Cancel)
                        {
                            if (e != null)
                            {
                                e.Cancel = true;
                                return;
                            }
                        }
                    }
                }
            }

            recent.Save();

            //release all opengl content
            foreach (UIGraph g in graphs)
            {
                if (crash)
                {
                    if (!string.IsNullOrEmpty(g.FilePath))
                    {
                        if (g.FromArchive)
                        {
                            if (string.IsNullOrEmpty(g.FromArchivePath))
                            {
                                g.Save(g.FilePath + ".recovery.mtga", true);
                            }
                            else
                            {
                                g.Save(g.FromArchivePath + ".recovery.mtga", true);
                            }
                        }
                        else
                        {
                            g.Save(g.FilePath + ".recovery.mtg", true);
                        }
                    }
                }

                g.DeleteTempArchiveData();
                g.Release();
            }

            graphs.Clear();

            FontManager.Release();

            //clear material and shader caches
            PBRMaterial.ReleaseBRDF();
            ImageProcessor.ReleaseAll();
            Material.Material.ReleaseAll();

            //release gl view
            if (UI3DPreview.Instance != null)
            {
                UI3DPreview.Instance.Release();
            }

            if (UIPreviewPane.Instance != null)
            {
                UIPreviewPane.Instance.Release();
            }

            ViewContext.Dispose();
        }
예제 #22
0
 public virtual void AttachTo(PBRMaterial material)
 {
     AddRefCount();
 }
예제 #23
0
 public virtual void DetachFrom(PBRMaterial material)
 {
     RemoveRefCount();
 }
예제 #24
0
        public MainViewModel()
        {
            EffectsManager = new DefaultEffectsManager();
            // camera setup
            Camera = new PerspectiveCamera
            {
                Position         = new Point3D(0, -2000, 400),
                LookDirection    = new Vector3D(0, 2000, 0),
                UpDirection      = UpDirection,
                FarPlaneDistance = 5000000,
            };


            // setup lighting
            //SkyboxTexture = LoadFileToMemory("Cubemap_Grandcanyon.dds");
            LightDirection = new Vector3D(0, -0.5, -1);
            LightDirection.Normalize();
            SetHeadLight();

            AmbientLightColor     = Colors.White * 1000;
            DirectionalLightColor = Color.FromScRgb(1, 10, 10, 10);
            BackgroundColor       = Color.FromRgb(40, 40, 40);

            // model transform
            ModelTransform = Transform3D.Identity;
            //var r = new System.Windows.Media.Media3D.AxisAngleRotation3D(new Vector3D(0, 0, 1), 90);
            //EnvironmentTransform = new System.Windows.Media.Media3D.RotateTransform3D(r);

            // model materials
            var material = new PBRMaterial();

            material.AlbedoColor            = new Color4(0.8f, 0.4f, 0.05f, 1f);
            material.MetallicFactor         = 0.2;
            material.ReflectanceFactor      = 0.8;
            material.RenderEnvironmentMap   = false;
            material.AmbientOcclusionFactor = 1;

            // floor plane grid
            Grid          = LineBuilder.GenerateGrid(new Vector3(0, 0, 1), -10, 10, -10, 10);
            GridColor     = Color.FromRgb(100, 100, 100);
            GridTransform = new System.Windows.Media.Media3D.ScaleTransform3D(100, 100, 100);

            // commands
            UpZCommand = new RelayCommand(_ => { Log = "test switch"; });

            // robot program
            var test = new TestProgram();

            Program = test.Program;
            Log     = Program.Errors.Count == 0 ? Program.RobotSystem.Name : string.Join(" ", Program.Errors);

            // make robot
            var cell   = Program.RobotSystem as Robots.RobotCell;
            var group  = cell.MechanicalGroups.First();
            var meshes = group.Joints.Select(j => j.Mesh).Prepend(group.Robot.BaseMesh);

            _origins = group.Joints.Select(j => j.Plane).Prepend(group.Robot.BasePlane).ToArray();

            foreach (var joint in meshes)
            {
                var model = new MeshGeometryModel3D();
                model.Geometry         = joint.ToWPF();
                model.Material         = material;
                model.Transform        = Transform3D.Identity;
                model.IsThrowingShadow = true;
                RobotModels.Add(model);
            }

            // timer
            _timer = new Timer(Tick, null, Timeout.Infinite, 0);
        }
    void Start()
    {
        var sceneController = FindObjectOfType <SceneController>();
        var scenesToLoad    = (Resources.Load("TestJSON/SceneLoadingTest") as TextAsset).text;

        sceneController.UnloadAllScenes();
        sceneController.LoadParcelScenes(scenesToLoad);

        var scene = sceneController.loadedScenes["0,0"];

        DCLTexture dclAtlasTexture = TestHelpers.CreateDCLTexture(
            scene,
            Utils.GetTestsAssetsPath() + "/Images/atlas.png",
            DCLTexture.BabylonWrapMode.CLAMP,
            FilterMode.Bilinear);

        DCLTexture dclAvatarTexture = TestHelpers.CreateDCLTexture(
            scene,
            Utils.GetTestsAssetsPath() + "/Images/avatar.png",
            DCLTexture.BabylonWrapMode.CLAMP,
            FilterMode.Bilinear);


        DecentralandEntity entity;

        TestHelpers.CreateEntityWithBasicMaterial(
            scene,
            new BasicMaterial.Model
        {
            texture = dclAtlasTexture.id,
        },
            out entity);

        TestHelpers.CreateEntityWithPBRMaterial(scene,
                                                new PBRMaterial.Model
        {
            albedoTexture = dclAvatarTexture.id,
            metallic      = 0,
            roughness     = 1,
        },
                                                out entity);

        PBRMaterial mat = TestHelpers.CreateEntityWithPBRMaterial(scene,
                                                                  new PBRMaterial.Model
        {
            albedoTexture = dclAvatarTexture.id,
            metallic      = 1,
            roughness     = 1,
            alphaTexture  = dclAvatarTexture.id,
        },
                                                                  out entity);

        // Re-assign last PBR material to new entity
        BoxShape      shape = TestHelpers.CreateEntityWithBoxShape(scene, new Vector3(5, 1, 2));
        BasicMaterial m     =
            TestHelpers.SharedComponentCreate <BasicMaterial, BasicMaterial.Model>(scene, CLASS_ID.BASIC_MATERIAL);

        Color color1;

        ColorUtility.TryParseHtmlString("#FF9292", out color1);

        // Update material attached to 2 entities, adding albedoColor
        scene.SharedComponentUpdate(m.id, JsonUtility.ToJson(new DCL.Components.PBRMaterial.Model
        {
            albedoTexture = dclAvatarTexture.id,
            metallic      = 1,
            roughness     = 1,
            alphaTexture  = dclAvatarTexture.id,
            albedoColor   = color1
        }));
    }
예제 #26
0
        public BaseDisposable SharedComponentCreate(string id, int classId)
        {
            BaseDisposable disposableComponent;

            if (disposableComponents.TryGetValue(id, out disposableComponent))
            {
                return(disposableComponent);
            }

            BaseDisposable newComponent = null;

            switch ((CLASS_ID)classId)
            {
            case CLASS_ID.BOX_SHAPE:
            {
                newComponent = new BoxShape(this);
                break;
            }

            case CLASS_ID.SPHERE_SHAPE:
            {
                newComponent = new SphereShape(this);
                break;
            }

            case CLASS_ID.CONE_SHAPE:
            {
                newComponent = new ConeShape(this);
                break;
            }

            case CLASS_ID.CYLINDER_SHAPE:
            {
                newComponent = new CylinderShape(this);
                break;
            }

            case CLASS_ID.PLANE_SHAPE:
            {
                newComponent = new PlaneShape(this);
                break;
            }

            case CLASS_ID.GLTF_SHAPE:
            {
                newComponent = new GLTFShape(this);
                break;
            }

            case CLASS_ID.NFT_SHAPE:
            {
                newComponent = new NFTShape(this);
                break;
            }

            case CLASS_ID.OBJ_SHAPE:
            {
                newComponent = new OBJShape(this);
                break;
            }

            case CLASS_ID.BASIC_MATERIAL:
            {
                newComponent = new BasicMaterial(this);
                break;
            }

            case CLASS_ID.PBR_MATERIAL:
            {
                newComponent = new PBRMaterial(this);
                break;
            }

            case CLASS_ID.AUDIO_CLIP:
            {
                newComponent = new DCLAudioClip(this);
                break;
            }

            case CLASS_ID.TEXTURE:
            {
                newComponent = new DCLTexture(this);
                break;
            }

            case CLASS_ID.UI_INPUT_TEXT_SHAPE:
            {
                newComponent = new UIInputText(this);
                break;
            }

            case CLASS_ID.UI_FULLSCREEN_SHAPE:
            case CLASS_ID.UI_SCREEN_SPACE_SHAPE:
            {
                if (GetSharedComponent <UIScreenSpace>() == null)
                {
                    newComponent = new UIScreenSpace(this);
                }

                break;
            }

            case CLASS_ID.UI_CONTAINER_RECT:
            {
                newComponent = new UIContainerRect(this);
                break;
            }

            case CLASS_ID.UI_SLIDER_SHAPE:
            {
                newComponent = new UIScrollRect(this);
                break;
            }

            case CLASS_ID.UI_CONTAINER_STACK:
            {
                newComponent = new UIContainerStack(this);
                break;
            }

            case CLASS_ID.UI_IMAGE_SHAPE:
            {
                newComponent = new UIImage(this);
                break;
            }

            case CLASS_ID.UI_TEXT_SHAPE:
            {
                newComponent = new UIText(this);
                break;
            }

            case CLASS_ID.VIDEO_CLIP:
            {
                newComponent = new DCLVideoClip(this);
                break;
            }

            case CLASS_ID.VIDEO_TEXTURE:
            {
                newComponent = new DCLVideoTexture(this);
                break;
            }

            case CLASS_ID.FONT:
            {
                newComponent = new DCLFont(this);
                break;
            }

            case CLASS_ID.NAME:
            {
                newComponent = new DCLName(this);
                break;
            }

            case CLASS_ID.LOCKED_ON_EDIT:
            {
                newComponent = new DCLLockedOnEdit(this);
                break;
            }

            case CLASS_ID.VISIBLE_ON_EDIT:
            {
                newComponent = new DCLVisibleOnEdit(this);
                break;
            }

            default:
                Debug.LogError($"Unknown classId");
                break;
            }

            if (newComponent != null)
            {
                newComponent.id = id;
                disposableComponents.Add(id, newComponent);
                OnAddSharedComponent?.Invoke(id, newComponent);
            }

            return(newComponent);
        }
예제 #27
0
        public static VrmProtobuf.Material PBRToGltf(this PBRMaterial pbr, List <Texture> textures)
        {
            var material = pbr.ToGltf(textures);

            // MetallicRoughness
            material.PbrMetallicRoughness.BaseColorFactor.Add(pbr.BaseColorFactor.ToFloat4());
            if (pbr.BaseColorTexture != null)
            {
                material.PbrMetallicRoughness.BaseColorTexture = new VrmProtobuf.TextureInfo
                {
                    Index = textures.IndexOfNullable(pbr.BaseColorTexture.Texture),
                };
            }
            material.PbrMetallicRoughness.MetallicFactor  = pbr.MetallicFactor;
            material.PbrMetallicRoughness.RoughnessFactor = pbr.RoughnessFactor;
            if (pbr.MetallicRoughnessTexture != null)
            {
                material.PbrMetallicRoughness.MetallicRoughnessTexture = new VrmProtobuf.TextureInfo
                {
                    Index = textures.IndexOfNullable(pbr.MetallicRoughnessTexture),
                };
            }

            // Normal
            if (pbr.NormalTexture != null)
            {
                material.NormalTexture = new VrmProtobuf.MaterialNormalTextureInfo
                {
                    Index = textures.IndexOfNullable(pbr.NormalTexture),
                    Scale = pbr.NormalTextureScale
                };
            }

            // Occlusion
            if (pbr.OcclusionTexture != null)
            {
                material.OcclusionTexture = new VrmProtobuf.MaterialOcclusionTextureInfo
                {
                    Index    = textures.IndexOfNullable(pbr.OcclusionTexture),
                    Strength = pbr.OcclusionTextureStrength,
                };
            }

            // Emissive
            if (pbr.EmissiveTexture != null)
            {
                material.EmissiveTexture = new VrmProtobuf.TextureInfo
                {
                    Index = textures.IndexOfNullable(pbr.EmissiveTexture),
                };
            }
            material.EmissiveFactor.Add(pbr.EmissiveFactor.X);
            material.EmissiveFactor.Add(pbr.EmissiveFactor.Y);
            material.EmissiveFactor.Add(pbr.EmissiveFactor.Z);

            // AlphaMode
            var alphaMode = (pbr.AlphaMode == AlphaModeType.BLEND_ZWRITE)?AlphaModeType.BLEND: pbr.AlphaMode;

            material.AlphaMode = EnumUtil.Cast <VrmProtobuf.Material.Types.alphaModeType>(alphaMode);

            // AlphaCutoff
            material.AlphaCutoff = pbr.AlphaCutoff;

            // DoubleSided
            material.DoubleSided = pbr.DoubleSided;

            return(material);
        }
예제 #28
0
        public void CleanUp(System.ComponentModel.CancelEventArgs e = null, bool crash = false)
        {
            if (!crash)
            {
                for (int i = 0; i < graphs.Count; ++i)
                {
                    UIGraph        g   = graphs[i];
                    LayoutDocument doc = documents[i];
                    if (g.Modified && !g.ReadOnly)
                    {
                        var result = MessageBox.Show(this, g.GraphName + " " + Properties.Resources.TITLE_HAS_BEEN_MODIFIED, Properties.Resources.TITLE_SAVE_CHANGES, MessageBoxButton.YesNoCancel);
                        if (result == MessageBoxResult.Yes)
                        {
                            HandleSave(g, doc);
                        }
                        else if (result == MessageBoxResult.Cancel)
                        {
                            if (e != null)
                            {
                                e.Cancel = true;
                                return;
                            }
                        }
                    }
                }
            }

            recent.Save();

            //release all opengl content
            foreach (UIGraph g in graphs)
            {
                if (crash)
                {
                    if (!string.IsNullOrEmpty(g.FilePath))
                    {
                        if (g.FromArchive)
                        {
                            if (string.IsNullOrEmpty(g.FromArchivePath))
                            {
                                g.Save(g.FilePath + ".recovery.mtga", true);
                            }
                            else
                            {
                                g.Save(g.FromArchivePath + ".recovery.mtga", true);
                            }
                        }
                        else
                        {
                            g.Save(g.FilePath + ".recovery.mtg", true);
                        }
                    }
                }

                g.DeleteTempArchiveData();
                g.Release();
            }

            graphs.Clear();

            FontManager.Release();

            FunctionGraph.ReleaseShaderBuffer();
            //clear material and shader caches
            PBRMaterial.ReleaseBRDF();
            ImageProcessor.ReleaseAll();
            Material.Material.ReleaseAll();

            //release gl view
            if (UI3DPreview.Instance != null)
            {
                UI3DPreview.Instance.Release();
            }

            if (UIPreviewPane.Instance != null)
            {
                UIPreviewPane.Instance.Release();
            }

            ViewContext.Dispose();
        }
예제 #29
0
        public void AttachModelList(List <Object3D> objs)
        {
            for (int i = 0; i < objs.Count; ++i)
            {
                var ob        = objs[i];
                var vertColor = new Color4((float)i / objs.Count, 0, 1 - (float)i / objs.Count, 1);
                ob.Geometry.Colors = new HelixToolkit.Wpf.SharpDX.Core.Color4Collection(Enumerable.Repeat(vertColor, ob.Geometry.Positions.Count));
                ob.Geometry.UpdateOctree();
                ob.Geometry.UpdateBounds();

                context.Post((o) =>
                {
                    var scaleTransform = new Media3D.ScaleTransform3D(15, 15, 15);
                    var s = new MeshGeometryModel3D
                    {
                        Geometry         = ob.Geometry,
                        CullMode         = SharpDX.Direct3D11.CullMode.Back,
                        IsThrowingShadow = true,
                        Transform        = scaleTransform
                    };

                    var diffuseMaterial     = new DiffuseMaterial();
                    PBRMaterial pbrMaterial = null;
                    if (ob.Material is PhongMaterialCore p)
                    {
                        var phong = p.ConvertToPhongMaterial();
                        phong.RenderEnvironmentMap   = true;
                        phong.RenderShadowMap        = true;
                        phong.RenderSpecularColorMap = false;
                        s.Material = phong;
                        diffuseMaterial.DiffuseColor = p.DiffuseColor;
                        diffuseMaterial.DiffuseMap   = p.DiffuseMap;
                        pbrMaterial = new PBRMaterial()
                        {
                            AlbedoColor          = p.DiffuseColor,
                            AlbedoMap            = p.DiffuseMap,
                            NormalMap            = p.NormalMap,
                            RMAMap               = p.SpecularColorMap,
                            RenderShadowMap      = true,
                            RenderEnvironmentMap = true,
                        };
                    }
                    //if (ob.Transform != null && ob.Transform.Count > 0)
                    //{
                    //    s.Instances = ob.Transform;
                    //}
                    this.Model1.Add(s);

                    Model2.Add(new MeshGeometryModel3D()
                    {
                        Geometry         = ob.Geometry,
                        CullMode         = SharpDX.Direct3D11.CullMode.Back,
                        IsThrowingShadow = true,
                        Material         = NormalMaterial,
                        Transform        = scaleTransform
                    });

                    ModelNormalVector.Add(new MeshGeometryModel3D()
                    {
                        Geometry         = ob.Geometry,
                        CullMode         = SharpDX.Direct3D11.CullMode.Back,
                        IsThrowingShadow = true,
                        Material         = NormalVectorMaterial,
                        Transform        = scaleTransform
                    });
                    Model3.Add(new MeshGeometryModel3D()
                    {
                        Geometry         = ob.Geometry,
                        CullMode         = SharpDX.Direct3D11.CullMode.Back,
                        IsThrowingShadow = true,
                        Material         = diffuseMaterial,
                        Transform        = scaleTransform
                    });

                    Model4.Add(new MeshGeometryModel3D()
                    {
                        Geometry         = ob.Geometry,
                        CullMode         = SharpDX.Direct3D11.CullMode.Back,
                        IsThrowingShadow = true,
                        Material         = PositionMaterial,
                        Transform        = scaleTransform
                    });

                    Model5.Add(new MeshGeometryModel3D()
                    {
                        Geometry         = ob.Geometry,
                        CullMode         = SharpDX.Direct3D11.CullMode.Back,
                        IsThrowingShadow = true,
                        Material         = VertMaterial,
                        Transform        = scaleTransform
                    });

                    Model6.Add(new MeshGeometryModel3D()
                    {
                        Geometry         = ob.Geometry,
                        CullMode         = SharpDX.Direct3D11.CullMode.Back,
                        IsThrowingShadow = true,
                        Material         = ColorStripeMaterial,
                        Transform        = scaleTransform
                    });

                    Model7.Add(new MeshGeometryModel3D
                    {
                        Geometry         = ob.Geometry,
                        CullMode         = SharpDX.Direct3D11.CullMode.Back,
                        IsThrowingShadow = true,
                        Transform        = scaleTransform,
                        Material         = pbrMaterial
                    });
                }, null);
            }
        }
예제 #30
0
        public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
        {
            base.OnGUI(materialEditor, properties);

            //isTrim = EditorGUILayout.Toggle("Color base", isTrim);
            //if (isTrim)
//            EditorGUILayout.LabelField("基本参数");
//            EditorGUI.indentLevel++;
//            {
            DrawSlider(_Brightness, "亮度", 0, 2);
//                DrawSlider(_Saturation, "饱和度",0, 2);
//                DrawSlider(_Contrast, "对比度",0, 2);
//            }
//            EditorGUI.indentLevel--;
//            EditorGUILayout.Space();
            DrawSlider(_ShadowStrength, _ShadowStrength.displayName);
            // Texture
            materialEditor.TexturePropertySingleLine(new GUIContent(_MainTex.displayName), _MainTex, _Color);
            materialEditor.TexturePropertySingleLine(new GUIContent(_NormalMap.displayName), _NormalMap);
            if (_NormalMap.textureValue)
            {
                EditorGUI.indentLevel++;
                DrawSlider(_BumpScale, _BumpScale.displayName, 0, 2);
                EditorGUI.indentLevel--;
            }
            materialEditor.DefaultShaderProperty(_DetailNormalMap, _DetailNormalMap.displayName);
            if (_DetailNormalMap.textureValue)
            {
                EditorGUI.indentLevel++;
                DrawSlider(_DetailBumpScale, _DetailBumpScale.displayName, 0, 2);
                EditorGUI.indentLevel--;
            }
            materialEditor.TexturePropertySingleLine(new GUIContent(_MaskTex.displayName), _MaskTex);
            materialEditor.TexturePropertySingleLine(new GUIContent(_EvoCube.displayName), _EvoCube);
            materialEditor.TexturePropertySingleLine(new GUIContent(_AOTex.displayName), _AOTex);
            if (_AOTex.textureValue)
            {
                EditorGUI.indentLevel++;
                DrawSlider(_AOScale, _AOScale.displayName, 0, 1);
                EditorGUI.indentLevel--;
            }
            EditorGUILayout.Space();
            materialEditor.ColorProperty(_SpecularTint, _SpecularTint.displayName);
            materialEditor.ColorProperty(_SheenTint, _SheenTint.displayName);
            EditorGUILayout.Space();
            // PBRMaterial
            PBRMaterial pbrMat = (PBRMaterial)_material.GetFloat("_Mat");

            _materialEditor.ShaderProperty(_PBRMat, _PBRMat.displayName);
            int index = (int)pbrMat;

            _materialEditor.ShaderProperty(_GGX, _GGX.displayName);
            DrawVector(_Metallic, index);
            DrawVector(_Roughness, index);
            DrawVector(_Specular, index);
            DrawVector(_Sheen, index);
            DrawVector(_Clearcoat, index);
            DrawVector(_ClearcoatGloss, index);
            DrawVector(_Subsurface, index);
            DrawVector(_Anisotropic, index);

            EditorGUILayout.Space();

            //isDetail = EditorGUILayout.Toggle("Detail", isDetail);
            materialEditor.TexturePropertySingleLine(new GUIContent(_DetailTex.displayName), _DetailTex);
            if (_DetailTex.textureValue)
            {
                EditorGUI.indentLevel++;
//                {

//                    DrawSlider(_DetailThickness, _DetailThickness.displayName);
                //DrawSlider(_DetailBumpScale, _DetailBumpScale.displayName, 0, 10);
//                    DrawSlider(_DetailScale, _DetailScale.displayName, 0, 1);
//                }
                EditorGUI.indentLevel--;
            }

            //isDrawSSS = EditorGUILayout.Toggle("SSS", isDrawSSS);
            //_SSSEnable.floatValue = isDrawSSS ? 1 : 0;
            _materialEditor.ShaderProperty(_ScatterThickness, _ScatterThickness.displayName);
            if (pbrMat == PBRMaterial.Skin && _ScatterThickness.floatValue > 0)
            {
                materialEditor.TexturePropertySingleLine(new GUIContent(_NoiseTex.displayName), _NoiseTex);
                materialEditor.TexturePropertySingleLine(new GUIContent(_ThicknessTex.displayName), _ThicknessTex);
                //_materialEditor.ShaderProperty(_SSSLightDir,_SSSLightDir.displayName);
                DrawAngle(_SSSLightDir);
                _materialEditor.ShaderProperty(_ScatterNum, _ScatterNum.displayName);
                _materialEditor.ShaderProperty(_SSSColor, _SSSColor.displayName);
                _materialEditor.ShaderProperty(_ScatterPower, _ScatterPower.displayName);
                _materialEditor.ShaderProperty(_ScatterScale, _ScatterScale.displayName);
                _materialEditor.ShaderProperty(_ScatterRadius, _ScatterRadius.displayName);
            }
        }