Пример #1
0
        private MyShadowMapData TSMShadowMap(ScriptableRenderContext context, MyRenderingData renderingData,
                                             ShadowSettings settings, int lightIndex)
        {
            var camera = renderingData.camera;

            if (settings.debug)
            {
                camera = GameObject.Find("Main Camera").GetComponent <Camera>();
            }
            var(view, projection) = GetShadowViewProjection(settings, renderingData, lightIndex);

            var cmd = CommandBufferPool.Get();

            cmd.Clear();
            var depthBuf = IdentifierPool.Get();

            cmd.GetTemporaryRT(depthBuf, settings.resolution, settings.resolution, 32, FilterMode.Point,
                               RenderTextureFormat.Depth);

            RenderTargetBinding binding = new RenderTargetBinding();

            binding.depthRenderTarget = depthBuf;
            cmd.SetRenderTarget(depthBuf);
            cmd.ClearRenderTarget(true, true, Color.black);

            MyShadowMapData shadowMapData = new MyShadowMapData()
            {
                shadowMapIdentifier = depthBuf,
                bias        = settings.bias,
                shadowType  = ShadowAlgorithms.TSM,
                world2Light = GL.GetGPUProjectionMatrix(projection, true) * view,
            };

            var trapezoidalTransfrom = TSMTransform(camera, shadowMapData.world2Light, settings);

            shadowMapData.postTransform = trapezoidalTransfrom;


            cmd.SetViewProjectionMatrices(view, projection);
            cmd.SetGlobalDepthBias(settings.depthBias, settings.normalBias);
            cmd.SetGlobalMatrix("_ShadowPostTransform", trapezoidalTransfrom);
            cmd.SetGlobalFloat("_SlopeDepthBias", -settings.normalBias);
            cmd.SetGlobalFloat("_DepthBias", -Mathf.Pow(2, settings.depthBias));

            context.ExecuteCommandBuffer(cmd);
            cmd.Clear();


            DrawShadowCasters(context, renderingData, shadowMapData, PassTSM);

            cmd.SetViewProjectionMatrices(renderingData.camera.worldToCameraMatrix,
                                          renderingData.camera.projectionMatrix);

            context.ExecuteCommandBuffer(cmd);
            cmd.Clear();

            CommandBufferPool.Release(cmd);

            return(shadowMapData);
        }
Пример #2
0
        public void AddPlane(BackgroundPlane plane)
        {
            int key = IdentifierPool.FirstAvailable <BackgroundPlane>(this.BackgroundPlanes);

            plane.Id = key;
            this.BackgroundPlanes.Add(key, plane);
        }
Пример #3
0
        ShadowMapData PSMShadowMap(ScriptableRenderContext context, RenderingData renderingData, ShadowSettings settings, int lightIndex)
        {
            var(view, projection, inverseZ) = PSMProjection(lightIndex, renderingData);
            //Debug.Log(inverseZ);
            Vector4 p  = new Vector4(-0.46017f, 0.16764f, 0.01015f, 1.00f);
            var     p1 = projection * view * p;
            var     p2 = GL.GetGPUProjectionMatrix(projection, false) * Matrix4x4.Scale(new Vector3(1, 1, -1)) * view * p;

            ShadowMapData shadowMapData = new ShadowMapData()
            {
                shadowMapIdentifier = IdentifierPool.Get(),
                world2Light         = GL.GetGPUProjectionMatrix(projection, true) * Matrix4x4.Scale(new Vector3(1, 1, -1)) * view,
                bias             = settings.Bias,
                ShadowType       = ShadowAlgorithms.PSM,
                ShadowParameters = new Vector4(inverseZ ? 1 : 0, 0, 0),
            };

            var cmd = CommandBufferPool.Get();

            cmd.GetTemporaryRT(shadowMapData.shadowMapIdentifier, settings.Resolution, settings.Resolution, 32, FilterMode.Point, RenderTextureFormat.Depth);
            cmd.SetRenderTarget(shadowMapData.shadowMapIdentifier);
            cmd.SetGlobalVector("_ShadowParameters", shadowMapData.ShadowParameters);
            cmd.SetGlobalDepthBias(1, 1);
            //cmd.SetViewProjectionMatrices(renderingData.camera.worldToCameraMatrix, renderingData.camera.projectionMatrix);
            cmd.ClearRenderTarget(true, true, Color.black);

            context.ExecuteCommandBuffer(cmd);
            cmd.Clear();

            DrawShadowCasters(context, renderingData, shadowMapData, PassPSM);

            CommandBufferPool.Release(cmd);

            return(shadowMapData);
        }
