Ejemplo n.º 1
0
        /// <summary>
        /// 设置Lighting相关参数
        /// </summary>
        public static void SetLighting(LightingData lighting)
        {
            RenderSettings.skybox = lighting.skyboxMaterial;
            RenderSettings.sun    = lighting.sunSource;

            switch (lighting.Source)
            {
            case LightingType.Skybox:
                RenderSettings.ambientMode = UnityEngine.Rendering.AmbientMode.Skybox;
                //Skybox类型的参数设置
                RenderSettings.ambientIntensity = lighting.intensityMultiplier;
                break;

            case LightingType.Gradient:

                RenderSettings.ambientMode = UnityEngine.Rendering.AmbientMode.Trilight;
                //Gradient类型设置
                RenderSettings.ambientSkyColor     = lighting.skyColor;
                RenderSettings.ambientEquatorColor = lighting.equatorColor;
                RenderSettings.ambientGroundColor  = lighting.groundColor;

                break;

            case LightingType.Color:

                RenderSettings.ambientMode = UnityEngine.Rendering.AmbientMode.Flat;
                //Color类型
                RenderSettings.ambientSkyColor = lighting.ambientColor;
                break;
            }
        }
Ejemplo n.º 2
0
        public void ExportLightingData()
        {
            var extensions = new[]
            {
                new ExtensionFilter("Lighting settings", "scmlighting")
            };

            var path = StandaloneFileBrowser.SaveFilePanel("Export Lighting", DefaultPath, "", extensions);

            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            LightingData Data = new LightingData();

            Data.LightingMultiplier = Scmap.map.LightingMultiplier;
            Data.SunDirection       = Scmap.map.SunDirection;

            Data.SunAmbience     = Scmap.map.SunAmbience;
            Data.SunColor        = Scmap.map.SunColor;
            Data.ShadowFillColor = Scmap.map.ShadowFillColor;
            Data.SpecularColor   = Scmap.map.SpecularColor;

            Data.Bloom    = Scmap.map.Bloom;
            Data.FogColor = Scmap.map.FogColor;
            Data.FogStart = Scmap.map.FogStart;
            Data.FogEnd   = Scmap.map.FogEnd;

            string DataString = JsonUtility.ToJson(Data);

            File.WriteAllText(path, DataString);
            EnvPaths.SetLastPath(ExportPathKey, System.IO.Path.GetDirectoryName(path));
        }
Ejemplo n.º 3
0
        public void ImportLightingData()
        {
            var extensions = new[]
            {
                new ExtensionFilter("Lighting settings", "scmlighting")
            };

            var paths = StandaloneFileBrowser.OpenFilePanel("Import Lighting", EnvPaths.GetMapsPath(), extensions, false);


            if (paths.Length == 0 || string.IsNullOrEmpty(paths[0]))
            {
                return;
            }

            string       data         = File.ReadAllText(paths[0]);
            LightingData LightingData = UnityEngine.JsonUtility.FromJson <LightingData>(data);

            Scmap.map.LightingMultiplier = LightingData.LightingMultiplier;
            Scmap.map.SunDirection       = LightingData.SunDirection;

            Scmap.map.SunAmbience     = LightingData.SunAmbience;
            Scmap.map.SunColor        = LightingData.SunColor;
            Scmap.map.ShadowFillColor = LightingData.ShadowFillColor;
            Scmap.map.SpecularColor   = LightingData.SpecularColor;

            Scmap.map.Bloom    = LightingData.Bloom;
            Scmap.map.FogColor = LightingData.FogColor;
            Scmap.map.FogStart = LightingData.FogStart;
            Scmap.map.FogEnd   = LightingData.FogEnd;


            LoadValues();
        }
