public ColorIntensity RayIntensity(SDScene scene, RayData data) { ColorIntensity color = new ColorIntensity(); float lightPass = LightPassValue(scene.ClosestDistance, data.Pos); if (lightPass == 0f) { return(color); } float diffuseDot = SunDirection.Dot(data.Normal); if (diffuseDot > 0f) { color += data.Mat.DiffuseIntensity * DiffuseIntensity * diffuseDot * lightPass; Vec3f reflectionDir = 2f * SunDirection.Dot(data.Normal) * data.Normal - SunDirection; Vec3f viewerDir = (data.RayOrigin - data.Pos).Normalized(); float specularDot = reflectionDir.Dot(viewerDir); if (specularDot > 0f) { color += SpecularIntensity * data.Mat.Specular * MathF.Pow(specularDot, data.Mat.Shininess) * lightPass; } } return(color); }
void MakeChunkNew(int vertices, Vector3 position, int x, int y) { double min, max; min = float.MaxValue; max = float.MinValue; float[,] perlinData = new float[vertices, vertices]; for (int i = 0; i < vertices; i++) { for (int j = 0; j < vertices; j++) { //float mjd = requestMajorFeature(vertices, i, j, x, y); //perlinData[i, j] = (float)perl.OctavePerlin(((i + ((vertices - 1) * x)) * 0.05d), (j + ((vertices - 1) * y)) * 0.05d, 0.1d, 5, 0.4d * mjd) + (5 * mjd); float mountainData = (float)mountains(i + ((vertices - 1) * x), j + ((vertices - 1) * y), 0.1); float desertData = (float)desert(i + ((vertices - 1) * x), j + ((vertices - 1) * y), 0.1); float lerpData = Mathf.Clamp01((8 * (float)perl.perlin((i + ((vertices - 1) * x)) * 0.002, (j + ((vertices - 1) * y)) * 0.002, 0.1)) - 4f); perlinData[i, j] = Mathf.Lerp(mountainData, desertData, lerpData); //perlinData[i, j] = Mathf.Clamp01((10 * (float)perl.perlin((i + ((vertices - 1) * x)) * 0.005, (j + ((vertices - 1) * y)) * 0.005, 0.1)) - 5f); //perlinData[i, j] = (float)mountains(i + ((vertices - 1) * x), j + ((vertices - 1) * y), 0.1); if (perlinData[i, j] < min) { min = perlinData[i, j]; } if (perlinData[i, j] > max) { max = perlinData[i, j]; } } } Debug.Log("Min " + min + " Max " + max); Mesh m = tp.Process(perlinData); GameObject newTile = new GameObject(); newTile.transform.position = position; SunDirection sd = newTile.AddComponent <SunDirection>(); sd.sunTransform = sunTransform; MeshFilter mf = newTile.AddComponent <MeshFilter>(); mf.mesh = m; MeshRenderer mr = newTile.AddComponent <MeshRenderer>(); mr.material = terrainMaterial; //Instantiate(water, new Vector3(position.x + 1000, 0, position.z + 1000), Quaternion.identity); }