Exemplo n.º 1
0
    private void Awake()
    {
        var light = GetComponent <Light>();

        if (current)
        {
            Debug.Log("Sun Light Should be Singleton!");
            Destroy(light);
            Destroy(this);
            return;
        }
        current                               = this;
        shadMap.light                         = light;
        light.enabled                         = false;
        shadMap.shadowmapTexture              = new RenderTexture(settings.resolution, settings.resolution, 16, RenderTextureFormat.RFloat, RenderTextureReadWrite.Linear);
        shadMap.shadowmapTexture.filterMode   = FilterMode.Point;
        shadMap.frustumCorners                = new NativeArray <Vector3>(8, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
        shadMap.shadowCam                     = GetComponent <Camera>();
        shadMap.shadowCam.enabled             = false;
        shadMap.shadowCam.orthographic        = true;
        shadMap.shadowCam.renderingPath       = RenderingPath.Forward;
        shadMap.shadowCam.useOcclusionCulling = true;
        shadMap.shadowCam.allowMSAA           = false;
        shadMap.shadowCam.allowHDR            = false;
        shadMap.shadowCam.targetTexture       = shadMap.shadowmapTexture;
        shadMap.shadowDepthMaterial           = new Material(Shader.Find("Hidden/ShadowDepth"));
        shadMap.shadowFrustumPlanes           = new NativeArray <AspectInfo>(3, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
        Vector3 eulerAngle = transform.eulerAngles;

        eulerAngle.z          = Random.Range(5f, 355f);
        transform.eulerAngles = eulerAngle;
    }
Exemplo n.º 2
0
 public override void SetSunLight(SunLight light)
 {
     device.SetUniformValue(viewMatrixLocation, viewMatrix);
     device.SetUniformValue(normalMatrixLocation, Matrix.InverseTranspose(modelViewMatrix));
     SetUniformColorValue(lightColorUniformLocation, light.Color);
     device.SetUniformValue(lightDirectionUniformLocation, light.Direction);
 }
Exemplo n.º 3
0
 public override void SetSunLight(SunLight light)
 {
     SetVertexShaderConstant(Matrix.Transpose(worldMatrix));
     //SetVertexShaderConstant(viewMatrix);
     //SetVertexShaderConstant(Matrix.Invert(worldMatrix * viewMatrix));
     SetVertexShaderConstant(light.Direction);
     SetVertexShaderConstant(light.Color);
 }
Exemplo n.º 4
0
 private void OnEnable()
 {
     if (current)
     {
         if (current != this)
         {
             Debug.Log("Sun Light Should be Singleton!");
             Destroy(light);
             Destroy(this);
             return;
         }
         else
         {
             OnDisable();
         }
     }
     light           = GetComponent <Light>();
     current         = this;
     shadCam.forward = transform.forward;
     shadCam.up      = transform.up;
     shadCam.right   = transform.right;
     light.enabled   = false;
     if (!shadowCam)
     {
         shadowCam = GetComponent <Camera>();
         if (!shadowCam)
         {
             shadowCam = gameObject.AddComponent <Camera>();
         }
         shadowCam.enabled             = false;
         shadowCam.hideFlags           = HideFlags.HideInInspector;
         shadowCam.aspect              = 1;
         shadowCam.orthographic        = true;
         shadowCam.worldToCameraMatrix = Matrix4x4.identity;
         shadowCam.projectionMatrix    = Matrix4x4.identity;
     }
     shadowmapTexture = new RenderTexture(new RenderTextureDescriptor
     {
         width              = resolution,
         height             = resolution,
         depthBufferBits    = 16,
         colorFormat        = RenderTextureFormat.Shadowmap,
         autoGenerateMips   = false,
         bindMS             = false,
         dimension          = UnityEngine.Rendering.TextureDimension.Tex2DArray,
         enableRandomWrite  = false,
         memoryless         = RenderTextureMemoryless.None,
         shadowSamplingMode = UnityEngine.Rendering.ShadowSamplingMode.RawDepth,
         msaaSamples        = 1,
         sRGB        = false,
         useMipMap   = false,
         volumeDepth = 4,
         vrUsage     = VRTextureUsage.None
     });
     shadowmapTexture.filterMode = FilterMode.Bilinear;
     shadowDepthMaterial         = new Material(Shader.Find("Hidden/ShadowDepth"));
     shadowFrustumPlanes         = new NativeArray <AspectInfo>(3, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
 }
 public override void SetSunLight(SunLight light)
 {
     shaderValues.LightDirection = new[]
     {
         light.Direction.X, light.Direction.Y, light.Direction.Z, 0.0f
     };
     shaderValues.LightColor = new[]
     {
         light.Color.RedValue, light.Color.GreenValue, light.Color.BlueValue, light.Color.AlphaValue
     };
 }
Exemplo n.º 6
0
        public SunLight CreateSunLight()
        {
            Vector3 dir = Vector3.Parse(direction);
            Color   col = Color.Parse(color);

            SunLight light = new SunLight {
                sunDirection = dir, sunColor = col, sunIntensity = intensity, renderParticipatingMedia = renderParticipatingMedia
            };

            Log.Info($"创建SunLight成功:方向:{dir},颜色:{col},强度:{intensity},是否渲染参与介质:{renderParticipatingMedia}");
            return(light);
        }
Exemplo n.º 7
0
 public override void SetSunLight(SunLight light)
 {
     if (!isLightingAlreadySet)
     {
         device.ShaderEffect.AmbientLightColor = Vector3.One * AmbientLightIntensity;
         isLightingAlreadySet = true;
     }
     device.ShaderEffect.DirectionalLight0.DiffuseColor =
         new Vector3(light.Color.RedValue, light.Color.GreenValue, light.Color.BlueValue);
     device.ShaderEffect.DirectionalLight0.Direction =
         new Vector3(-light.Direction.X, -light.Direction.Y, -light.Direction.Z);
 }
 private void OnDestroy()
 {
     if (current != this)
     {
         return;
     }
     current = null;
     shadMap.frustumCorners.Dispose();
     shadMap.shadowmapTexture.Release();
     Destroy(shadMap.shadowmapTexture);
     Destroy(shadMap.shadowDepthMaterial);
     shadMap.shadowFrustumPlanes.Dispose();
 }
Exemplo n.º 9
0
    private SunLight m_sunLight;        //游戏里的太阳

    // Use this for initialization
    void Start()
    {
        //时间
        m_dayTime              = new GameDayTime(m_minInTick, m_hourInMinuts, m_monthInDays);
        m_dayTime.notifier    += new GameDayTime.Notify(OnChangeMinute);
        m_dayTime.DayNotifier += new GameDayTime.NotifyDay(OnDayChange);

        //太阳
        m_sunLight = new SunLight(m_sunRiseTime, m_sunSetTime, m_hourInMinuts, m_dayTime, m_lightIntensityAtMidDay, m_SunColor, m_SunRiseColor);

        SetInitData();

        RefreshTextUI();
    }
Exemplo n.º 10
0
        private static StaticFit DirectionalShadowStaticFit(Camera cam, SunLight sunlight, float *outClipDistance)
        {
            StaticFit staticFit;

            staticFit.resolution     = sunlight.resolution;
            staticFit.mainCamTrans   = cam;
            staticFit.frustumCorners = new NativeArray <float3>((SunLight.CASCADELEVELCOUNT + 1) * 4, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
            outClipDistance[0]       = cam.nearClipPlane;
            outClipDistance[1]       = sunlight.firstLevelDistance;
            outClipDistance[2]       = sunlight.secondLevelDistance;
            outClipDistance[3]       = sunlight.thirdLevelDistance;
            outClipDistance[4]       = sunlight.farestDistance;
            return(staticFit);
        }
Exemplo n.º 11
0
        private void LoadLight()
        {
            SceneLight = new SunLight(GraphicsDevice, Content);                      // A default light is required for other components

            SceneLight.Direction      = new Vector3(1f, .5f, -.6f);                  // Direction this light points
            SceneLight.AmbientColor   = new Vector3(0.3f, 0.3f, 0.3f);               // RGB values of our light
            SceneLight.SpecularColor  = new Vector3(0.2f, 0.2f, 0.2f);
            SceneLight.DiffuseColor   = new Vector3(1.0f, 1.0f, 1.0f);
            SceneLight.SpecularPower  = 64;                                         // Lower means more reflection
            SceneLight.AmbientPower   = 0.6f;
            SceneLight.MinimumAmbient = 0.2f;
            SceneLight.EnableDayNight(15);                                            // Let this sunlight rise and set every 30 seconds

            ComponentList.Add(SceneLight);
        }
Exemplo n.º 12
0
        public SunLight CreateSunLight()
        {
            Vector3 rot = Vector3.Parse(euler);
            Color   col = Color.Parse(color);

            SunLight sunLight = SunLight.Create();

            sunLight.color     = col;
            sunLight.intensity = intensity;
            sunLight.euler     = string.IsNullOrEmpty(euler) ? new Vector3(50, -30, 0) : rot;


            Log.Info($"创建SunLight成功:旋转:{sunLight.euler},颜色:{col},强度:{intensity},是否渲染参与介质:{renderParticipatingMedia}");
            return(sunLight);
        }
Exemplo n.º 13
0
        protected override void UpdateLights()
        {
            switch (LightMode)
            {
            case 1:
                Light = new ThreePointLights();
                break;

            case 2:
                Light = new DefaultLights();
                break;

            default:
                Light = new SunLight();
                break;
            }
            RaisePropertyChanged("Light");
        }
 private void OnDisable()
 {
     if (current != this)
     {
         return;
     }
     current = null;
     if (shadowmapTexture)
     {
         shadowmapTexture.Release();
         DestroyImmediate(shadowmapTexture);
     }
     if (shadowDepthMaterial)
     {
         DestroyImmediate(shadowDepthMaterial);
     }
     if (shadowFrustumPlanes.IsCreated)
     {
         shadowFrustumPlanes.Dispose();
     }
 }
Exemplo n.º 15
0
        private void RadioButtonLight_Checked(object sender, RoutedEventArgs e)
        {
            if (cont != null)
            {
                List <LightSetup> lights = new List <LightSetup>();

                foreach (object obj in cont.Children)
                {
                    if (obj is LightSetup)
                    {
                        lights.Add((LightSetup)obj);
                    }
                }

                foreach (LightSetup lsetup in lights)
                {
                    cont.Children.Remove(lsetup);
                }


                if (RB_DefaultLight.IsChecked == true)
                {
                    Debug.WriteLine("DEFAULTLIGHT");
                    DefaultLights defaultLights = new DefaultLights();
                    cont.Children.Add(defaultLights);
                }
                else if (RB_SunLight.IsChecked == true)
                {
                    Debug.WriteLine("SUNLIGHT");
                    SunLight sunLight = new SunLight();
                    cont.Children.Add(sunLight);
                }
                else if (RB_SpotLight.IsChecked == true)
                {
                    Debug.WriteLine("SPOTLIGHT");
                    SpotHeadLight spotHeadLight = new SpotHeadLight();
                    cont.Children.Add(spotHeadLight);
                }
            }
        }
    private void Awake()
    {
        var light = GetComponent <Light>();

        if (current)
        {
            Debug.Log("Sun Light Should be Singleton!");
            Destroy(light);
            Destroy(this);
            return;
        }
        current                              = this;
        shadMap.light                        = light;
        light.enabled                        = false;
        shadMap.shadowmapTexture             = new RenderTexture(settings.resolution, settings.resolution, 16, RenderTextureFormat.RFloat, RenderTextureReadWrite.Linear);
        shadMap.shadowmapTexture.useMipMap   = false;
        shadMap.shadowmapTexture.dimension   = UnityEngine.Rendering.TextureDimension.Tex2DArray;
        shadMap.shadowmapTexture.volumeDepth = 4;
        shadMap.shadowmapTexture.filterMode  = FilterMode.Point;
        shadMap.frustumCorners               = new NativeArray <Vector3>(8, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
        shadMap.shadowDepthMaterial          = new Material(Shader.Find("Hidden/ShadowDepth"));
        shadMap.shadowFrustumPlanes          = new NativeArray <AspectInfo>(3, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
    }
Exemplo n.º 17
0
        public void ShowModel(string filePath)
        {
            // Empty the viewer
            ViewPort3D.Children.Clear();
            // Init Lights
            var lights = new SunLight();

            ViewPort3D.Children.Add(lights);

            var sim = PedSimXMLWriter.Deserialize(filePath);

            if (sim == null)
            {
                return;
            }

            MeshBuilder mb;

            // Visualize Areas
            foreach (var item in sim.layouts[0].scenario.areas)
            {
                mb = new MeshBuilder(false, false);

                List <Point3D> ptd3Ds   = new List <Point3D>();
                var            material = new DiffuseMaterial();

                if (item.type == PedSimXMLWriter.areaType.Origin.ToString())
                {
                    foreach (var point in item.points)
                    {
                        ptd3Ds.Add(new Point3D {
                            X = point.x, Y = point.y, Z = 0.000001
                        });
                    }

                    mb.AddPolygon(ptd3Ds);
                    material = new DiffuseMaterial {
                        Brush = Brushes.Chartreuse
                    };
                }
                else if (item.type == PedSimXMLWriter.areaType.Intermediate.ToString())
                {
                    foreach (var point in item.points)
                    {
                        ptd3Ds.Add(new Point3D {
                            X = point.x, Y = point.y, Z = 0
                        });
                    }
                    mb.AddPolygon(ptd3Ds);
                    material = new DiffuseMaterial {
                        Brush = Brushes.Aqua
                    };
                }

                var myGeometryModel = new GeometryModel3D
                {
                    Material     = material,
                    BackMaterial = material,
                    Geometry     = mb.ToMesh(true)
                };

                ViewPort3D.Children.Add(new ModelUIElement3D {
                    Model = myGeometryModel
                });
            }

            // Visualize Obstacles
            foreach (var item in sim.layouts[0].scenario.obstacles)
            {
                mb = new MeshBuilder(false, false);

                List <Point3D> ptd3Ds = new List <Point3D>();

                foreach (var point in item.points)
                {
                    ptd3Ds.Add(new Point3D()
                    {
                        X = point.x, Y = point.y, Z = 0
                    });
                }

                mb.AddPolygon(ptd3Ds);

                var myGeometryModel = new GeometryModel3D
                {
                    Material = new DiffuseMaterial()
                    {
                        Brush = Brushes.Red
                    },
                    BackMaterial = new DiffuseMaterial()
                    {
                        Brush = Brushes.Red
                    },
                    Geometry = mb.ToMesh(true)
                };

                ViewPort3D.Children.Add(new ModelUIElement3D {
                    Model = myGeometryModel
                });
            }
        }
    private void OnEnable()
    {
        if (current)
        {
            if (current != this)
            {
                Debug.Log("Sun Light Should be Singleton!");
                Destroy(light);
                Destroy(this);
                return;
            }
            else
            {
                OnDisable();
            }
        }
        light           = GetComponent <Light>();
        current         = this;
        shadCam.forward = transform.forward;
        shadCam.up      = transform.up;
        shadCam.right   = transform.right;
        light.enabled   = false;
        GameObject GetChild(string name)
        {
            for (int i = 0; i < transform.childCount; ++i)
            {
                if (transform.GetChild(i).name == name)
                {
                    return(transform.GetChild(i).gameObject);
                }
            }
            return(null);
        }

        if (!shadowCam)
        {
            GameObject shadObj = GetChild("Sun_Shadow_Cam");
            if (!shadObj)
            {
                shadObj = new GameObject("Sun_Shadow_Cam");
            }
            shadowCam = shadObj.GetComponent <Camera>();
            if (!shadowCam)
            {
                shadObj.transform.SetParent(transform);
                shadObj.transform.localRotation = Quaternion.identity;
                shadObj.transform.localPosition = Vector3.zero;
                shadObj.transform.localScale    = Vector3.one;
                shadObj.hideFlags = HideFlags.HideAndDontSave;
                shadowCam         = shadObj.AddComponent <Camera>();
            }
            shadowCam.enabled             = false;
            shadowCam.aspect              = 1;
            shadowCam.orthographic        = true;
            shadowCam.worldToCameraMatrix = Matrix4x4.identity;
            shadowCam.projectionMatrix    = Matrix4x4.identity;
        }
        shadowmapTexture = new RenderTexture(new RenderTextureDescriptor
        {
            width              = resolution,
            height             = resolution,
            depthBufferBits    = 16,
            colorFormat        = RenderTextureFormat.Shadowmap,
            autoGenerateMips   = false,
            bindMS             = false,
            dimension          = UnityEngine.Rendering.TextureDimension.Tex2DArray,
            enableRandomWrite  = false,
            memoryless         = RenderTextureMemoryless.None,
            shadowSamplingMode = UnityEngine.Rendering.ShadowSamplingMode.RawDepth,
            msaaSamples        = 1,
            sRGB        = false,
            useMipMap   = false,
            volumeDepth = 4,
            vrUsage     = VRTextureUsage.None
        });
        shadowmapTexture.filterMode = FilterMode.Bilinear;
        shadowDepthMaterial         = new Material(Shader.Find("Hidden/ShadowDepth"));
        shadowFrustumPlanes         = new NativeArray <AspectInfo>(3, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
    }
Exemplo n.º 19
0
 public override void SetSunLight(SunLight light)
 {
 }
Exemplo n.º 20
0
        public void Deserialize(HelixViewport3D control, DataStore data)
        {
            List <object> list = new List <object>(2);

            list.Add(null);
            list.Add(null);

            DeserializeDefault(control);
            brush.Deserialize(control, data);

            list[1] = control.Tag;

            Debug.WriteLine("ModelP:  Path: " + modelp.LocalPathToModel);

            if (modelp != null)
            {
                if (!String.IsNullOrWhiteSpace(modelp.LocalPathToModel))
                {
                    string lpath = System.IO.Path.Combine(LocalPath.GetResourcesPath(), modelp.LocalPathToModel);
                    if (File.Exists(lpath))
                    {
                        LoadModel(control, lpath);
                        list[0] = control.Tag;
                    }
                    else
                    {
                        DefaultModel(control);
                    }
                }
                else
                {
                    DefaultModel(control);
                }
            }
            else
            {
                DefaultModel(control);
            }

            if (camera != null)
            {
                camera.Deserialize(control.Camera);
            }

            if (lightType == ModelLightType.LightType.SpotHeadlight)
            {
                SpotHeadLight spotHeadLight = new SpotHeadLight();
                control.Children.Add(spotHeadLight);
            }
            else if (lightType == ModelLightType.LightType.SunLight)
            {
                SunLight sunLight = new SunLight();
                control.Children.Add(sunLight);
            }
            else
            {
                DefaultLights defaultLights = new DefaultLights();
                control.Children.Add(defaultLights);
            }

            control.Tag = list;


            control.Loaded += (s, e) => {
                if (control.CameraController != null)
                {
                    control.CameraController.IsEnabled = CameraControl;
                }

                control.ShowViewCube = CameraControl;
            };
        }
Exemplo n.º 21
0
 void Start()
 {
     myRigidBody = GetComponent <Rigidbody2D>();
     petriDish   = FindObjectOfType <PetriDish>();
     sunlight    = FindObjectOfType <SunLight>();
 }
Exemplo n.º 22
0
        protected override void OnLoad()
        {
            //Initialize opengl debug callback
            _debugProcCallbackHandle = GCHandle.Alloc(_debugProcCallback);
            GL.Enable(EnableCap.DebugOutput);
            GL.Enable(EnableCap.DebugOutputSynchronous);
            GL.DebugMessageCallback(_debugProcCallback, IntPtr.Zero);
            //Init game contexts
            Init();

            //Load test assets
            //var sponza = GLTFAssetLoader.Load(@"D:\Blender\Models\sponza-gltf-pbr\sponza.gltf");
            //var zelda = GLTFAssetLoader.Load(@"D:\Blender\Models\JourneyPBR\Export\untitled.glb", 0.01f);
            //var car = AssetLoader.LoadAssets(@"D:\Blender\Models\Audi R8\Models\Audi R8.fbx", 0.1f);
            //var Sphere = GLTFAssetLoader.Load(@"D:\Blender\Models\Sphere.fbx", 1f);
            var spire = GLTFAssetLoader.Load(@"D:\Blender\Models\Spire.glb");
            var mc    = GLTFAssetLoader.Load(@"D:\Blender\Models\beta map split.glb", 1f);

            mc.Root.Transform.Position -= Vector3.UnitY * 128;
            GameLoop.Instantiate(mc, null);
            //GameLoop.Instantiate(Sphere, null);
            //GameLoop.Instantiate(car, null);
            //GameLoop.Instantiate(zelda, null);
            //GameLoop.Instantiate(sponza, null);
            GameLoop.Instantiate(spire, null);
            //Add RigidBodys
            //var rb1 = new RigidBody();
            //rb1.DetectionSettings = RigidBody.ContinuousDetectionSettings;
            //rb1.Shape = new BepuPhysics.Collidables.Sphere(Sphere.Root.Transform.Scale.X);
            //Sphere.Root.AddScript(rb1);

            //var rb2 = new RigidBody();
            //rb2.RigidBodyType = RigidBodyType.Kinematic;
            //rb2.Shape = new BepuPhysics.Collidables.Box(1000, 0.1f, 1000);
            //sponza.Root.AddScript(rb2);

            //Add Game Camera
            var c = new Camera(new Viewport(ClientRectangle));

            ICamera.MainCamera = c;
            GameObject CameraObj = new GameObject("Main Camera");

            CameraObj.AddScript(c);
            gameCamController = new FlyCamController();
            CameraObj.AddScript(gameCamController);
            var stack = new PostProcessStack();

            stack.AddEffect(new BloomEffect());
            stack.AddEffect(new ToneMapACES());
            CameraObj.AddScript(stack);
            GameLoop.Add(CameraObj);
            var light = new SunLight();

            light.Color    = Color4.White.ToNumerics().ToOpenTK().Xyz;
            light.Strength = 2;
            CameraObj.AddScript(light);
            gameCamController.Enabled = false;
            //Spinny thingy
            //zelda.Root.AddScript(new TurnTable());
            //var t = Sphere.Root.GetComponent<Transform>()!;
            //t.Position = new Vector3(0, 4, 0);
            //t.Scale = new Vector3(0.1f);

            Input.Keyboard      = KeyboardState;
            Input.Mouse         = MouseState;
            editorCamController = EditorManager.cam.GameObject.GetScript <FlyCamController>() !;
            EditMode            = true;
        }
 void Awake()
 {
     Instance = this;
 }