Пример #4
0
        private MyShadowMapData StandardShadowMap(ScriptableRenderContext context, MyRenderingData renderingData,
                                                  ShadowSettings settings, int lightIndex)
        {
            var cmd = CommandBufferPool.Get();

            cmd.Clear();
            var depthBuf = IdentifierPool.Get();

            cmd.GetTemporaryRT(depthBuf, settings.resolution, settings.resolution, 32, FilterMode.Point,
                               RenderTextureFormat.Depth);

            RenderTargetBinding binding = new RenderTargetBinding();

            binding.depthRenderTarget = depthBuf;
            cmd.SetRenderTarget(depthBuf);
            cmd.ClearRenderTarget(true, true, Color.black);

            MyShadowMapData shadowMapData = new MyShadowMapData()
            {
                shadowMapIdentifier = depthBuf,
                bias       = settings.bias,
                shadowType = ShadowAlgorithms.Standard,
            };

            var(view, projection) = GetShadowViewProjection(settings, renderingData, lightIndex);

            cmd.SetViewProjectionMatrices(view, projection);

            shadowMapData.world2Light = projection * view;

            cmd.SetGlobalDepthBias(settings.depthBias, settings.normalBias);

            context.ExecuteCommandBuffer(cmd);
            cmd.Clear();

            DrawShadowCasters(context, renderingData, shadowMapData, PassSimple);

            cmd.SetViewProjectionMatrices(renderingData.camera.worldToCameraMatrix,
                                          renderingData.camera.projectionMatrix);

            context.ExecuteCommandBuffer(cmd);
            cmd.Clear();


            CommandBufferPool.Release(cmd);

            return(shadowMapData);
        }
Пример #5
0
        public override void Cleanup(ScriptableRenderContext context, ref RenderingData renderingData)
        {
            var cmd = CommandBufferPool.Get();

            foreach (var light in renderingData.lights)
            {
                if (LightMaps.ContainsKey(light.light))
                {
                    IdentifierPool.Release(LightMaps[light.light].shadowMapIdentifier);
                    cmd.ReleaseTemporaryRT(LightMaps[light.light].shadowMapIdentifier);
                }
            }
            LightMaps.Clear();
            context.ExecuteCommandBuffer(cmd);
            cmd.Clear();
            CommandBufferPool.Release(cmd);
        }
Пример #6
0
        //Debug 用
        private void RenderVolumeDepth(CommandBuffer cmd, MyRenderingData renderingData)
        {
            var debugRT = IdentifierPool.Get();

            cmd.GetTemporaryRT(debugRT, renderingData.camera.pixelWidth, renderingData.camera.pixelHeight, 0,
                               FilterMode.Point, RenderTextureFormat.ARGBFloat);
            cmd.SetRenderTarget(debugRT);
            cmd.SetGlobalTexture("_RWVolumeDepthTexture", volumeDepthTexID);

            foreach (var volumeData in visibleVolumes)
            {
                cmd.SetGlobalInt("_VolumeIndex", volumeData.volumeIndex);
                cmd.DrawMesh(volumeData.volume.VolumeMesh, volumeData.volume.transform.localToWorldMatrix, volumeMat, 0,
                             volumeDepthPass);
            }

            cmd.ReleaseTemporaryRT(debugRT);
            IdentifierPool.Release(debugRT);
        }
