/// <summary> /// precompute atmosphere, normal and vertex data /// </summary> public void Precompute() { K = Screen.width / (2f * Mathf.Tan((65f / 2f) * Mathf.Deg2Rad)); m_perlin = new ImprovedPerlinNoise(0); m_perlin.LoadResourcesFor3DNoise(); Texture2D perm = m_perlin.GetPermutationTable2D(); Texture2D grad = m_perlin.GetGradient3D(); VertexComputeShader.SetTexture(0, "_PermTable2D", perm); VertexComputeShader.SetTexture(0, "_Gradient3D", grad); mat.SetTexture(PermTable2D, perm); mat.SetTexture(Gradient3D, grad); VertexComputeBuffer = new ComputeBuffer((ChunkSegments + 2) * (ChunkSegments + 2), 12); NormalComputeBuffer = new ComputeBuffer((ChunkSegments + 2) * (ChunkSegments + 2), 12); PlanetMapCreatorBuffer = new ComputeBuffer(1024 * 1024, 32); VertexComputeShader.SetBuffer(0, "vertexBuffer", VertexComputeBuffer); VertexComputeShader.SetBuffer(0, "normalBuffer", NormalComputeBuffer); PlanetMapGeneratorShader.SetBuffer(0, "Output", PlanetMapCreatorBuffer); PlanetMapGeneratorShader.SetTexture(0, "_PermTable2D", perm); PlanetMapGeneratorShader.SetTexture(0, "_Gradient3D", grad); UpdateNoise(); }
public override bool Calculate() { Debug.Log("calc"); if (!allInputsReady()) { //Debug.LogError(" input no ready"); return(false); } if (Outputs == null || Outputs.Count == 0) { Debug.LogError(" null Outputs in " + this); return(false); } if (m_Wrapping) { m_Value6.Floor(); // = (FloatRemap)Mathf.Floor(m_Value6); m_Value5.Floor(); // = (FloatRemap)Mathf.Floor(m_Value5); } if (m_Param == null) { m_Param = new TextureParam(m_TexWidth, m_TexHeight); } if (m_perlin == null || m_perlin.GetPermutationTable1D() == null || m_perlin.GetGradient2D() == null) { m_perlin = new ImprovedPerlinNoise(m_seed); m_perlin.LoadResourcesFor2DNoise(); } if (m_Param != null) { switch (m_OpType) { case TexOP.PerlinBm: General(m_Value1, m_Value2, m_Value3, m_Param, ShaderOp.PerlinBm); break; case TexOP.PerlinTurb: General(m_Value1, m_Value2, m_Value3, m_Param, ShaderOp.PerlinTurb); break; case TexOP.PerlinRidge: General(m_Value1, m_Value2, m_Value3, m_Param, ShaderOp.PerlinRidge); break; case TexOP.VeroniNoise: General(m_Value1, m_Value2, m_Value3, m_Param, ShaderOp.VeroniNoise); break; case TexOP.Simplex3D: General(m_Value1, m_Value2, m_Value3, m_Param, ShaderOp.Simplex3D); break; } } //m_Cached = m_Param.GetHWSourceTexture(); CreateCachedTextureIcon(); Outputs[0].SetValue <TextureParam> (m_Param); CheckDiskIcon(name, m_Param); return(true); }
void Start() { m_perlin = new ImprovedPerlinNoise(m_seed); m_perlin.LoadResourcesFor2DNoise(); GetComponent <Renderer>().material.SetTexture("_PermTable1D", m_perlin.GetPermutationTable1D()); GetComponent <Renderer>().material.SetTexture("_Gradient2D", m_perlin.GetGradient2D()); }
public void StartATL() { perlin = new ImprovedPerlinNoise(seed); perlin.LoadResourcesFor4DNoise(); GetComponent <Renderer>().material.SetTexture("_PermTable1D", perlin.GetPermutationTable1D()); GetComponent <Renderer>().material.SetTexture("_PermTable2D", perlin.GetPermutationTable2D()); GetComponent <Renderer>().material.SetTexture("_Gradient4D", perlin.GetGradient4D()); }
public void Init() { DontDestroyOnLoad(this); noise = new ImprovedPerlinNoise(seed); noise.LoadResourcesFor3DNoise(); renderer.material.SetTexture("_PermTable2D", noise.GetPermutationTable2D()); renderer.material.SetTexture("_Gradient3D", noise.GetGradient3D()); currentTime = 0; renderer.material.SetFloat("_Evolution", currentTime); }
// Use this for initialization void Start() { twoPowDimensionWidth = (int)Mathf.Pow(2, powerOfTwoSize); m_perlin = new ImprovedPerlinNoise(m_seed); m_perlin.LoadResourcesFor2DNoise(); compShade.SetTexture(compShade.FindKernel("CSProcGen"), "_Gradient2D", m_perlin.GetGradient2D()); compShade.SetTexture(compShade.FindKernel("CSProcGen"), "_PermTable1D", m_perlin.GetPermutationTable1D()); buffer[READ] = new ComputeBuffer(twoPowDimensionWidth * twoPowDimensionWidth, sizeof(float), ComputeBufferType.Default); buffer[WRITE] = new ComputeBuffer(twoPowDimensionWidth * twoPowDimensionWidth, sizeof(float), ComputeBufferType.Default); }
void Start() { //There are 8 threads run per group so N must be divisible by 8. if (N % 8 != 0) { throw new System.ArgumentException("N must be divisible be 8"); } //Holds the voxel values, generated from perlin noise. m_noiseBuffer = new ComputeBuffer(N * N * N, sizeof(float)); //Holds the normals of the voxels. m_normalsBuffer = new ComputeBuffer(N * N * N, sizeof(float) * 3); //Holds the verts generated by the marching cubes. m_meshBuffer = new ComputeBuffer(SIZE, sizeof(float) * 7); //These two buffers are just some settings needed by the marching cubes. m_cubeEdgeFlags = new ComputeBuffer(256, sizeof(int)); m_cubeEdgeFlags.SetData(cubeEdgeFlags); m_triangleConnectionTable = new ComputeBuffer(256 * 16, sizeof(int)); m_triangleConnectionTable.SetData(triangleConnectionTable); //Make the perlin noise, make sure to load resources to match shader used. perlin = new ImprovedPerlinNoise(m_seed); perlin.LoadResourcesFor4DNoise(); //Constract a mesh. var vcount = N * N * 3 * 5; var vertices = new Vector3[vcount]; var uv = new Vector2[vcount]; for (var i = 0; i < vcount; i++) { uv[i] = new Vector2(i, 0); } var indices = new int[vcount]; for (var i = 0; i < vcount; i++) { indices[i] = i; } m_mesh = new Mesh(); m_mesh.vertices = vertices; m_mesh.uv = uv; m_mesh.SetIndices(indices, MeshTopology.Triangles, 0); m_mesh.bounds = new Bounds(Vector3.zero, Vector3.one * 1000); }
private Node CreateNode(Box3D bounds, int level, EntityManager entityManager) { var mesh = MeshCreator.CreateXZGrid(10, 10); var staticMesh = new StaticMesh { Color = new Vector4(0f, 0f, 1f, 1f), ModelMatrix = Matrix4.Identity, }; var size = bounds.Max - bounds.Min; var mesh3V3N = mesh.Transformed(Matrix4.CreateScale((float)size.X, 1, (float)size.Z) * Matrix4.CreateTranslation((Vector3)bounds.Center)); var improvedPerlinNoise = new ImprovedPerlinNoise(4711); for (int i = 0; i < mesh3V3N.Vertices.Length; i++) { var vertex = mesh3V3N.Vertices[i]; var height = improvedPerlinNoise.Noise(vertex.Position.X, vertex.Position.Z) * 0.2; mesh3V3N.Vertices[i] = new Vertex3V3N { Normal = new Vector3(0, 1, 0), Position = new Vector3(vertex.Position.X, (float)height, vertex.Position.Z) }; } staticMesh.Update(mesh3V3N); var entity = new Entity(Guid.NewGuid().ToString()); entityManager.Add(entity); entityManager.AddComponentToEntity(entity, staticMesh); if (level == 0) { return(new Node(bounds, new Node[] { }, entity, 1)); } var min = bounds.Min; var max = bounds.Max; var center = bounds.Center; return(new Node(bounds, new[] { CreateNode(new Box3D(bounds.Min, center), level - 1, entityManager), CreateNode(new Box3D(new Vector3d(center.X, 0, min.Z), new Vector3d(max.X, 0, center.Z)), level - 1, entityManager), CreateNode(new Box3D(new Vector3d(min.X, 0, center.Z), new Vector3d(center.X, 0, max.Z)), level - 1, entityManager), CreateNode(new Box3D(center, max), level - 1, entityManager) }, entity, Math.Pow(2, level))); }
void Start () { //There are 8 threads run per group so N must be divisible by 8. if(N%8 != 0) throw new System.ArgumentException("N must be divisible be 8"); //Holds the voxel values, generated from perlin noise. m_noiseBuffer = new ComputeBuffer(N * N * N, sizeof(float)); //Holds the normals of the voxels. m_normalsBuffer = new ComputeBuffer(N * N * N, sizeof(float)*3); //Holds the verts generated by the marching cubes. m_meshBuffer = new ComputeBuffer(SIZE, sizeof(float)*7); //These two buffers are just some settings needed by the marching cubes. m_cubeEdgeFlags = new ComputeBuffer(256, sizeof(int)); m_cubeEdgeFlags.SetData(cubeEdgeFlags); m_triangleConnectionTable = new ComputeBuffer(256 * 16, sizeof(int)); m_triangleConnectionTable.SetData(triangleConnectionTable); //Make the perlin noise, make sure to load resources to match shader used. perlin = new ImprovedPerlinNoise(m_seed); perlin.LoadResourcesFor4DNoise(); //Constract a mesh. var vcount = N * N * 3 * 5; var vertices = new Vector3[vcount]; var uv = new Vector2[vcount]; for (var i = 0; i < vcount; i++) uv[i] = new Vector2(i, 0); var indices = new int[vcount]; for (var i = 0; i < vcount; i++) indices[i] = i; m_mesh = new Mesh(); m_mesh.vertices = vertices; m_mesh.uv = uv; m_mesh.SetIndices(indices, MeshTopology.Triangles, 0); m_mesh.bounds = new Bounds(Vector3.zero, Vector3.one * 1000); }
protected override void Start() { base.Start(); if (TerrainNode == null) { TerrainNode = transform.parent.GetComponent <TerrainNode>(); } if (TerrainNode.Body == null) { TerrainNode.Body = transform.parent.GetComponentInParent <CelestialBody>(); } var tileSize = GetTileSize(0); if ((tileSize - GetBorder() * 2 - 1) % (TerrainNode.Body.GridResolution - 1) != 0) { throw new InvalidParameterException("Tile size - border * 2 - 1 must be divisible by grid mesh resolution - 1" + string.Format(": {0}-{1}", tileSize, GetBorder())); } var storage = Cache.GetStorage(0) as GPUTileStorage; if (storage == null) { throw new InvalidStorageException("Storage must be a GPUTileStorage"); } if (storage.FilterMode != FilterMode.Point) { throw new InvalidParameterException("GPUTileStorage filter must be point. There will be seams in the terrain otherwise"); } uniforms = new Uniforms(); Noise = new ImprovedPerlinNoise(UpsampleSettings.Seed); Noise.LoadResourcesFor3DNoise(); UpSampleMaterial.SetTexture("_PermTable2D", Noise.GetPermutationTable2D()); UpSampleMaterial.SetTexture("_Gradient3D", Noise.GetGradient3D()); }
//public void PerlinNoise2D() //{ // int terrainWidth = TerrainData.heightmapResolution; // int terrainHeight = TerrainData.heightmapResolution; // float[,] heightMap = TerrainData.GetHeights(0, 0, terrainWidth, terrainHeight); // for (int x = 0; x < terrainHeight; x++) // { // for (int y = 0; y < terrainWidth; y++) // { // float inputX = (x + PerlinOffsetX) * PerlinScaleX; // float inputY = (y + PerlinOffsetY) * PerlinScaleY; // heightMap[x, y] = Utils.FBM(inputX, inputY, PerlinOctaves, PerlinPersistance) * PerlinHeightScale; // } // } // SaveToFile(heightMap, "./PerlinNoise.csv"); // TerrainData.SetHeights(0, 0, heightMap); //} public void ImprovetPerlinNoise() { int terrainWidth = TerrainData.heightmapResolution; int terrainHeight = TerrainData.heightmapResolution; var perlin = new ImprovedPerlinNoise(); float[,] heightMap = TerrainData.GetHeights(0, 0, terrainWidth, terrainHeight); for (int x = 0; x < terrainHeight; x++) { for (int y = 0; y < terrainWidth; y++) { double inputX = (x + PerlinOffsetX) * PerlinScaleX; double inputY = (y + PerlinOffsetY) * PerlinScaleY; heightMap[x, y] += (float)perlin.Noise(inputX, inputY, 0) * PerlinHeightScale; } } //SaveToFile(heightMap, "./OwnPerlinNoise.csv"); TerrainData.SetHeights(0, 0, heightMap); }
public ScaledNoiseGenerator() { _largeScaleNoise = new ImprovedPerlinNoise(4711); _noise = new NoiseFactory.RidgedMultiFractal().Create(new NoiseFactory.NoiseParameters()); }
void Start() { m_waterDamping = Mathf.Clamp01(m_waterDamping); m_regolithDamping = Mathf.Clamp01(m_regolithDamping); float u = 1.0f / (float)TEX_SIZE; m_rectLeft = new Rect(0.0f, 0.0f, u, 1.0f); m_rectRight = new Rect(1.0f - u, 0.0f, u, 1.0f); m_rectBottom = new Rect(0.0f, 0.0f, 1.0f, u); m_rectTop = new Rect(0.0f, 1.0f - u, 1.0f, u); m_terrainField = new RenderTexture[2]; m_waterOutFlow = new RenderTexture[2]; m_waterVelocity = new RenderTexture[2]; m_advectSediment = new RenderTexture[2]; m_waterField = new RenderTexture[2]; m_sedimentField = new RenderTexture[2]; m_regolithField = new RenderTexture[2]; m_regolithOutFlow = new RenderTexture[2]; m_lavaField = new RenderTexture[2]; m_lavaVelocity = new RenderTexture[2]; m_lavaOutFlow = new RenderTexture[2]; m_terrainField[0] = new RenderTexture(TEX_SIZE, TEX_SIZE, 0, RenderTextureFormat.ARGBFloat); m_terrainField[0].enableRandomWrite = true; m_terrainField[0].wrapMode = TextureWrapMode.Clamp; m_terrainField[0].filterMode = FilterMode.Point; m_terrainField[1] = new RenderTexture(TEX_SIZE, TEX_SIZE, 0, RenderTextureFormat.ARGBFloat); m_terrainField[1].wrapMode = TextureWrapMode.Clamp; m_terrainField[1].filterMode = FilterMode.Point; m_waterOutFlow[0] = new RenderTexture(TEX_SIZE, TEX_SIZE, 0, RenderTextureFormat.ARGBHalf); m_waterOutFlow[0].wrapMode = TextureWrapMode.Clamp; m_waterOutFlow[0].filterMode = FilterMode.Point; m_waterOutFlow[1] = new RenderTexture(TEX_SIZE, TEX_SIZE, 0, RenderTextureFormat.ARGBHalf); m_waterOutFlow[1].wrapMode = TextureWrapMode.Clamp; m_waterOutFlow[1].filterMode = FilterMode.Point; m_lavaOutFlow[0] = new RenderTexture(TEX_SIZE, TEX_SIZE, 0, RenderTextureFormat.ARGBHalf); m_lavaOutFlow[0].wrapMode = TextureWrapMode.Clamp; m_lavaOutFlow[0].filterMode = FilterMode.Point; m_lavaOutFlow[1] = new RenderTexture(TEX_SIZE, TEX_SIZE, 0, RenderTextureFormat.ARGBHalf); m_lavaOutFlow[1].wrapMode = TextureWrapMode.Clamp; m_lavaOutFlow[1].filterMode = FilterMode.Point; m_waterVelocity[0] = new RenderTexture(TEX_SIZE, TEX_SIZE, 0, RenderTextureFormat.RGHalf); m_waterVelocity[0].wrapMode = TextureWrapMode.Clamp; m_waterVelocity[0].filterMode = FilterMode.Bilinear; m_waterVelocity[1] = new RenderTexture(TEX_SIZE, TEX_SIZE, 0, RenderTextureFormat.RGHalf); m_waterVelocity[1].wrapMode = TextureWrapMode.Clamp; m_waterVelocity[1].filterMode = FilterMode.Bilinear; m_lavaVelocity[0] = new RenderTexture(TEX_SIZE, TEX_SIZE, 0, RenderTextureFormat.RGHalf); m_lavaVelocity[0].wrapMode = TextureWrapMode.Clamp; m_lavaVelocity[0].filterMode = FilterMode.Bilinear; m_lavaVelocity[1] = new RenderTexture(TEX_SIZE, TEX_SIZE, 0, RenderTextureFormat.RGHalf); m_lavaVelocity[1].wrapMode = TextureWrapMode.Clamp; m_lavaVelocity[1].filterMode = FilterMode.Bilinear; m_waterField[0] = new RenderTexture(TEX_SIZE, TEX_SIZE, 0, RenderTextureFormat.RFloat); m_waterField[0].wrapMode = TextureWrapMode.Clamp; m_waterField[0].filterMode = FilterMode.Point; m_waterField[1] = new RenderTexture(TEX_SIZE, TEX_SIZE, 0, RenderTextureFormat.RFloat); m_waterField[1].wrapMode = TextureWrapMode.Clamp; m_waterField[1].filterMode = FilterMode.Point; m_lavaField[0] = new RenderTexture(TEX_SIZE, TEX_SIZE, 0, RenderTextureFormat.RFloat); m_lavaField[0].wrapMode = TextureWrapMode.Clamp; m_lavaField[0].filterMode = FilterMode.Point; m_lavaField[1] = new RenderTexture(TEX_SIZE, TEX_SIZE, 0, RenderTextureFormat.RFloat); m_lavaField[1].wrapMode = TextureWrapMode.Clamp; m_lavaField[1].filterMode = FilterMode.Point; m_regolithField[0] = new RenderTexture(TEX_SIZE, TEX_SIZE, 0, RenderTextureFormat.RFloat); m_regolithField[0].wrapMode = TextureWrapMode.Clamp; m_regolithField[0].filterMode = FilterMode.Point; m_regolithField[1] = new RenderTexture(TEX_SIZE, TEX_SIZE, 0, RenderTextureFormat.RFloat); m_regolithField[1].wrapMode = TextureWrapMode.Clamp; m_regolithField[1].filterMode = FilterMode.Point; m_regolithOutFlow[0] = new RenderTexture(TEX_SIZE, TEX_SIZE, 0, RenderTextureFormat.ARGBHalf); m_regolithOutFlow[0].wrapMode = TextureWrapMode.Clamp; m_regolithOutFlow[0].filterMode = FilterMode.Point; m_regolithOutFlow[1] = new RenderTexture(TEX_SIZE, TEX_SIZE, 0, RenderTextureFormat.ARGBHalf); m_regolithOutFlow[1].wrapMode = TextureWrapMode.Clamp; m_regolithOutFlow[1].filterMode = FilterMode.Point; m_sedimentField[0] = new RenderTexture(TEX_SIZE, TEX_SIZE, 0, RenderTextureFormat.RHalf); m_sedimentField[0].wrapMode = TextureWrapMode.Clamp; m_sedimentField[0].filterMode = FilterMode.Bilinear; m_sedimentField[1] = new RenderTexture(TEX_SIZE, TEX_SIZE, 0, RenderTextureFormat.RHalf); m_sedimentField[1].wrapMode = TextureWrapMode.Clamp; m_sedimentField[1].filterMode = FilterMode.Bilinear; m_advectSediment[0] = new RenderTexture(TEX_SIZE, TEX_SIZE, 0, RenderTextureFormat.RHalf); m_advectSediment[0].wrapMode = TextureWrapMode.Clamp; m_advectSediment[0].filterMode = FilterMode.Bilinear; m_advectSediment[1] = new RenderTexture(TEX_SIZE, TEX_SIZE, 0, RenderTextureFormat.RHalf); m_advectSediment[1].wrapMode = TextureWrapMode.Clamp; m_advectSediment[1].filterMode = FilterMode.Bilinear; m_tiltAngle = new RenderTexture(TEX_SIZE, TEX_SIZE, 0, RenderTextureFormat.RHalf); m_tiltAngle.wrapMode = TextureWrapMode.Clamp; m_tiltAngle.filterMode = FilterMode.Point; m_slippageHeight = new RenderTexture(TEX_SIZE, TEX_SIZE, 0, RenderTextureFormat.RHalf); m_slippageHeight.wrapMode = TextureWrapMode.Clamp; m_slippageHeight.filterMode = FilterMode.Point; m_slippageOutflow = new RenderTexture(TEX_SIZE, TEX_SIZE, 0, RenderTextureFormat.ARGBHalf); m_slippageOutflow.wrapMode = TextureWrapMode.Clamp; m_slippageOutflow.filterMode = FilterMode.Point; m_perlin = new ImprovedPerlinNoise(m_seed); m_perlin.LoadResourcesFor2DNoise(); MakeGrids(); }
public void Init() { DontDestroyOnLoad (this); noise = new ImprovedPerlinNoise (seed); noise.LoadResourcesFor3DNoise (); renderer.material.SetTexture ("_PermTable2D", noise.GetPermutationTable2D ()); renderer.material.SetTexture ("_Gradient3D", noise.GetGradient3D ()); currentTime = 0; renderer.material.SetFloat ("_Evolution", currentTime); }