Ejemplo n.º 4
0
        protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider)
        {
            if (windowService == null)
            {
                throw new ArgumentNullException("windowService");
            }

            if (objectProvider == null)
            {
                throw new ArgumentNullException("objectProvider");
            }

            if (objectProvider.GetObject() is List <List <IntPoint> > polygons)
            {
                var vertexStorage = PlatingHelper.PolygonToVertexStorage(polygons);

                var polygonsMesh = VertexSourceToMesh.Extrude(vertexStorage, zHeight: 30);

                // Position
                var aabb = polygonsMesh.GetAxisAlignedBoundingBox();
                polygonsMesh.Transform(Matrix4X4.CreateTranslation(-aabb.Center));
                polygonsMesh.Transform(Matrix4X4.CreateScale(1.6 / aabb.XSize));

                var systemWindow = new SystemWindow(800, 600);
                var lighting     = new LightingData();

                //Debugger.Launch();
                systemWindow.AfterDraw += (s, e) =>
                {
                    var screenSpaceBounds = systemWindow.TransformToScreenSpace(systemWindow.LocalBounds);

                    WorldView world = new WorldView(screenSpaceBounds.Width, screenSpaceBounds.Height);
                    //world.Translate(new Vector3(0, 0, 0));
                    //world.Rotate(Quaternion.FromEulerAngles(new Vector3(rotateX, 0, 0)));

                    GLHelper.SetGlContext(world, screenSpaceBounds, lighting);
                    GLHelper.Render(polygonsMesh, Color.White);
                    GLHelper.UnsetGlContext();
                };

                using (var displayForm = new OpenGLSystemWindow()
                {
                    AggSystemWindow = systemWindow
                })
                {
                    //System.Diagnostics.Debugger.Launch();
                    windowService.ShowDialog(displayForm);
                }
            }
        }
Ejemplo n.º 5
0
        public LogoSpinner(GuiWidget widget, double scale = 1.6, double spinSpeed = 0.6, double yOffset = 0.5, double rotateX = -0.1)
        {
            // loading animation stuff
            LightingData lighting = new LightingData();

            Mesh logoMesh;

            using (var logoStream = StaticData.Instance.OpenStream(Path.Combine("Stls", "MH Logo.stl")))
            {
                logoMesh = StlProcessing.Load(logoStream, CancellationToken.None);
            }

            // Position
            var aabb = logoMesh.GetAxisAlignedBoundingBox();

            logoMesh.Transform(Matrix4X4.CreateTranslation(-aabb.Center));

            logoMesh.Transform(Matrix4X4.CreateScale(scale / aabb.XSize));

            var anglePerDraw = 1 / MathHelper.Tau * spinSpeed;
            var angle        = 0.0;

            widget.BeforeDraw += (s, e) =>
            {
                var       screenSpaceBounds = widget.TransformToScreenSpace(widget.LocalBounds);
                WorldView world             = new WorldView(screenSpaceBounds.Width, screenSpaceBounds.Height);
                world.Translate(new Vector3(0, yOffset, 0));
                world.Rotate(Quaternion.FromEulerAngles(new Vector3(rotateX, 0, 0)));

                GLHelper.SetGlContext(world, screenSpaceBounds, lighting);
                GLHelper.Render(logoMesh, this.MeshColor, Matrix4X4.CreateRotationY(angle), RenderTypes.Shaded);
                GLHelper.UnsetGlContext();
            };

            Animation spinAnimation = new Animation()
            {
                DrawTarget      = widget,
                FramesPerSecond = 20
            };

            spinAnimation.Update += (s, time) =>
            {
                if (this.SpinLogo)
                {
                    angle += anglePerDraw;
                }
            };
            spinAnimation.Start();
        }
Ejemplo n.º 6
0
        public static LightingData CreateLightingData(bool other)
        {
            string     goName = other ? "other_lightmap" : "main_lightmap";
            GameObject target = GameObject.Find(goName);

            if (target == null)
            {
                target = new GameObject(goName);
            }

            LightingData lightingData = target.GetComponent <LightingData>();

            if (lightingData == null)
            {
                lightingData = target.AddComponent <LightingData>();
            }

            //target.layer = 31;

            return(lightingData);
        }