Пример #7
0
        void RenderVolumeDepth(ScriptableRenderContext context, RenderingData renderingData)
        {
            var cmd     = CommandBufferPool.Get("Light Volume Depth");
            var debugRT = IdentifierPool.Get();

            cmd.GetTemporaryRT(debugRT, renderingData.camera.pixelWidth, renderingData.camera.pixelHeight, 0, FilterMode.Point, RenderTextureFormat.ARGBFloat);
            cmd.SetRenderTarget(debugRT);
            cmd.SetGlobalTexture("_RWVolumeDepthTexture", VolumeDepthTex);

            foreach (var volumeData in visibleVolumes)
            {
                cmd.SetGlobalInt("_VolumeIndex", volumeData.VolumeIndex);
                cmd.DrawMesh(volumeData.Volume.VolumeMesh, volumeData.Volume.transform.localToWorldMatrix, volumeMat, 0, PassVolumeDepth);
            }

            cmd.ReleaseTemporaryRT(debugRT);
            IdentifierPool.Release(debugRT);

            context.ExecuteCommandBuffer(cmd);
            cmd.Clear();
            CommandBufferPool.Release(cmd);
        }
Пример #8
0
            public GeyserState(TrileGroup group, GeysersHost host)
            {
                ServiceHelper.InjectServices((object)this);
                this.Host             = host;
                this.Group            = group;
                this.SinceStateChange = TimeSpan.FromSeconds(-(double)group.GeyserOffset);
                Vector3 position = Enumerable.Aggregate <TrileInstance, Vector3>((IEnumerable <TrileInstance>) this.Group.Triles, Vector3.Zero, (Func <Vector3, TrileInstance, Vector3>)((a, b) => a + b.Center)) / (float)group.Triles.Count;
                int     key1     = IdentifierPool.FirstAvailable <BackgroundPlane>(this.LevelManager.BackgroundPlanes);

                this.TopPlane = new BackgroundPlane(this.LevelMaterializer.AnimatedPlanesMesh, "sewer/sewer_geyser_top", true)
                {
                    Id             = key1,
                    Position       = position,
                    YTextureRepeat = true,
                    Crosshatch     = true,
                    Doublesided    = true
                };
                this.LevelManager.BackgroundPlanes.Add(key1, this.TopPlane);
                int key2 = IdentifierPool.FirstAvailable <BackgroundPlane>(this.LevelManager.BackgroundPlanes);

                this.TilePlane = new BackgroundPlane(this.LevelMaterializer.AnimatedPlanesMesh, "sewer/sewer_geyser_tile", true)
                {
                    Id             = key2,
                    Position       = position,
                    YTextureRepeat = true,
                    Billboard      = true
                };
                this.LevelManager.BackgroundPlanes.Add(key2, this.TilePlane);
                this.TopPlane.Timing.Step = this.TilePlane.Timing.Step;
                this.loopEmitter          = SoundEffectExtensions.EmitAt(this.Host.LoopSound, position, true, 0.0f, 0.0f);
                foreach (TrileInstance trileInstance in group.Triles)
                {
                    trileInstance.PhysicsState.IgnoreCollision    = true;
                    trileInstance.PhysicsState.IgnoreClampToWater = true;
                }
            }
Пример #9
0
 public void Setup()
 {
     this.identifierPool = new IdentifierPool();
 }
