private void OnAddBlockBefore(ChunkPrimer chunk, int x, int y, int z, VoxelMaterial voxel) { Task.Run(() => { _dbControl.InsertBlock(chunk.position.x, chunk.position.y, chunk.position.z, x, y, z, voxel.GetInstanceID()); }); }
public virtual void SetVoxel(int x, int y, int z, VoxelMaterial material) { var type = MaterialRegistry.Instance.GetMaterialId(material); if (Voxels[x, y, z] == null && type == 0 || Voxels[x, y, z] != null && type == Voxels[x, y, z].BlockType) { return; } if (type == 0) // set to air { Voxels[x, y, z] = null; } else { if (Voxels[x, y, z] == null) { Voxels[x, y, z] = new VoxelData(type); } else { Voxels[x, y, z].BlockType = type; } } DirtyVoxels.Add(new Vector3(x, y, z)); }
public override void SetVoxel(int x, int y, int z, VoxelMaterial material) { base.SetVoxel(x, y, z, material); Vector3 pos; if (!material.Equals(MaterialRegistry.Instance.GetMaterialFromName("Air"))) { pos = new Vector3(x, y - 1, z); if (_smallMultiblocks.ContainsKey(pos)) { var mb = _smallMultiblocks[pos]; _smallMultiblocks.Remove(pos); Object.Destroy(mb.gameObject); } } pos = new Vector3(x, y, z); if (_smallMultiblocks.ContainsKey(pos)) { var mb = _smallMultiblocks[pos]; _smallMultiblocks.Remove(pos); Object.Destroy(mb.gameObject); } OnContainerUpdated(); }
public void TestRenderIsland() { var dirtMaterial = new VoxelMaterial(); dirtMaterial.Texture = TW.Assets.LoadTexture("GrassGreenTexture0006.jpg"); var size = 20; var island = new ArrayFiniteVoxels(new Point3(size, size, size)); island.NodeSize = 0.25f; for (int i = 0; i < size; i++) { for (int j = i; j < size - i; j++) { for (int k = i; k < size - i; k++) { island.SetVoxel(new Point3(j, -i + size - 1, k), dirtMaterial); } } } var c = new VoxelMeshBuilder(); var mesh = c.BuildMesh(island); var e = new Entity(); e.Mesh = mesh; }
private void OnRemoveBlockBefore(ChunkPrimer chunk, int x, int y, int z, VoxelMaterial voxel) { Task.Run(() => { _dbControl.RemoveBlock(chunk.position.x, chunk.position.y, chunk.position.z, x, y, z); }); }
public Rect(int x, int y, VoxelMaterial type) { X = x; Y = y; Width = 1; Height = 1; Type = type; }
public static Rect[] CreateRectsForPlane(VoxelMaterial[,] plane) { var rects = new List <Rect>(); var visited = new bool[plane.GetLength(0), plane.GetLength(1)]; Rect curRectangle = null; VoxelMaterial curType = null; for (var j = 0; j < plane.GetLength(1); j++) { for (var i = 0; i < plane.GetLength(0); i++) { var vox = plane[i, j]; if (!Equals(vox, curType) || visited[i, j]) //End Rect because of current voxel { if (curRectangle != null) { ExpandVertically(curRectangle, curType, plane); rects.Add(curRectangle); SetVisited(curRectangle, visited); curRectangle = null; } if (visited[i, j]) { continue; } } if (vox != null) //Create new Rect if there is no { if (curRectangle == null) { curRectangle = new Rect(i, j, vox); curType = vox; } else { curRectangle.Width++; } } if (i == plane.GetLength(1) - 1) // End because of Border { if (curRectangle != null) { ExpandVertically(curRectangle, curType, plane); rects.Add(curRectangle); SetVisited(curRectangle, visited); curRectangle = null; } } } } return(rects.ToArray()); }
protected internal VoxelMaterial Create(string name, MaterialTyp typ, Color c, Drop[] drops, bool fixedColor = false) { if (!_counterTyp.ContainsKey(typ)) { _counterTyp[typ] = 0; } var vm = new VoxelMaterial(_counterTyp[typ]++, typ, fixedColor ? c : GetSimilarColor(c), VoxelMaterials.Values.Count, drops); VoxelMaterials[vm.Id] = vm; VoxelMaterialByName[name] = vm; return(vm); }
public VoxelPrimitive(byte begin_x, byte end_x, byte begin_y, byte end_y, byte begin_z, byte end_z, VoxelVisiableFaces _faces, VoxelMaterial _material) { begin.x = begin_x; begin.y = begin_y; begin.z = begin_z; end.x = end_x; end.y = end_y; end.z = end_z; material = _material; faces = _faces; }
public VoxelPrimitive(Vector3 begin, Vector3 end, VoxelMaterial _material) { this.begin = begin; this.end = end; material = _material; faces.left = true; faces.right = true; faces.top = true; faces.bottom = true; faces.front = true; faces.back = true; }
private void RenderMRT(RenderBuffer[] renderBuffers, RenderBuffer depthBuffer) { Graphics.SetRenderTarget(renderBuffers, depthBuffer); GL.Clear(false, true, Color.clear); GL.PushMatrix(); GL.LoadOrtho(); VoxelMaterial.SetPass(6); GL.Begin(GL.QUADS); GL.TexCoord2(0.0f, 0.0f); GL.Vertex3(0.0f, 0.0f, 0.1f); GL.TexCoord2(1.0f, 0.0f); GL.Vertex3(1.0f, 0.0f, 0.1f); GL.TexCoord2(1.0f, 1.0f); GL.Vertex3(1.0f, 1.0f, 0.1f); GL.TexCoord2(0.0f, 1.0f); GL.Vertex3(0.0f, 1.0f, 0.1f); GL.End(); GL.PopMatrix(); }
public void TestRenderEmptyVoxel() { var dirtMaterial = new VoxelMaterial(); dirtMaterial.Texture = TW.Assets.LoadTexture("GrassGreenTexture0006.jpg"); var island = new ArrayFiniteVoxels(new Point3(1, 1, 1)); var c = new VoxelMeshBuilder(); var mesh = c.BuildMesh(island); var e = new Entity(); e.Mesh = mesh; }
public override bool Stroke(Ray ray, BrickTree tree, VoxelMaterial voxelMaterial, VoxelMaterialAtlas materialAtlas, List <byte> blackList, Queue <OctreeEntry <Brick> > outChangedBricks, Bounds bounds) { OctreeEntry <Brick> brickEntry = FirstBrickIntersected(ray, tree, blackList); Brick brick = brickEntry.entry; Vector3 brickPosition = brickEntry.bounds.min; found.Clear(); selector.Select(ray, brick, brickPosition, blackList, found); if (found.Count == 0) { return(false); } Vector3i cell = found.Dequeue(); brick.SetValue(cell.x, cell.y, cell.z, materialAtlas.GetMaterialId(voxelMaterial)); outChangedBricks.Enqueue(brickEntry); if (cell.x == 0) { OctreeEntry <Brick> modified = tree.GetAt(brickEntry.cell.x - 1, brickEntry.cell.y, brickEntry.cell.z); outChangedBricks.Enqueue(modified); } if (cell.y == 0) { OctreeEntry <Brick> modified = tree.GetAt(brickEntry.cell.x, brickEntry.cell.y - 1, brickEntry.cell.z); outChangedBricks.Enqueue(modified); } if (cell.z == 0) { OctreeEntry <Brick> modified = tree.GetAt(brickEntry.cell.x, brickEntry.cell.y, brickEntry.cell.z - 1); outChangedBricks.Enqueue(modified); } return(true); }
internal static void ExpandVertically(Rect curRectangle, VoxelMaterial curType, VoxelMaterial[,] plane) { while (true) { if (curRectangle.Y + curRectangle.Height == plane.GetLength(1)) { return; //reached bottom } //check next line for (var i = curRectangle.X; i < curRectangle.X + curRectangle.Width; i++) { if (!Equals(plane[i, curRectangle.Y + curRectangle.Height], curType)) { return; // found wrong type } } curRectangle.Height++; } }
public static void DrawCapsule(Vector3 start, Vector3 end, float veinRadius, VoxelMaterial material, VoxelMaterial replace = null) { var minx = (int)(Mathf.Min(start.x, end.x) - veinRadius); var miny = (int)(Mathf.Min(start.y, end.y) - veinRadius); var minz = (int)(Mathf.Min(start.z, end.z) - veinRadius); var maxx = (int)(Mathf.Max(start.x, end.x) + veinRadius); var maxy = (int)(Mathf.Max(start.y, end.y) + veinRadius); var maxz = (int)(Mathf.Max(start.z, end.z) + veinRadius); var direction = (start - end).normalized; var ray = new Ray(start, direction); for (int x = minx; x < maxx; x++) { for (int y = miny; y < maxy; y++) { for (int z = minz; z < maxz; z++) { if (!Map.Instance.IsInBounds(x, y, z)) { continue; } if (Vector3.Cross(ray.direction, new Vector3(x, y, z) - ray.origin).magnitude <= veinRadius) { var intersect = ray.origin + ray.direction * Vector3.Dot(ray.direction, new Vector3(x, y, z) - ray.origin); if (!((start - end).magnitude < (start - intersect).magnitude || (end - start).magnitude < (end - intersect).magnitude)) { if (replace == null || World.At(x, y, z).GetMaterial().Equals(replace)) { World.At(x, y, z).SetVoxel(material); } } } if ((new Vector3(x, y, z) - start).magnitude <= veinRadius || (new Vector3(x, y, z) - end).magnitude <= veinRadius) { if (replace == null || World.At(x, y, z).GetMaterial().Equals(replace)) { World.At(x, y, z).SetVoxel(material); } } } } } }
public VoxelPrimitive(byte begin_x, byte end_x, byte begin_y, byte end_y, byte begin_z, byte end_z, VoxelMaterial _material) { begin.x = begin_x; begin.y = begin_y; begin.z = begin_z; end.x = end_x; end.y = end_y; end.z = end_z; material = _material; faces.left = true; faces.right = true; faces.top = true; faces.bottom = true; faces.front = true; faces.back = true; }
public PlanetMaterial(MyPlanetMaterialDefinition def) { Depth = def.MaxDepth; if (def.Material != null) Material = GetMaterial(def.Material); Value = def.Value; if (def.HasLayers) { Layers = new VoxelMaterial[def.Layers.Length]; for (int i = 0; i < Layers.Length; i++) { Layers[i] = new VoxelMaterial(); Layers[i].Material = GetMaterial(def.Layers[i].Material); Layers[i].Depth = def.Layers[i].Depth; } } }
public void Extract(BrickTree brickTree, Vector3i brickWorld, List <Color> colors, List <Vector3> vertices, List <Vector3> normals, List <Vector2> uv, List <int> indices, Pool <Color> colorPool, Pool <Vector2> vector2Pool, Pool <Vector3> vector3Pool) { int xOffset = brickTree.BrickDimensionX * brickWorld.x; int yOffset = brickTree.BrickDimensionY * brickWorld.y; int zOffset = brickTree.BrickDimensionZ * brickWorld.z; ColorUtil colorUtil = new ColorUtil(); int normalDirection; for (int x = 0; x < brickTree.BrickDimensionX; ++x) { for (int y = 0; y < brickTree.BrickDimensionY; ++y) { for (int z = 0; z < brickTree.BrickDimensionZ; ++z) { int trueX = x + xOffset; int trueY = y + yOffset; int trueZ = z + zOffset; VoxelMaterial voxel = materialAtlas.GetVoxelMaterial(brickTree.GetVoxelAt(trueX, trueY, trueZ)); VoxelMaterial voxelPlusX = materialAtlas.GetVoxelMaterial(brickTree.GetVoxelAt(trueX + 1, trueY, trueZ)); VoxelMaterial voxelPlusY = materialAtlas.GetVoxelMaterial(brickTree.GetVoxelAt(trueX, trueY + 1, trueZ)); VoxelMaterial voxelPlusZ = materialAtlas.GetVoxelMaterial(brickTree.GetVoxelAt(trueX, trueY, trueZ + 1)); if (CheckForTransition(voxel, voxelPlusX, out normalDirection)) { AddQuadX(voxel, x, y, z, normalDirection, colors, vertices, normals, uv, indices, colorPool, vector2Pool, vector3Pool, colorUtil); } if (CheckForTransition(voxel, voxelPlusY, out normalDirection)) { AddQuadY(voxel, x, y, z, normalDirection, colors, vertices, normals, uv, indices, colorPool, vector2Pool, vector3Pool, colorUtil); } if (CheckForTransition(voxel, voxelPlusZ, out normalDirection)) { AddQuadZ(voxel, x, y, z, normalDirection, colors, vertices, normals, uv, indices, colorPool, vector2Pool, vector3Pool, colorUtil); } } } } }
public void PaintWithRay(Ray ray, VoxelBrush brush, VoxelMaterial material) { Queue <OctreeEntry <Brick> > changed = new Queue <OctreeEntry <Brick> >(); Bounds bounds = new Bounds(); bounds.SetMinMax(new Vector3(1, 1, 1), new Vector3(maxDimensions.x * voxelTree.BrickDimensionX - 1, maxDimensions.y * voxelTree.BrickDimensionY - 1, maxDimensions.z * voxelTree.BrickDimensionZ - 1)); if (brush.Stroke(ray, voxelTree, material, materialAtlas, materialAtlas.airMaterials, changed, bounds)) { while (changed.Count > 0) { OctreeEntry <Brick> entry = changed.Dequeue(); if (entry == null) { continue; } createBrick(entry.cell.x, entry.cell.y, entry.cell.z); } } }
public IFiniteVoxels GenerateIsland(int size) { var mat = new VoxelMaterial(); var map = GenerateBottomIslandHeightmap(size); MakeIslandShape(map); var max = 0f; for (int x = 0; x < map.Size.X; x++) { for (int y = 0; y < map.Size.Y; y++) { var val = map[new Point2(x, y)]; max = val > max ? val : max; } } var ret = new ArrayFiniteVoxels(new Point3(map.Size.X, (int)Math.Floor(max) + 1, map.Size.Y)); for (int x = 0; x < map.Size.X; x++) { for (int y = 0; y < map.Size.Y; y++) { var val = map[new Point2(x, y)]; for (int i = -(int)val; i < -2; i++) { ret.SetVoxel(new Point3(x, i + ret.Size.Y - 1, y), mat); } } } return(ret); }
private void AddQuadX(VoxelMaterial voxel, int x, int y, int z, int normalDirection, List <Color> colors, List <Vector3> vertices, List <Vector3> normals, List <Vector2> uv, List <int> indices, Pool <Color> colorPool, Pool <Vector2> vector2Pool, Pool <Vector3> vector3Pool, ColorUtil colorUtil) { int vertexIndex = vertices.Count; Color color = colorPool.Catch(); color = voxel.color; colors.Add(color); color = colorPool.Catch(); color = voxel.color; colors.Add(color); color = colorPool.Catch(); color = voxel.color; colors.Add(color); color = colorPool.Catch(); color = voxel.color; colors.Add(color); Vector3 fish = vector3Pool.Catch(); fish.Set(x + 1, y, z); vertices.Add(fish); fish = vector3Pool.Catch(); fish.Set(x + 1, y + 1, z); vertices.Add(fish); fish = vector3Pool.Catch(); fish.Set(x + 1, y, z + 1); vertices.Add(fish); fish = vector3Pool.Catch(); fish.Set(x + 1, y + 1, z + 1); vertices.Add(fish); fish = vector3Pool.Catch(); fish.Set(normalDirection, 0, 0); normals.Add(fish); normals.Add(fish); normals.Add(fish); normals.Add(fish); Vector2 smallFish = vector2Pool.Catch(); smallFish.Set(0, 0); uv.Add(smallFish); smallFish = vector2Pool.Catch(); smallFish.Set(1, 0); uv.Add(smallFish); smallFish = vector2Pool.Catch(); smallFish.Set(0, 1); uv.Add(smallFish); smallFish = vector2Pool.Catch(); smallFish.Set(1, 1); uv.Add(smallFish); if (voxel.stateOfMatter == StateOfMatter.GAS) { indices.Add(vertexIndex + 2); indices.Add(vertexIndex + 1); indices.Add(vertexIndex); indices.Add(vertexIndex + 1); indices.Add(vertexIndex + 2); indices.Add(vertexIndex + 3); } else { indices.Add(vertexIndex); indices.Add(vertexIndex + 1); indices.Add(vertexIndex + 2); indices.Add(vertexIndex + 3); indices.Add(vertexIndex + 2); indices.Add(vertexIndex + 1); } }
private void OnRemoveBlockAfter(ChunkPrimer chunk, int x, int y, int z, VoxelMaterial voxel) { }
public void SetVoxel(Point3 pos, VoxelMaterial dirtMaterial) { throw new NotImplementedException(); }
public void AddVoxelMaterial(byte id, VoxelMaterial material) { idToMaterial.Add(id, material); materialToId.Add(material, id); }
public byte GetMaterialId(VoxelMaterial material) { return(materialToId[material]); }
private void CreatePath(List <Raido> markersPath, List <Mannaz> markersBase, VoxelMaterial dirt, VoxelMaterial grass) { var transforms = new List <Transform>(); if (markersPath.Count > 0) { transforms.AddRange(markersPath.OrderBy(m => m.Number).Select(m => m.transform)); } if (markersBase.Count > 0) { transforms.AddRange(markersBase.Select(m => m.transform)); } if (transforms.Count < 2) { return; } var list = Bezier.GetBSplinePoints(transforms.Select(m => m.position).ToList(), 10f); Path = BuildWalkablePath(list); for (var i = 1; i < list.Count; i++) { ResourceManager.DrawCapsule(list[i - 1], list[i], 3f, dirt, grass); } }
public int GetMaterialId(VoxelMaterial material) { return(material.Id); }
public BuildingJob(Vector3 position, VoxelMaterial material) : base(position, 1.1f, new Color(material.Color.r, material.Color.g, material.Color.b, 0.5f), Overlay.Building, "Building") { _material = material; RemainingTime = 1f; }
public override bool Stroke(Ray ray, BrickTree tree, VoxelMaterial voxelMaterial, VoxelMaterialAtlas materialAtlas, List <byte> blackList, Queue <OctreeEntry <Brick> > outChangedBricks, Bounds bounds) { // Find the brick intersected OctreeEntry <Brick> brickEntry = FirstBrickIntersected(ray, tree, blackList); // If we can't find one return if (brickEntry == null) { return(false); } Brick brick = brickEntry.entry; Vector3 brickPosition = brickEntry.bounds.min; dummyVector3.Set(brickEntry.cell.x, brickEntry.cell.y, brickEntry.cell.z); // Make sure the brick is within the legal paining bounds if (!bounds.Contains(dummyVector3)) { // return false; } // Clear the resused found queue found.Clear(); // Find which cells are intersected within the grid selector.Select(ray, brick, brickPosition, blackList, found); if (found.Count == 0) { return(false); } Vector3i firstIntersection = found.Dequeue(); Ray offsetRay = new Ray(new Vector3(ray.origin.x - brickPosition.x, ray.origin.y - brickPosition.y, ray.origin.z - brickPosition.z), ray.direction); float distance; RayEntersCellFromCell(offsetRay, firstIntersection, dummyVector3i, out distance); Vector3i adjacentLocal = dummyVector3i; Vector3i adjacentWorld = adjacentLocal + brickEntry.bounds.min; dummyVector3.Set(adjacentWorld.x, adjacentWorld.y, adjacentWorld.z); if (!bounds.Contains(dummyVector3)) { return(false); } tree.SetVoxelAt(adjacentWorld.x, adjacentWorld.y, adjacentWorld.z, materialAtlas.GetMaterialId(voxelMaterial)); Vector3i cellModified = new Vector3i(adjacentWorld.x / tree.BrickDimensionX, adjacentWorld.y / tree.BrickDimensionY, adjacentWorld.z / tree.BrickDimensionZ); OctreeEntry <Brick> modified = tree.GetAt(cellModified.x, cellModified.y, cellModified.z); outChangedBricks.Enqueue(modified); if (adjacentLocal.x == 0) { modified = tree.GetAt(cellModified.x - 1, cellModified.y, cellModified.z); outChangedBricks.Enqueue(modified); } if (adjacentLocal.y == 0) { modified = tree.GetAt(cellModified.x, cellModified.y - 1, cellModified.z); outChangedBricks.Enqueue(modified); } if (adjacentLocal.z == 0) { modified = tree.GetAt(cellModified.x, cellModified.y, cellModified.z - 1); outChangedBricks.Enqueue(modified); } return(true); }
private void LateUpdate() { voxelSize = Mathf.Clamp(voxelSize, 4, 64); propogationSteps = Mathf.Clamp(propogationSteps, 0, voxelSize); fluxRes = Mathf.Clamp(fluxRes, 16, 2048); if (multiplyColor) { Shader.EnableKeyword("MULTIPLY_COLOR"); Shader.DisableKeyword("MULTIPLY_COLOR_OFF"); } else { Shader.DisableKeyword("MULTIPLY_COLOR"); Shader.EnableKeyword("MULTIPLY_COLOR_OFF"); } if (on) { Shader.EnableKeyword("ENABLE_BLEED"); Shader.DisableKeyword("DISABLE_BLEED"); if (pointSample) { Shader.EnableKeyword("VOXEL_POINT_SAMPLE"); Shader.DisableKeyword("VOXEL_TRILINEAR_SAMPLE"); } else { Shader.DisableKeyword("VOXEL_POINT_SAMPLE"); Shader.EnableKeyword("VOXEL_TRILINEAR_SAMPLE"); } } else { Shader.DisableKeyword("ENABLE_BLEED"); Shader.EnableKeyword("DISABLE_BLEED"); return; } if (camera.isOrthoGraphic) { Shader.EnableKeyword("ORTHOGRAPHIC"); Shader.DisableKeyword("PERSPECTIVE"); } else { Shader.DisableKeyword("ORTHOGRAPHIC"); Shader.EnableKeyword("PERSPECTIVE"); } var lpoints = RecalculateFrustrumPoints(camera); Shader.SetGlobalVector("_LightDir", transform.forward); Shader.SetGlobalFloat("_LPVDimensions", voxelSize); Shader.SetGlobalFloat("_LPVDimensionsSquared", voxelSize * voxelSize); Shader.SetGlobalVector("_LPV_AABBMin", volumeBounds.min); Shader.SetGlobalVector("_LPV_AABBMax", volumeBounds.max); Shader.SetGlobalVector("_LPV_Extents", volumeBounds.max - volumeBounds.min); Shader.SetGlobalTexture("_VoxelTex", _voxelTexture); VoxelMaterial.SetFloat("_LightCameraNear", camera.nearClipPlane); VoxelMaterial.SetFloat("_LightCameraFar", camera.farClipPlane); VoxelMaterial.SetFloat("_NormalOffset", normalOffset); VoxelMaterial.SetFloat("_FallOff", colorStrength * 3); VoxelMaterial.SetFloat("_BlendSpeed", Time.renderedFrameCount == 1 ? 1 : blendSpeed); VoxelMaterial.SetVector("_FrustrumPoints", new Vector4( lpoints[4].x, lpoints[5].x, lpoints[5].y, lpoints[6].y)); VoxelMaterial.SetMatrix("_WorldToView", camera.worldToCameraMatrix); VoxelMaterial.SetMatrix("_ViewToWorld", camera.cameraToWorldMatrix); camera.targetTexture = AlbedoTexture; Shader.EnableKeyword("DISABLE_BLEED"); Shader.DisableKeyword("ENABLED_BLEED"); camera.Render(); Shader.DisableKeyword("DISABLE_BLEED"); Shader.EnableKeyword("ENABLED_BLEED"); VoxelMaterial.SetTexture("_MainTex", AlbedoTexture); RenderTexture depthHalf = null; RenderTexture depthQuarter = null; RenderTexture albedoHalf = null; RenderTexture albedoQuarter = null; if (downSampleRSM) { VoxelMaterial.SetFloat("_VPLMergeLimit", vplMergeLimit); albedoHalf = GetTempPointTexture(AlbedoTexture.width / 2); depthHalf = GetTempPointTexture(AlbedoTexture.width / 2); albedoQuarter = GetTempPointTexture(AlbedoTexture.width / 4); depthQuarter = GetTempPointTexture(AlbedoTexture.width / 4); RenderMRT(new RenderBuffer [] { albedoHalf.colorBuffer, depthHalf.colorBuffer }, albedoHalf.depthBuffer); RenderMRT(new RenderBuffer [] { albedoQuarter.colorBuffer, depthQuarter.colorBuffer }, albedoQuarter.depthBuffer); VoxelMaterial.SetTexture("_MainTex", albedoQuarter); VoxelMaterial.SetTexture("_CameraDepthNormalsTextureManual", depthQuarter); Shader.EnableKeyword("DEPTH_TEXTURE_MANUAL"); Shader.DisableKeyword("DEPTH_TEXTURE_UNITY"); } else { Shader.DisableKeyword("DEPTH_TEXTURE_MANUAL"); Shader.EnableKeyword("DEPTH_TEXTURE_UNITY"); } Shader.EnableKeyword("SAMPLE_COLOR"); Shader.DisableKeyword("SAMPLE_NORMAL"); RenderTexture.active = VoxelTexture; GL.Clear(false, true, Color.black); RenderVolume(VoxelMaterial, 0, voxelSize); RenderTexture.active = null; var blurBuffer = RenderTexture.GetTemporary(voxelSize * voxelSize, voxelSize, 0); for (int k = 0; k < propogationSteps; k++) { Graphics.Blit(VoxelTexture, blurBuffer, VoxelMaterial, 1); VoxelTexture.DiscardContents(); Graphics.Blit(blurBuffer, VoxelTexture, VoxelMaterial, 2); blurBuffer.DiscardContents(); Graphics.Blit(VoxelTexture, blurBuffer, VoxelMaterial, 3); VoxelTexture.DiscardContents(); Graphics.Blit(blurBuffer, VoxelTexture); blurBuffer.DiscardContents(); } RenderTexture.ReleaseTemporary(blurBuffer); if (Application.isPlaying) { Shader.EnableKeyword("FRAME_BLEND"); Shader.DisableKeyword("FRAME_BLEND_DISABLED"); VoxelMaterial.SetTexture("_PrevTex", PrevTexture); var temp = RenderTexture.GetTemporary(voxelSize * voxelSize, voxelSize, 0); Graphics.Blit(VoxelTexture, temp, VoxelMaterial, 4); Graphics.Blit(temp, VoxelTexture); Graphics.Blit(temp, PrevTexture); RenderTexture.ReleaseTemporary(temp); } else { Shader.DisableKeyword("FRAME_BLEND"); Shader.EnableKeyword("FRAME_BLEND_DISABLED"); } if (downSampleRSM) { RenderTexture.ReleaseTemporary(depthHalf); RenderTexture.ReleaseTemporary(depthQuarter); RenderTexture.ReleaseTemporary(albedoHalf); RenderTexture.ReleaseTemporary(albedoQuarter); } }
public override int GetHashCode() { // ReSharper disable once NonReadonlyMemberInGetHashCode return(VoxelMaterial?.GetHashCode() ?? 0); }