Esempio n. 1
0
        void FinalProcess()
        {
            App.Current.Dispatcher.Invoke(() =>
            {
                if (mesh == null)
                {
                    return;
                }

                CreateBufferIfNeeded();

                mesh.Mat = mat;

                float rx = (float)rotationX * ((float)Math.PI / 180.0f);
                float ry = (float)rotationY * ((float)Math.PI / 180.0f);
                float rz = (float)rotationZ * ((float)Math.PI / 180.0f);

                Quaternion rot      = Quaternion.FromEulerAngles(rx, ry, rz);
                Matrix4 rotation    = Matrix4.CreateFromQuaternion(rot);
                Matrix4 translation = Matrix4.CreateTranslation(xOffset, yOffset, zOffset);
                Matrix4 scale       = Matrix4.CreateScale(scaleX, scaleY, scaleZ);

                Matrix4 view = rotation * Matrix4.CreateTranslation(0, 0, -cameraZoom);
                Vector3 pos  = Vector3.Normalize((view * new Vector4(0, 0, 1, 1)).Xyz) * cameraZoom;

                GLTextuer2D albedo    = (inputAlbedo.HasInput) ? (GLTextuer2D)inputAlbedo.Input.Data : null;
                GLTextuer2D metallic  = (inputMetallic.HasInput) ? (GLTextuer2D)inputMetallic.Input.Data : null;
                GLTextuer2D roughness = (inputRoughness.HasInput) ? (GLTextuer2D)inputRoughness.Input.Data : null;
                GLTextuer2D normal    = (inputNormal.HasInput) ? (GLTextuer2D)inputNormal.Input.Data : null;
                GLTextuer2D heightm   = (inputHeight.HasInput) ? (GLTextuer2D)inputHeight.Input.Data : null;
                GLTextuer2D occlusion = (inputOcclusion.HasInput) ? (GLTextuer2D)inputOcclusion.Input.Data : null;

                UI3DPreview v = UI3DPreview.Instance;

                if (v != null)
                {
                    mesh.IrradianceMap = HdriManager.Irradiance;
                    mesh.PrefilterMap  = HdriManager.Prefiltered;

                    if (albedo == null)
                    {
                        albedo = v.defaultDarkGray;
                    }
                    if (metallic == null)
                    {
                        metallic = v.defaultBlack;
                    }
                    if (roughness == null)
                    {
                        roughness = v.defaultBlack;
                    }
                    if (heightm == null)
                    {
                        heightm = v.defaultWhite;
                    }
                    if (occlusion == null)
                    {
                        occlusion = v.defaultWhite;
                    }
                    if (normal == null)
                    {
                        normal = v.defaultBlack;
                    }
                }

                mat.Albedo    = albedo;
                mat.Height    = heightm;
                mat.Normal    = normal;
                mat.Metallic  = metallic;
                mat.Occlusion = occlusion;
                mat.Roughness = roughness;

                mesh.View           = view;
                mesh.CameraPosition = pos;
                mesh.Projection     = Proj;

                mesh.Tiling = new Vector2(meshtileX, meshtileY);

                //TRS
                mesh.Model = scale * translation;

                //light position currently doesn't do anything
                //just setting values to a default
                mesh.LightPosition = new Vector3(0, 0, 0);
                mesh.LightColor    = new Vector3(1, 1, 1);

                processor.TileX = tileX;
                processor.TileY = tileY;
                processor.Mesh  = mesh;
                processor.Process(width, height, buffer);
                processor.Complete();

                Updated();
                Output.Data = buffer;
                Output.Changed();
            });
        }
Esempio n. 2
0
        void Process()
        {
            if (mesh == null)
            {
                return;
            }

            CreateBufferIfNeeded();

            mesh.Mat = mat;

            float rx = (float)this.rotation.X * ((float)Math.PI / 180.0f);
            float ry = (float)this.rotation.Y * ((float)Math.PI / 180.0f);
            float rz = (float)this.rotation.Z * ((float)Math.PI / 180.0f);

            Quaternion rot         = Quaternion.FromEulerAngles(rx, ry, rz);
            Matrix4    rotation    = Matrix4.CreateFromQuaternion(rot);
            Matrix4    translation = Matrix4.CreateTranslation(position.X, position.Y, position.Z);
            Matrix4    scale       = Matrix4.CreateScale(this.scale.X, this.scale.Y, this.scale.Z);

            Matrix4 view = rotation * Matrix4.CreateTranslation(0, 0, -cameraZoom);
            Vector3 pos  = Vector3.Normalize((view * new Vector4(0, 0, 1, 1)).Xyz) * cameraZoom;

            GLTextuer2D albedo    = (inputAlbedo.HasInput) ? (GLTextuer2D)inputAlbedo.Reference.Data : null;
            GLTextuer2D metallic  = (inputMetallic.HasInput) ? (GLTextuer2D)inputMetallic.Reference.Data : null;
            GLTextuer2D roughness = (inputRoughness.HasInput) ? (GLTextuer2D)inputRoughness.Reference.Data : null;
            GLTextuer2D normal    = (inputNormal.HasInput) ? (GLTextuer2D)inputNormal.Reference.Data : null;
            GLTextuer2D heightm   = (inputHeight.HasInput) ? (GLTextuer2D)inputHeight.Reference.Data : null;
            GLTextuer2D occlusion = (inputOcclusion.HasInput) ? (GLTextuer2D)inputOcclusion.Reference.Data : null;
            GLTextuer2D thickness = (inputThickness.HasInput) ? (GLTextuer2D)inputThickness.Reference.Data : null;

            mesh.IrradianceMap = Irradiance;
            mesh.PrefilterMap  = Prefilter;

            if (albedo == null)
            {
                albedo = DefaultDarkGray;
            }
            if (metallic == null)
            {
                metallic = DefaultBlack;
            }
            if (roughness == null)
            {
                roughness = DefaultBlack;
            }
            if (heightm == null)
            {
                heightm = DefaultWhite;
            }
            if (occlusion == null)
            {
                occlusion = DefaultWhite;
            }
            if (normal == null)
            {
                normal = DefaultBlack;
            }
            if (thickness == null)
            {
                thickness = DefaultBlack;
            }

            mat.Albedo    = albedo;
            mat.Height    = heightm;
            mat.Normal    = normal;
            mat.Metallic  = metallic;
            mat.Occlusion = occlusion;
            mat.Roughness = roughness;
            mat.Thickness = thickness;

            mesh.View           = view;
            mesh.CameraPosition = pos;
            mesh.Projection     = Proj;

            mesh.Tiling = new Vector2(meshtileX, meshtileY);

            //TRS
            mesh.Model = scale * translation;

            //light position currently doesn't do anything
            //just setting values to a default
            mesh.LightPosition = new Vector3(0, 0, 0);
            mesh.LightColor    = new Vector3(1, 1, 1);

            processor.TileX = tileX;
            processor.TileY = tileY;
            processor.Mesh  = mesh;
            processor.Process(width, height, buffer);
            processor.Complete();

            Output.Data = buffer;
            TriggerTextureChange();
        }