Пример #10
0
        void RenderLightVolume(ScriptableRenderContext context, RenderingData renderingData)
        {
            var cmd = CommandBufferPool.Get("Light Volume");

            var renderSize = new Vector2Int(renderingData.camera.pixelWidth, renderingData.camera.pixelHeight) / asset.VolumeResolutionScale;
            var rt         = IdentifierPool.Get();

            cmd.GetTemporaryRT(rt, renderSize.x, renderSize.y, 0, FilterMode.Point, RenderTextureFormat.Default);
            cmd.SetRenderTarget(rt, rt);
            cmd.ClearRenderTarget(false, true, Color.black);

            cmd.SetGlobalTexture("_CameraDepthTex", renderingData.DepthTarget);
            cmd.SetCameraParams(renderingData.camera, true);

            float globalExtinction = Mathf.Log(1 / (0.1f)) / asset.VisibilityDistance;

            foreach (var volumeData in visibleVolumes)
            {
                if (!volumeData.Volume.enabled)
                {
                    continue;
                }
                var     light = renderingData.cullResults.visibleLights[volumeData.LightIndex];
                Vector4 lightPos;
                if (light.lightType == LightType.Directional)
                {
                    lightPos = (-light.light.transform.forward).ToVector4(0);
                }
                else
                {
                    lightPos = light.light.transform.position.ToVector4(1);
                }
                cmd.SetGlobalVector("_LightPosition", lightPos);
                cmd.SetGlobalVector("_LightDirection", -light.light.transform.forward);
                cmd.SetGlobalFloat("_LightAngle", Mathf.Cos(Mathf.Deg2Rad * light.spotAngle / 2));
                cmd.SetGlobalVector("_LightColor", light.finalColor * volumeData.Volume.IntensityMultiplier);
                cmd.SetGlobalVector("_WorldCameraPos", renderingData.camera.transform.position);
                cmd.SetGlobalVector("_FrameSize", new Vector4(renderSize.x, renderSize.y, 1f / renderSize.x, 1f / renderSize.y));
                cmd.SetGlobalInt("_Steps", volumeData.Volume.RayMarchingSteps);
                cmd.SetGlobalVector("_RangeLimit", volumeData.Volume.RayMarchingRange);
                cmd.SetGlobalFloat("_IncomingLoss", volumeData.Volume.IncomingLoss);
                cmd.SetGlobalFloat("_LightDistance", volumeData.Volume.LightDistance);
                var extinction = globalExtinction;
                if (volumeData.Volume.ExtinctionOverride)
                {
                    extinction = Mathf.Log(1 / (0.1f)) / volumeData.Volume.VisibilityDistance;
                }
                cmd.SetGlobalVector("_TransmittanceExtinction", new Vector3(extinction, extinction, extinction));
                if (asset.JitterPatterns.Length > 0)
                {
                    cmd.SetGlobalTexture("_SampleNoise", asset.JitterPatterns[renderingData.FrameID % asset.JitterPatterns.Length]);
                }

                if (renderingData.shadowMapData.ContainsKey(volumeData.Volume.light))
                {
                    var shadowData = renderingData.shadowMapData[volumeData.Volume.light];
                    cmd.SetGlobalTexture("_ShadowMap", shadowData.shadowMapIdentifier);
                    cmd.SetGlobalMatrix("_WorldToLight", shadowData.world2Light);

                    cmd.SetGlobalMatrix("_WorldToLight", shadowData.world2Light);
                    cmd.SetGlobalTexture("_ShadowMap", shadowData.shadowMapIdentifier);
                    cmd.SetGlobalFloat("_ShadowBias", shadowData.bias);
                    cmd.SetGlobalInt("_ShadowType", (int)shadowData.ShadowType);
                    cmd.SetGlobalVector("_ShadowParameters", shadowData.ShadowParameters);
                    cmd.SetGlobalMatrix("_ShadowPostTransform", shadowData.postTransform);
                    //cmd.SetGlobalMatrix("_")
                    cmd.SetGlobalInt("_UseShadow", 1);
                }
                else
                {
                    cmd.SetGlobalInt("_UseShadow", 0);
                }

                var boundaryPlanes = volumeData.Volume.GetVolumeBoundFaces(renderingData.camera);
                cmd.SetGlobalVectorArray("_BoundaryPlanes", boundaryPlanes);
                cmd.SetGlobalInt("_BoundaryPlaneCount", boundaryPlanes.Count);

                switch (light.lightType)
                {
                case LightType.Point:
                case LightType.Spot:
                    cmd.DrawMesh(volumeData.Volume.VolumeMesh, volumeData.Volume.transform.localToWorldMatrix, volumeMat, 0, PassVolumeScattering);
                    break;

                case LightType.Directional:
                    cmd.BlitFullScreen(BuiltinRenderTextureType.None, rt, volumeMat, PassFullScreenVolumeScattering);
                    break;
                }

                //cmd.DrawMesh(volumeData.Volume.VolumeMesh, volumeData.Volume.transform.localToWorldMatrix, volumeMat, 0, PassVolumeScattering);
            }

            cmd.SetGlobalTexture("_CameraDepthTex", renderingData.DepthTarget);
            cmd.SetGlobalFloat("_GlobalFogExtinction", globalExtinction);
            cmd.SetGlobalColor("_AmbientLight", asset.FogLight);
            //cmd.Blit(BuiltinRenderTextureType.None, renderingData.ColorTarget, volumeMat, PassGlobalFog);
            cmd.BlitFullScreen(BuiltinRenderTextureType.None, renderingData.ColorTarget, volumeMat, PassGlobalFog);

            cmd.Blit(rt, renderingData.ColorTarget, volumeMat, PassVolumeResolve);


            //cmd.ReleaseTemporaryRT(rt);
            //IdentifierPool.Release(rt);
            cmd.ReleaseTemporaryRT(rt);
            IdentifierPool.Release(rt);

            context.ExecuteCommandBuffer(cmd);
            cmd.Clear();
            CommandBufferPool.Release(cmd);
        }