Ejemplo n.º 7
0
        public static void AddStencilShaderProperties(PropertyCollector collector, SystemData systemData, LightingData lightingData, bool splitLighting)
        {
            bool ssrStencil = false;

            if (lightingData != null)
            {
                ssrStencil = systemData.surfaceType == SurfaceType.Opaque ? lightingData.receiveSSR : lightingData.receiveSSRTransparent;
                bool receiveSSROpaque      = lightingData.receiveSSR;
                bool receiveSSRTransparent = lightingData.receiveSSRTransparent;
                bool receiveDecals         = lightingData.receiveDecals;
                bool blendPreserveSpecular = lightingData.blendPreserveSpecular;

                // Don't add those property on Unlit
                collector.AddToggleProperty(kUseSplitLighting, splitLighting);
                collector.AddToggleProperty(kReceivesSSR, receiveSSROpaque);
                collector.AddToggleProperty(kReceivesSSRTransparent, receiveSSRTransparent);
                collector.AddToggleProperty(kEnableBlendModePreserveSpecularLighting, blendPreserveSpecular);
                collector.AddToggleProperty(kSupportDecals, receiveDecals);
            }

            // Configure render state
            BaseLitGUI.ComputeStencilProperties(ssrStencil, splitLighting, out int stencilRef, out int stencilWriteMask,
                                                out int stencilRefDepth, out int stencilWriteMaskDepth, out int stencilRefGBuffer, out int stencilWriteMaskGBuffer,
                                                out int stencilRefMV, out int stencilWriteMaskMV
                                                );

            // All these properties values will be patched with the material keyword update
            collector.AddIntProperty("_StencilRef", stencilRef);
            collector.AddIntProperty("_StencilWriteMask", stencilWriteMask);
            // Depth prepass
            collector.AddIntProperty("_StencilRefDepth", stencilRefDepth);             // Nothing
            collector.AddIntProperty("_StencilWriteMaskDepth", stencilWriteMaskDepth); // StencilUsage.TraceReflectionRay
            // Motion vector pass
            collector.AddIntProperty("_StencilRefMV", stencilRefMV);                   // StencilUsage.ObjectMotionVector
            collector.AddIntProperty("_StencilWriteMaskMV", stencilWriteMaskMV);       // StencilUsage.ObjectMotionVector
            // Distortion vector pass
            collector.AddIntProperty("_StencilRefDistortionVec", (int)StencilUsage.DistortionVectors);
            collector.AddIntProperty("_StencilWriteMaskDistortionVec", (int)StencilUsage.DistortionVectors);
            // Gbuffer
            collector.AddIntProperty("_StencilWriteMaskGBuffer", stencilWriteMaskGBuffer);
            collector.AddIntProperty("_StencilRefGBuffer", stencilRefGBuffer);
            collector.AddIntProperty("_ZTestGBuffer", 4);
        }
Ejemplo n.º 8
0
 public LightSystem(LightingData m_data)
 {
     this.m_data = m_data;
 }
 public static void SetUpLighting(LightingData l, Texture2D tex)
 {
     lights.SetUpLighting(l.LightPower, l.AmbientPower, l.Position, l.Target, tex, l.LightColor);
 }
 public static void SetUpLighting(LightingData l)
 {
     lights.SetUpLighting(l.LightPower, l.AmbientPower, l.Position, l.Target, l.LightColor);
 }
