public void Draw() { Start(); if (instance != null) { Hide(); } instance = new LightRenderer(new GameObject("lightRenderer")); instance.transform.localScale = Vector3.one * radius; instance.transform.parent = transform; instance.transform.localPosition = Vector3.zero; instance.meshFilter.sharedMesh = ((GameObject)Resources.Load("SpecSphere", typeof(GameObject))).GetComponent <MeshFilter>().sharedMesh; #if UNITY_2018_1_OR_NEWER if (GraphicsSettings.currentRenderPipeline != null) { // Scriptable Render Pipeline Support instance.renderer.sharedMaterial = new Material(GraphicsSettings.currentRenderPipeline.defaultParticleMaterial.shader); instance.renderer.sharedMaterial.SetColor("_BaseColor", light.color * CalcBrightness()); } else #endif { // Built in Render Pipeline Support instance.renderer.sharedMaterial = new Material(Shader.Find("Particles/Standard Unlit")) { color = light.color * CalcBrightness() }; } instance.gameObject.isStatic = true; }
//-------------------------------------------------------------- #region Creation & Cleanup //-------------------------------------------------------------- public LightBufferRenderer(IGraphicsService graphicsService) { _graphicsService = graphicsService; LightRenderer = new LightRenderer(graphicsService); AmbientOcclusionType = AmbientOcclusionType.SSAO; _copyFilter = new CopyFilter(graphicsService); }
protected void ResetState(Vector3 position, Quaternion rotation) { m_slowTime = 0; m_state = State.IDLE; Vector3 v = transform.position; m_rigidbody.isKinematic = false; v.y = m_MaxYAxis; transform.position = position; transform.rotation = rotation; m_rigidbody.constraints = RigidbodyConstraints.None; m_rigidbody.angularVelocity = Vector3.zero; m_rigidbody.velocity = Vector3.zero; m_rigidbody.useGravity = true; renderer.enabled = true; collider.enabled = true; LightRenderer.Open(); OpenRenderer(); ReversePhysicalMaterial(); PhysicalSupportTools.Remove(gameObject, PhysicalSupportType.MaxSpeedLimit); RackBallCollision rb; if (rb = GetComponent <RackBallCollision>()) { Destroy(rb); } enabled = true; }
internal sealed override EffectTechnique ApplyEffectParams(LightRenderer renderer) { base.ApplyEffectParams(renderer); renderer._fxLightParamTexture.SetValue(Texture); return(renderer._fxTexturedLightTech); }
public void Dispose() { RsDebug?.Dispose(); _rsCw?.Dispose(); _rsCcw?.Dispose(); LightRenderer.Dispose(); LightMapRenderer.Dispose(); ShadowRenderer.Dispose(); }
private void Initialize() { graphicsDevice = ScreenManager.GraphicsDevice; content = ScreenManager.Content; spriteBatch = ScreenManager.SpriteBatch; font = ScreenManager.Font; MeshManager.InitializeManager(graphicsDevice, content); screenWidth = graphicsDevice.Viewport.Width; screenHeight = graphicsDevice.Viewport.Height; clearColor = new Color(0.0f, 0.0f, 0.0f, 0.0f); // Create Render Targets mainRT = new RenderTarget2D(graphicsDevice, screenWidth, screenHeight, false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8, 0, RenderTargetUsage.PreserveContents); reflectionRT = new RenderTarget2D(graphicsDevice, screenWidth / 2, screenHeight / 2, true, SurfaceFormat.Color, DepthFormat.Depth24Stencil8); occlusionRT = new RenderTarget2D(graphicsDevice, screenWidth / 8, screenHeight / 8, false, SurfaceFormat.Color, DepthFormat.None); bloomRT = new RenderTarget2D(graphicsDevice, screenWidth / 8, screenHeight / 8, false, SurfaceFormat.Color, DepthFormat.None); postEffects = new PostProcessingEffects(graphicsDevice, content.Load <Effect>(@"Effects\PostProcessingEffects")); // Create renderers lightRenderer = new LightRenderer(graphicsDevice, content.Load <Effect>(@"Effects\Light")); terrainRenderer = new TerrainRenderer(graphicsDevice, content.Load <Effect>(@"Effects\Terrain")); surfaceRenderer = new SurfaceRenderer(graphicsDevice, content.Load <Effect>(@"Effects\Surface")); waterRenderer = new WaterRenderer(graphicsDevice, content.Load <Effect>(@"Effects\Water")); billboardRenderer = new BillboardRenderer(graphicsDevice, content.Load <Effect>(@"Effects\Billboard")); meshRenderer = new MeshRenderer(graphicsDevice, content.Load <Effect>(@"Effects\Mesh")); // Create camera camera = new FirstPersonCamera(); camera.AspectRatio = graphicsDevice.Viewport.AspectRatio; camera.AABBSize = new Vector2(1.0f, 8.0f); camera.DrawDistance = 10000.0f; camera.MoveSpeed = 25.0f; camera.FreeFlyEnabled = false; camera.PitchMinDegrees = -75.0f; camera.PitchMaxDegrees = 60.0f; camera.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), camera.AspectRatio, 0.1f, 10000.0f); secretSFX = content.Load <SoundEffect>(@"SoundEffects\shotgun_pump"); // Load level data LoadLevel(@"Levels\" + levelFileName); }
public void Dispose() { if (!_disposed) { _disposed = true; LightRenderer.Dispose(); _ssaoFilter.SafeDispose(); _copyFilter.Dispose(); } }
void ApplayScreenUpdateLight() { //return; if (ScreenUpdateManager.GetChangeLight()) { LightRenderer.CalculateChangeScreen(ScreenUpdateManager.GetLightUptateWorldMin(), ScreenUpdateManager.GetLightUptateWorldMax()); LightLayerRender(); ScreenUpdateManager.EndUpdateLight(); } }
public void Hide() { if (instance != null) { if (instance.gameObject != null) { DestroyImmediate(instance.renderer.sharedMaterial); instance.Destroy(); } } instance = null; }
internal sealed override EffectTechnique ApplyEffectParams(LightRenderer renderer) { base.ApplyEffectParams(renderer); // MathHelper.Pi - 2 x ArcTan reduced. float halfAngle = MathHelper.PiOver2 - (float)Math.Atan(2 * Scale.X / Scale.Y); renderer._fxLightParamConeAngle.SetValue(halfAngle); renderer._fxLightParamConeDecay.SetValue(ConeDecay); return(renderer._fxSpotLightTech); }
internal static LightRenderer Create(Teapot model, vec3 lengths, string positionNameInIBufferable) { var shaderCodes = new ShaderCode[2]; shaderCodes[0] = new ShaderCode(System.IO.File.ReadAllText(@"shaders\LightRenderer\Light.vert"), ShaderType.VertexShader); shaderCodes[1] = new ShaderCode(System.IO.File.ReadAllText(@"shaders\LightRenderer\Light.frag"), ShaderType.FragmentShader); var map = new AttributeMap(); map.Add("in_Position", Teapot.strPosition); map.Add("in_Normal", Teapot.strNormal); //map.Add("in_Color", Teapot.strColor); var renderer = new LightRenderer(model, shaderCodes, map, positionNameInIBufferable); renderer.Lengths = lengths; return renderer; }
public LightBufferRenderer(IGraphicsService graphicsService) { LightRenderer = new LightRenderer(graphicsService); _ssaoFilter = new SsaoFilter(graphicsService) { // Normally the SsaoFilter applies the occlusion values directly to the // source texture. But here the filter should ignore the input image and // create grayscale image (white = no occlusion, black = max occlusion). CombineWithSource = false, }; _copyFilter = new CopyFilter(graphicsService); }
internal static LightRenderer Create(Teapot model, vec3 lengths, string positionNameInIBufferable) { var shaderCodes = new ShaderCode[2]; shaderCodes[0] = new ShaderCode(System.IO.File.ReadAllText(@"shaders\LightRenderer\Light.vert"), ShaderType.VertexShader); shaderCodes[1] = new ShaderCode(System.IO.File.ReadAllText(@"shaders\LightRenderer\Light.frag"), ShaderType.FragmentShader); var map = new AttributeMap(); map.Add("in_Position", Teapot.strPosition); map.Add("in_Normal", Teapot.strNormal); //map.Add("in_Color", Teapot.strColor); var renderer = new LightRenderer(model, shaderCodes, map, positionNameInIBufferable); renderer.Lengths = lengths; return(renderer); }
public static AlphaRef LightRendererAlpha(LightRenderer renderer) { Func <float> get = () => renderer.brightness; Action <float> set = (a) => { renderer.brightness = a; if (a == 0) { renderer.viewMesh.enabled = false; } else { renderer.viewMesh.enabled = true; } }; return(new AlphaRef(set, get)); }
public void Load(GraphicsDevice device, GraphicsDeviceManager deviceManager, GameWindow window, Effect fxHull, Effect fxLight, Effect fxShadow, Effect fxTexture) { Device = device; DeviceManager = deviceManager; Window = window; BuildGraphicsResources(); // Load providers. Camera.Load(this); Textures.Load(this); // Load renderers. LightMapRenderer.Load(this, fxTexture); ShadowRenderer.Load(this, fxShadow, fxHull); LightRenderer.Load(this, fxLight); }
public void Draw() { Start(); if (instance != null) { Hide(); } instance = new LightRenderer(new GameObject("lightRenderer")); instance.transform.localScale = Vector3.one * radius; instance.transform.parent = transform; instance.transform.localPosition = Vector3.zero; instance.meshFilter.sharedMesh = ((GameObject)Resources.Load("SpecSphere", typeof(GameObject))).GetComponent <MeshFilter>().sharedMesh; instance.renderer.sharedMaterial = new Material(Shader.Find("Particles/Standard Unlit")) { color = light.color * CalcBrightness() }; instance.gameObject.isStatic = true; }
internal sealed override EffectTechnique ApplyEffectParams(LightRenderer renderer) { base.ApplyEffectParams(renderer); return(renderer._fxPointLightTech); }
public void Load(string file, GraphicsDevice graphicsDevice) { int width = -1; int height = -1; int tilesize = -1; List <TiledObjectGroup> objectGroups = new List <TiledObjectGroup>(); List <MapLayer> layers = new List <MapLayer>(); TileSetManager ts = new TileSetManager(); hope = new LightRenderer(graphicsDevice, this); using (XmlReader xr = XmlReader.Create(file)) { while (xr.Read()) { if (xr.NodeType == XmlNodeType.EndElement) { continue; } switch (xr.Name) { case "tileset": using (StringReader sr = new StringReader(xr.ReadOuterXml())) using (XmlReader r = XmlReader.Create(sr)) ts.LoadTileSet(file, r, graphicsDevice); break; case "layer": MapLayer layer = null; string name = xr["name"]; using (StringReader sr = new StringReader(xr.ReadOuterXml())) using (XmlReader r = XmlReader.Create(sr)) layer = MapLayer.Load(r, graphicsDevice, ts, System.IO.Path.GetDirectoryName(file)); if (!name.StartsWith("Light")) { layers.Add(layer); } else { hope.AddLayer(layer); } break; case "map": width = int.Parse(xr["width"]); height = int.Parse(xr["height"]); tilesize = int.Parse(xr["tilewidth"]); //should be same as tileheight break; case "objectgroup": TiledObjectGroup og = new TiledObjectGroup(xr["name"]); og.Load(xr); objectGroups.Add(og); break; default: break; } } } BasicTile.SetTileSize(tilesize); this.width = width; this.height = height; this.ObjectGroups = objectGroups.ToArray(); this.Layers = layers.ToArray(); hope.LoadTileSets(ts); nodes = new Node[width, height]; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { nodes[x, y] = new Node(new Index2(x, y)); } } for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { nodes[x, y].SetNeighbours(GetNeighbours(x, y)); } } var lightbulbs = GetGroupByName("Lights"); foreach (var lightbulb in lightbulbs.Objects) { hope.AddLight(new Light((Index2)lightbulb.Position, (short)lightbulb.Properties.GetPropertyAsInt("Strength"), 1f, lightbulb.Properties.GetPropertyAsColor("Color"))); } }
internal virtual EffectTechnique ApplyEffectParams(LightRenderer renderer) { renderer._fxLightParamColor.SetValue(_color); renderer._fxLightParamIntensity.SetValue(IntensityFactor); return(null); }
public void Render() { // Update hulls internal data structures. Hulls.Update(); // We want to use clamping sampler state throughout the lightmap rendering process. // This is required when drawing lights. Since light rendering and alpha clearing is done // in a single step, light is rendered with slightly larger quad where tex coords run out of the [0..1] range. Device.SamplerStates[0] = SamplerState.LinearClamp; // Switch render target to lightmap. Device.SetRenderTargets(Textures.LightmapBindings); // Clear lightmap color, depth and stencil data. Device.Clear(ClearOptions.DepthBuffer | ClearOptions.Stencil | ClearOptions.Target, _ambientColor, 1f, 0); // Set per frame shader data. ShadowRenderer.PreRender(); // Generate lightmap. For each light, mask the shadowed areas determined by hulls and render light. int lightCount = Lights.Count; for (int i = 0; i < lightCount; i++) { Light light = Lights[i]; // Continue only if light is enabled and not inside any hull. if (!light.Enabled || Hulls.Contains(light)) { continue; } // Update light's internal data structures. light.Update(); // Continue only if light is within camera view. if (!light.Intersects(Camera)) { continue; } // Set scissor rectangle to clip any shadows outside of light's range. BoundingRectangle scissor; Camera.GetScissorRectangle(light, out scissor); Device.SetScissorRectangle(ref scissor); // Mask shadowed areas by reducing alpha. ShadowRenderer.Render(light); // Draw light and clear alpha (reset it to 1 [fully lit] for next light). LightRenderer.Render(light); // Clear light's dirty flag. light.Dirty = false; } // Switch render target back to default. Device.SetRenderTargets(Textures.GetOriginalRenderTargetBindings()); // Blend original scene and lightmap and present to backbuffer. LightMapRenderer.Present(); // Clear hulls dirty flag. Hulls.Dirty = false; }
//-------------------------------------------------------------- #region Methods //-------------------------------------------------------------- public void Render(IList <SceneNode> lights, RenderContext context) { var graphicsService = context.GraphicsService; var graphicsDevice = graphicsService.GraphicsDevice; var renderTargetPool = graphicsService.RenderTargetPool; var target = context.RenderTarget; var viewport = context.Viewport; var width = viewport.Width; var height = viewport.Height; RenderTarget2D aoRenderTarget = null; if (_ssaoFilter != null) { // Render ambient occlusion info into a render target. aoRenderTarget = renderTargetPool.Obtain2D(new RenderTargetFormat( width / _ssaoDownsampleFactor, height / _ssaoDownsampleFactor, false, SurfaceFormat.Color, DepthFormat.None)); // PostProcessors require that context.SourceTexture is set. But since // _ssaoFilter.CombineWithSource is set to false, the SourceTexture is not // used and we can set it to anything except null. context.SourceTexture = aoRenderTarget; context.RenderTarget = aoRenderTarget; context.Viewport = new Viewport(0, 0, aoRenderTarget.Width, aoRenderTarget.Height); _ssaoFilter.Process(context); context.SourceTexture = null; } // The light buffer consists of two full-screen render targets into which we // render the accumulated diffuse and specular light intensities. var lightBufferFormat = new RenderTargetFormat(width, height, false, SurfaceFormat.HdrBlendable, DepthFormat.Depth24Stencil8); context.LightBuffer0 = renderTargetPool.Obtain2D(lightBufferFormat); context.LightBuffer1 = renderTargetPool.Obtain2D(lightBufferFormat); // Set the device render target to the light buffer. _renderTargetBindings[0] = new RenderTargetBinding(context.LightBuffer0); // Diffuse light accumulation _renderTargetBindings[1] = new RenderTargetBinding(context.LightBuffer1); // Specular light accumulation graphicsDevice.SetRenderTargets(_renderTargetBindings); context.RenderTarget = context.LightBuffer0; context.Viewport = graphicsDevice.Viewport; // Clear the light buffer. (The alpha channel is not used. We can set it to anything.) graphicsDevice.Clear(new Color(0, 0, 0, 255)); // Restore the depth buffer (which XNA destroys in SetRenderTarget). // (This is only needed if lights can use a clip geometry (LightNode.Clip).) var rebuildZBufferRenderer = (RebuildZBufferRenderer)context.Data[RenderContextKeys.RebuildZBufferRenderer]; rebuildZBufferRenderer.Render(context, true); // Render all lights into the light buffers. LightRenderer.Render(lights, context); if (aoRenderTarget != null) { // Render the ambient occlusion texture using multiplicative blending. // This will darken the light buffers depending on the ambient occlusion term. // Note: Theoretically, this should be done after the ambient light renderer // and before the directional light renderer because AO should not affect // directional lights. But doing this here has more impact. context.SourceTexture = aoRenderTarget; graphicsDevice.BlendState = GraphicsHelper.BlendStateMultiply; _copyFilter.Process(context); } // Clean up. graphicsService.RenderTargetPool.Recycle(aoRenderTarget); context.SourceTexture = null; context.RenderTarget = target; context.Viewport = viewport; _renderTargetBindings[0] = new RenderTargetBinding(); _renderTargetBindings[1] = new RenderTargetBinding(); }
public void Render() { p1 = camera.ViewportToWorldPoint(new Vector3(0, 0, camera.nearClipPlane)); int offsetX = Mathf.CeilToInt(p1.x / tileSize); int offsetY = Mathf.CeilToInt(p1.y / tileSize); Vector3 newPos = new Vector2(offsetX * tileSize - 2 * tileSize, offsetY * tileSize - 2 * tileSize); int dist = (int)Vector2.Distance(lastP1, newPos); if (dist >= tileSize) { Vector2 delta = newPos - lastP1; var deltaX = (int)(Mathf.Sign(delta.x) * Mathf.CeilToInt(Mathf.Abs(delta.x / tileSize))); var deltaY = (int)(Mathf.Sign(delta.y) * Mathf.CeilToInt(Mathf.Abs(delta.y / tileSize))); lastP1 = newPos; screenStart = new Vector2Int(Mathf.CeilToInt(p1.x / tileSize), Mathf.CeilToInt(p1.y / tileSize)); screenEnd = new Vector2Int((int)(screenStart.x + countTileX), (int)(screenStart.y + countTileY)); ScreenUpdateManager.SetScreenRect(screenStart, screenEnd); LightRenderer.SetScreenRect(screenStart, screenEnd); var add = obstacleLight.layerData.SizeAdd; SwapItemManager.SetSize(screenEnd.x - screenStart.x + 2 * add, screenEnd.y - screenStart.y + 2 * add); //SwapItemManager.SetStartPos(new Vector2Int(screenStart.x - add, screenStart.y - add)); //определяем свапнутую область int swapStartX = 0; int swapEndX = Mathf.CeilToInt(countTileX); int swapStartY = 0; int swapEndY = Mathf.CeilToInt(countTileY); if (deltaX > 0) { swapStartX = 0; swapEndX = Mathf.CeilToInt(countTileX - deltaX) - 3; } if (deltaX < 0) { swapStartX = -(int)deltaX; swapEndX = Mathf.CeilToInt(countTileX); } if (deltaY > 0) { swapStartY = 0; swapEndY = Mathf.CeilToInt(countTileY - deltaY) - 3; } if (deltaY < 0) { swapStartY = -(int)deltaY; swapEndY = Mathf.CeilToInt(countTileY); } for (int ii = 0; ii < layerMeshs.Count; ii++) { layerMeshs[ii].ShiftCells((int)deltaX, (int)deltaY); } obstacleLight.ShiftCells((int)deltaX, (int)deltaY); LightRenderer.Swap((int)deltaX, (int)deltaY); // -< SwapItemManager.SetStartPos(new Vector2Int(screenStart.x - add, screenStart.y - add)); SwapItemManager.Swap((int)deltaX, (int)deltaY); for (int i = 0; i < countTileX - 1; i++) { for (int j = 0; j < countTileY - 1; j++) { bool inSwapRect = i >= swapStartX && i <= swapEndX && j >= swapStartY && j <= swapEndY; if (inSwapRect) { continue; } var x = p1.x + i * tileSize; var y = p1.y + j * tileSize; var tileStructure = tileDataProvider.GetTileStructure(x, y); for (int ii = 0; ii < layerMeshs.Count; ii++) { var frameStructure = tileDataProvider.GetFrameStructure(x, y, tileStructure, layerMeshs[ii].layerData); layerMeshs[ii].ChangeTile(j, i, frameStructure.TileCollection, frameStructure.FrameX, frameStructure.FrameY, frameStructure.DeltaHeight); } } } for (int i = 0; i < layerMeshs.Count; i++) { layerMeshs[i].RenderMesh(); } // RenderLayerAddSize(obstacleLight, obstacleLight.layerData.SizeAdd, deltaX, deltaY); // -< tixtuteGO.transform.position = newPos; OnSwap.TryCall(); } }
void Update() { if (LightUvProvider != null) { LightUvProvider.LateUpdate(); } if (tileDataProvider == null) { return; } if (Input.GetKeyUp(KeyCode.T)) { LightRenderer.Test(); LightLayerRender(true); } if (Input.GetKeyUp(KeyCode.G)) { MapGenerator.ChangeMap(); } if (Input.GetKeyUp(KeyCode.Alpha0)) { carrentMarkerType = 0; carrentMarkerLayer = 0; } if (Input.GetKeyUp(KeyCode.Alpha8)) { carrentMarkerType = 8; carrentMarkerLayer = 3; } if (Is_Edit_mod) { if (Input.GetMouseButton(0)) { countClick++; var pos = camera.ScreenToWorldPoint(Input.mousePosition); tileDataProvider.СircleDamageTile(pos.x + 1.5f * tileSize, pos.y + 1.5f * tileSize, carrentMarkerType, carrentMarkerLayer, carrentMarkeLiquidType, 1); lastP1 = new Vector3(); UpdateScreenTiles(); // Render(); } if (Input.GetMouseButton(1)) { var pos = camera.ScreenToWorldPoint(Input.mousePosition); var tile = tileDataProvider.GetTileStructure(pos.x + 1.5f * tileSize, pos.y + 1.5f * tileSize); // pos.x, pos.y); carrentMarkerType = tile.type; carrentMarkerLayer = tile.layer; carrentMarkeLiquidType = tile.liquidType; } } if (Input.GetKeyUp(KeyCode.R)) { tileDataProvider.LoadNext(); lastP1 = new Vector3(); UpdateScreenTiles(); // Render(); } //Profiler.BeginSample("1"); UpdateScreenTiles(); //Profiler.EndSample(); //Profiler.BeginSample("2"); ApplayScreenUpdate(); //Profiler.EndSample(); //Profiler.BeginSample("3"); Render(); //Profiler.EndSample(); //Profiler.BeginSample("4"); if (useLight) { ApplayScreenUpdateLight(); } //Profiler.EndSample(); LightRenderer.Update(); ScreenUpdateManager.RedrawFullScreenLight(); }