Пример #11
0
 private void TryInitialize()
 {
     if (this.isHooked)
     {
         this.Gomez.EnteredDoor -= new Action(this.CheckWinCondition);
         this.isHooked           = false;
     }
     if (this.LevelManager.Name != "CRYPT")
     {
         this.TraversedVolumes.Clear();
     }
     else
     {
         if (this.LevelManager.LastLevelName == "CRYPT")
         {
             this.TraversedVolumes.Add(this.PlayerManager.DoorVolume.Value);
             if (this.TraversedVolumes.Count > 4)
             {
                 this.TraversedVolumes.RemoveAt(0);
             }
             for (int index = 0; index < this.TraversedVolumes.Count; ++index)
             {
                 if (CryptHost.VolumeSequence[this.TraversedVolumes.Count - 1 - index] != this.TraversedVolumes[this.TraversedVolumes.Count - 1 - index])
                 {
                     this.TraversedVolumes.Clear();
                     break;
                 }
             }
         }
         else
         {
             this.TraversedVolumes.Clear();
         }
         ICollection <int> keys     = this.LevelManager.Scripts.Keys;
         int[]             numArray = new int[4]
         {
             0,
             1,
             2,
             3
         };
         foreach (int key in Enumerable.ToArray <int>(Enumerable.Except <int>((IEnumerable <int>)keys, (IEnumerable <int>)numArray)))
         {
             this.LevelManager.Scripts.Remove(key);
         }
         foreach (Volume volume in (IEnumerable <Volume>) this.LevelManager.Volumes.Values)
         {
             if (volume.Id > 1 && (volume.Id != 14 || this.TraversedVolumes.Count != 3))
             {
                 int key = IdentifierPool.FirstAvailable <Script>(this.LevelManager.Scripts);
                 int num = RandomHelper.InList <int>(Enumerable.Except <int>((IEnumerable <int>) this.LevelManager.Volumes.Keys, (IEnumerable <int>) new int[3]
                 {
                     0,
                     1,
                     volume.Id
                 }));
                 Script script1 = new Script();
                 script1.Id = key;
                 List <ScriptTrigger> triggers       = script1.Triggers;
                 ScriptTrigger        scriptTrigger1 = new ScriptTrigger();
                 scriptTrigger1.Event  = "Enter";
                 scriptTrigger1.Object = new Entity()
                 {
                     Type       = "Volume",
                     Identifier = new int?(volume.Id)
                 };
                 ScriptTrigger scriptTrigger2 = scriptTrigger1;
                 triggers.Add(scriptTrigger2);
                 List <ScriptAction> actions       = script1.Actions;
                 ScriptAction        scriptAction1 = new ScriptAction();
                 scriptAction1.Operation = "ChangeLevelToVolume";
                 scriptAction1.Arguments = new string[4]
                 {
                     "CRYPT",
                     num.ToString(),
                     "True",
                     "False"
                 };
                 scriptAction1.Object = new Entity()
                 {
                     Type = "Level"
                 };
                 ScriptAction scriptAction2 = scriptAction1;
                 actions.Add(scriptAction2);
                 Script script2 = script1;
                 foreach (ScriptAction scriptAction3 in script2.Actions)
                 {
                     scriptAction3.Process();
                 }
                 this.LevelManager.Scripts.Add(key, script2);
             }
         }
         this.LevelManager.Scripts[2].Disabled = this.TraversedVolumes.Count != 3;
     }
 }