Ejemplo n.º 11
0
        private Color GetColor(float3 pixelPos)
        {
            // Create ray from camera position to pixel position
            // e + t * d (where e is origin)
            float3 d = normalize(pixelPos - CameraPosition);
            float3 e = CameraPosition;

            // Find closest intersection point
            float              closestt = 1000000;
            float3             closestIntersectionPoint  = new float3(0, 0, 0);
            float3             closestIntersectionNormal = new float3(0, 0, 0);
            ObjectLightingData lightingData = new ObjectLightingData();

            // Loop Spheres
            for (int i = 0; i < Spheres.Length; i++)  // No foreachs in jobs
            {
                SphereData sphere = Spheres[i];

                // Using ray-sphere intersection equation
                float3 c = sphere.Position;
                float  R = sphere.Radius;

                float3 eminusc      = e - c;
                float  ddoteminusc  = dot(d, eminusc);
                float  descriminant = ddoteminusc * ddoteminusc - dot(d, d) * (dot(eminusc, eminusc) - R * R);
                if (descriminant < 0)
                {
                    // No hit
                    continue;
                }

                float sqrtdesc = sqrt(descriminant);
                float plust    = (-ddoteminusc + sqrtdesc) / dot(d, d);
                float minust   = (-ddoteminusc - sqrtdesc) / dot(d, d);

                if (plust > 0 && minust > 0)
                {
                    // In front of camera
                    float t = min(plust, minust);
                    if (t < closestt)
                    {
                        closestIntersectionPoint  = e + t * d;
                        closestIntersectionNormal = (closestIntersectionPoint - c) / R;
                        closestt     = t;
                        lightingData = sphere.LightingData;
                    }
                }
                else if (plust > 0 && minust < 0 || plust < 0 && minust > 0)
                {
                    // Inside circle
                }
                else if (plust < 0 && minust < 0)
                {
                    // Circle is behind camera.
                }
            }

            // Loop Triangles
            for (int i = 0; i < Triangles.Length; i++)
            {
                // No foreachs in jobs
                SingleTriangleData triangle = Triangles[i];

                float3 a = triangle.a;
                float3 b = triangle.b;
                float3 c = triangle.c;

                float detA = determinant(
                    float3x3(a.x - b.x, a.x - c.x, d.x,
                             a.y - b.y, a.y - c.y, d.y,
                             a.z - b.z, a.z - c.z, d.z));

                // Compute t
                float t = determinant(
                    float3x3(a.x - b.x, a.x - c.x, a.x - e.x,
                             a.y - b.y, a.y - c.y, a.y - e.y,
                             a.z - b.z, a.z - c.z, a.z - e.z)) /
                          detA;

                if (t < 0 || t > closestt)
                {
                    continue;
                }

                // Compute gamma
                float gamma = determinant(
                    float3x3(a.x - b.x, a.x - e.x, d.x,
                             a.y - b.y, a.y - e.y, d.y,
                             a.z - b.z, a.z - e.z, d.z)) /
                              detA;

                if (gamma < 0 || gamma > 1)
                {
                    continue;
                }

                // Compute beta
                float beta = determinant(
                    float3x3(a.x - e.x, a.x - c.x, d.x,
                             a.y - e.y, a.y - c.y, d.y,
                             a.z - e.z, a.z - c.z, d.z)) /
                             detA;

                if (beta < 0 || beta > 1 - gamma)
                {
                    continue;
                }

                closestt = t;
                closestIntersectionPoint  = e + t * d;
                closestIntersectionNormal = normalize(cross(c - a, b - a));
                lightingData = triangle.LightingData;
            }

            // Sphong Blinn Shading with no ambient lighting
            if (closestt < 1000000)
            {
                float3 p = closestIntersectionPoint;
                float3 n = closestIntersectionNormal;

                // v = direction from point to viewers eye
                float3 v = normalize(e - closestIntersectionPoint);

                Color color = new Color(0, 0, 0, 1);

                // It's been hit! Calculate the color based on lighting
                for (int j = 0; j < Lights.Length; j++)
                {
                    LightingData light = Lights[j];

                    // l = vector from light to intersect point
                    float3 l = normalize(light.Position - p);

                    // h = half vector to light source
                    float3 h = normalize(v + l);
                    color += lightingData.diffuseCoefficient * light.Color * max(0, dot(n, l)) +
                             lightingData.specularCoefficient * light.Color *
                             pow(max(0, dot(n, h)), lightingData.phongExponent);
                }

                return(color);
            }
            return(BackgroundColor);
        }
Ejemplo n.º 12
0
 public LightRecoverSystem(LightingData m_data) : base(m_data)
 {
 }