Пример #12
0
        private void TryInitialize()
        {
            this.Destroy();
            this.Visible = this.Enabled = this.LevelManager.Name == "HEX_REBUILD";
            if (!this.Enabled)
            {
                return;
            }
            this.GameState.HideHUD = true;
            this.CameraManager.ChangeViewpoint(Viewpoint.Right, 0.0f);
            this.PlayerManager.Background = false;
            ArtObject artObject = this.CMProvider.CurrentLevel.Load <ArtObject>("Art Objects/NEW_HEXAO");
            int       key       = IdentifierPool.FirstAvailable <ArtObjectInstance>(this.LevelManager.ArtObjects);

            this.HexahedronAo = new ArtObjectInstance(artObject)
            {
                Id = key
            };
            this.LevelManager.ArtObjects.Add(key, this.HexahedronAo);
            this.HexahedronAo.Initialize();
            this.HexahedronAo.Hidden = true;
            this.WhiteCube           = new Mesh()
            {
                Effect      = (BaseEffect) new DefaultEffect.VertexColored(),
                Blending    = new BlendingMode?(BlendingMode.Additive),
                DepthWrites = false
            };
            this.WhiteCube.Rotation = this.CameraManager.Rotation * Quaternion.CreateFromRotationMatrix(Matrix.CreateLookAt(Vector3.One, Vector3.Zero, Vector3.Up));
            this.WhiteCube.AddColoredBox(new Vector3(4f), Vector3.Zero, Color.White, true);
            FinalRebuildHost finalRebuildHost = this;
            Mesh             mesh1            = new Mesh();
            Mesh             mesh2            = mesh1;

            DefaultEffect.LitTextured litTextured1 = new DefaultEffect.LitTextured();
            litTextured1.Specular        = true;
            litTextured1.Emissive        = 0.5f;
            litTextured1.AlphaIsEmissive = true;
            DefaultEffect.LitTextured litTextured2 = litTextured1;
            mesh2.Effect   = (BaseEffect)litTextured2;
            mesh1.Blending = new BlendingMode?(BlendingMode.Opaque);
            Mesh mesh3 = mesh1;

            finalRebuildHost.SolidCubes = mesh3;
            this.OriginalCubeRotation   = this.SolidCubes.Rotation = this.WhiteCube.Rotation;
            ShaderInstancedIndexedPrimitives <VertexPositionNormalTextureInstance, Vector4> geometry1 = Enumerable.FirstOrDefault <Trile>(this.LevelManager.ActorTriles(ActorType.CubeShard)).Geometry;
            ShaderInstancedIndexedPrimitives <VertexPositionNormalTextureInstance, Vector4> geometry2 = Enumerable.FirstOrDefault <Trile>(this.LevelManager.ActorTriles(ActorType.SecretCube)).Geometry;

            this.sHexAppear      = this.CMProvider.CurrentLevel.Load <SoundEffect>("Sounds/Ending/HexRebuild/HexAppear");
            this.sCubeAppear     = this.CMProvider.CurrentLevel.Load <SoundEffect>("Sounds/Ending/HexRebuild/CubeAppear");
            this.sMotorSpin1     = this.CMProvider.CurrentLevel.Load <SoundEffect>("Sounds/Ending/HexRebuild/MotorStart1");
            this.sMotorSpin2     = this.CMProvider.CurrentLevel.Load <SoundEffect>("Sounds/Ending/HexRebuild/MotorStart2");
            this.sMotorSpinAOK   = this.CMProvider.CurrentLevel.Load <SoundEffect>("Sounds/Ending/HexRebuild/MotorStartAOK");
            this.sMotorSpinCrash = this.CMProvider.CurrentLevel.Load <SoundEffect>("Sounds/Ending/HexRebuild/MotorStartCrash");
            this.sRayWhiteout    = this.CMProvider.CurrentLevel.Load <SoundEffect>("Sounds/Ending/HexRebuild/RayWhiteout");
            this.sAku            = this.CMProvider.CurrentLevel.Load <SoundEffect>("Sounds/Ending/HexRebuild/Aku");
            this.sZoomIn         = this.CMProvider.CurrentLevel.Load <SoundEffect>("Sounds/Ending/HexRebuild/ZoomIn");
            this.sAmbientDrone   = this.CMProvider.CurrentLevel.Load <SoundEffect>("Sounds/Ending/HexRebuild/AmbientDrone");
            for (int index = 0; index < Math.Min(this.GameState.SaveData.CubeShards + this.GameState.SaveData.SecretCubes, 64); ++index)
            {
                Vector3 vector3 = this.CubeOffsets[index];
                ShaderInstancedIndexedPrimitives <VertexPositionNormalTextureInstance, Vector4> indexedPrimitives = index < this.GameState.SaveData.CubeShards ? geometry1 : geometry2;
                Group group = this.SolidCubes.AddGroup();
                group.Geometry = (IIndexedPrimitiveCollection) new IndexedUserPrimitives <VertexPositionNormalTextureInstance>(Enumerable.ToArray <VertexPositionNormalTextureInstance>((IEnumerable <VertexPositionNormalTextureInstance>)indexedPrimitives.Vertices), indexedPrimitives.Indices, indexedPrimitives.PrimitiveType);
                group.Position = vector3;
                group.Rotation = Quaternion.CreateFromAxisAngle(Vector3.Up, (float)RandomHelper.Random.Next(0, 4) * 1.570796f);
                group.Enabled  = false;
                group.Material = new Material();
            }
            this.SolidCubes.Texture = this.LevelMaterializer.TrilesMesh.Texture;
            this.InvertEffect       = new InvertEffect();
            this.RaysMesh           = new Mesh()
            {
                Effect      = (BaseEffect) new DefaultEffect.VertexColored(),
                Blending    = new BlendingMode?(BlendingMode.Additive),
                DepthWrites = false
            };
            this.FlareMesh = new Mesh()
            {
                Effect       = (BaseEffect) new DefaultEffect.Textured(),
                Texture      = (Dirtyable <Texture>)((Texture)this.CMProvider.Global.Load <Texture2D>("Other Textures/flare_alpha")),
                Blending     = new BlendingMode?(BlendingMode.Alphablending),
                SamplerState = SamplerState.AnisotropicClamp,
                DepthWrites  = false,
                AlwaysOnTop  = true
            };
            this.FlareMesh.AddFace(Vector3.One, Vector3.Zero, FaceOrientation.Front, true);
            this.RtHandle = this.TargetRenderer.TakeTarget();
            this.TargetRenderer.ScheduleHook(this.DrawOrder, this.RtHandle.Target);
            ServiceHelper.AddComponent((IGameComponent)(this.Glitches = new NesGlitches(this.Game)));
        }
Пример #13
0
        private void TryInitialize()
        {
            this.BatchedInstances.Clear();
            this.BatchedInstancesSet.Clear();
            this.CleanInstances.Clear();
            this.AllEmplacements.Clear();
            this.AllEmplacements.TrimExcess();
            this.CleanInstances.TrimExcess();
            this.BatchedInstances.TrimExcess();
            this.RandomTrileIds = (int[])null;
            if (this.Enabled)
            {
                this.LevelMaterializer.TrileInstanceBatched -= new Action <TrileInstance>(this.BatchInstance);
            }
            this.Enabled = false;
            if (!this.LevelManager.Quantum || this.LevelManager.TrileSet == null)
            {
                return;
            }
            this.Enabled = true;
            List <int> list1 = Enumerable.ToList <int>(Enumerable.Select <Trile, int>(Enumerable.Where <Trile>(this.LevelMaterializer.MaterializedTriles, (Func <Trile, bool>)(x =>
            {
                if (x.Geometry != null && !x.Geometry.Empty && !ActorTypeExtensions.IsTreasure(x.ActorSettings.Type))
                {
                    return(x.ActorSettings.Type != ActorType.SplitUpCube);
                }
                else
                {
                    return(false);
                }
            })), (Func <Trile, int>)(x => x.Id)));

            this.RandomTrileIds = new int[250];
            int num = 0;

            for (int index1 = 0; index1 < 250; ++index1)
            {
                int index2 = Quantumizer.Random.Next(0, list1.Count);
                int index3 = list1[index2];
                this.RandomTrileIds[num++] = index3;
                this.LevelManager.TrileSet[index3].ForceKeep = true;
                list1.RemoveAt(index2);
            }
            Trile trile = Enumerable.FirstOrDefault <Trile>((IEnumerable <Trile>) this.LevelManager.TrileSet.Triles.Values, (Func <Trile, bool>)(x => x.Name == "__QIPT"));

            if (trile == null)
            {
                trile = new Trile(CollisionType.None)
                {
                    Name           = "__QIPT",
                    Immaterial     = true,
                    SeeThrough     = true,
                    Thin           = true,
                    TrileSet       = this.LevelManager.TrileSet,
                    MissingTrixels = (TrixelCluster)null,
                    Id             = IdentifierPool.FirstAvailable <Trile>((IDictionary <int, Trile>) this.LevelManager.TrileSet.Triles)
                };
                this.LevelManager.TrileSet.Triles.Add(trile.Id, trile);
                this.LevelMaterializer.RebuildTrile(trile);
            }
            List <int> list2 = new List <int>();
            bool       flag  = (double)this.LevelManager.Size.X > (double)this.LevelManager.Size.Z;

            float[] numArray = new float[4]
            {
                0.0f,
                1.570796f,
                3.141593f,
                4.712389f
            };
            for (int y = 0; (double)y < (double)this.LevelManager.Size.Y; ++y)
            {
                if (flag)
                {
                    list2.Clear();
                    list2.AddRange(Enumerable.Range(0, (int)this.LevelManager.Size.Z));
                    for (int x = 0; (double)x < (double)this.LevelManager.Size.X; ++x)
                    {
                        int z;
                        if (list2.Count > 0)
                        {
                            int index = RandomHelper.Random.Next(0, list2.Count);
                            z = list2[index];
                            list2.RemoveAt(index);
                        }
                        else
                        {
                            z = RandomHelper.Random.Next(0, (int)this.LevelManager.Size.Z);
                        }
                        this.LevelManager.RestoreTrile(new TrileInstance(new TrileEmplacement(x, y, z), trile.Id)
                        {
                            Phi = numArray[Quantumizer.Random.Next(0, 4)]
                        });
                    }
                    while (list2.Count > 0)
                    {
                        int index = RandomHelper.Random.Next(0, list2.Count);
                        int z     = list2[index];
                        list2.RemoveAt(index);
                        this.LevelManager.RestoreTrile(new TrileInstance(new TrileEmplacement(RandomHelper.Random.Next(0, (int)this.LevelManager.Size.X), y, z), trile.Id)
                        {
                            Phi = numArray[Quantumizer.Random.Next(0, 4)]
                        });
                    }
                }
                else
                {
                    list2.Clear();
                    list2.AddRange(Enumerable.Range(0, (int)this.LevelManager.Size.X));
                    for (int z = 0; (double)z < (double)this.LevelManager.Size.Z; ++z)
                    {
                        int x;
                        if (list2.Count > 0)
                        {
                            int index = RandomHelper.Random.Next(0, list2.Count);
                            x = list2[index];
                            list2.RemoveAt(index);
                        }
                        else
                        {
                            x = RandomHelper.Random.Next(0, (int)this.LevelManager.Size.X);
                        }
                        this.LevelManager.RestoreTrile(new TrileInstance(new TrileEmplacement(x, y, z), trile.Id)
                        {
                            Phi = numArray[Quantumizer.Random.Next(0, 4)]
                        });
                    }
                    while (list2.Count > 0)
                    {
                        int index = RandomHelper.Random.Next(0, list2.Count);
                        int x     = list2[index];
                        list2.RemoveAt(index);
                        this.LevelManager.RestoreTrile(new TrileInstance(new TrileEmplacement(x, y, RandomHelper.Random.Next(0, (int)this.LevelManager.Size.Z)), trile.Id)
                        {
                            Phi = numArray[Quantumizer.Random.Next(0, 4)]
                        });
                    }
                }
            }
            foreach (TrileInstance trileInstance in (IEnumerable <TrileInstance>) this.LevelManager.Triles.Values)
            {
                trileInstance.VisualTrileId = new int?(this.RandomTrileIds[Quantumizer.Random.Next(0, this.RandomTrileIds.Length)]);
                trileInstance.RefreshTrile();
                trileInstance.NeedsRandomCleanup = true;
            }
            this.LevelMaterializer.CleanUp();
            this.LevelMaterializer.TrileInstanceBatched += new Action <TrileInstance>(this.BatchInstance);
        }