Added stepness task
This commit is contained in:
parent
765955cd22
commit
c050fdfc5f
@ -3,7 +3,8 @@ using System.Collections.Generic;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using System.Linq; // used for Sum of array
|
using System.Linq; // used for Sum of array
|
||||||
|
|
||||||
public class ProceduralTextureScript : MonoBehaviour {
|
public class ProceduralTextureScript : MonoBehaviour
|
||||||
|
{
|
||||||
public float snowHeight;
|
public float snowHeight;
|
||||||
public float rockSlope;
|
public float rockSlope;
|
||||||
|
|
||||||
@ -13,21 +14,26 @@ public class ProceduralTextureScript : MonoBehaviour {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float transition(float start, float end,float value) {
|
float transition(float start, float end, float value)
|
||||||
if (start > end) {
|
{
|
||||||
|
if (start > end)
|
||||||
|
{
|
||||||
return 1 - transition(end, start, value);
|
return 1 - transition(end, start, value);
|
||||||
}
|
}
|
||||||
if (value < start) {
|
if (value < start)
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (value >= end) {
|
if (value >= end)
|
||||||
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
var scaledValue = (value - start) / (end - start);
|
var scaledValue = (value - start) / (end - start);
|
||||||
return scaledValue;
|
return scaledValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void runProcedrualTexturing() {
|
public void runProcedrualTexturing()
|
||||||
|
{
|
||||||
var terrain = gameObject.GetComponent<Terrain>();
|
var terrain = gameObject.GetComponent<Terrain>();
|
||||||
var layers = terrain.terrainData.alphamapLayers;
|
var layers = terrain.terrainData.alphamapLayers;
|
||||||
var height = terrain.terrainData.alphamapWidth;
|
var height = terrain.terrainData.alphamapWidth;
|
||||||
@ -38,35 +44,33 @@ public class ProceduralTextureScript : MonoBehaviour {
|
|||||||
Debug.Log(height);
|
Debug.Log(height);
|
||||||
Debug.Log(width);
|
Debug.Log(width);
|
||||||
|
|
||||||
Debug.Log(terrain.terrainData.GetInterpolatedHeight(0.5f,0.5f));
|
Debug.Log(terrain.terrainData.GetInterpolatedHeight(0.5f, 0.5f));
|
||||||
|
|
||||||
var newSplatMap = new float[width, height, layers];
|
var newSplatMap = new float[width, height, layers];
|
||||||
//for (int i=0; i<)
|
//for (int i=0; i<)
|
||||||
|
|
||||||
for (int i=0; i < width;i++) {
|
for (int i = 0; i < width; i++)
|
||||||
for (int j = 0; j < width; j++) {
|
{
|
||||||
|
for (int j = 0; j < width; j++)
|
||||||
|
{
|
||||||
float x = j / (float)height;
|
float x = j / (float)height;
|
||||||
float y = i / (float)width;
|
float y = i / (float)width;
|
||||||
var splatWeights = new float[layers];
|
var splatWeights = new float[layers];
|
||||||
var terrainHeight = terrain.terrainData.GetInterpolatedHeight(x,y);
|
var terrainSteepness = terrain.terrainData.GetSteepness(x, y);
|
||||||
|
for (int k = 0; k < layers; k++)
|
||||||
for (int k = 0; k < layers; k++) {
|
{
|
||||||
splatWeights[k] = Random.RandomRange(0.0f,1.0f);
|
splatWeights[k] = terrainSteepness;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
float sum = splatWeights.Sum();
|
float sum = splatWeights.Sum();
|
||||||
|
|
||||||
for (int k = 0; k < layers; k++) {
|
for (int k = 0; k < layers; k++)
|
||||||
newSplatMap[i,j,k]=splatWeights[k]/sum;
|
{
|
||||||
|
newSplatMap[i, j, k] = splatWeights[k] / sum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
terrain.terrainData.SetAlphamaps(0, 0, newSplatMap);
|
terrain.terrainData.SetAlphamaps(0, 0, newSplatMap);
|
||||||
|
|
||||||
var a = terrain.terrainData.treeInstances;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
|
Loading…
Reference in New Issue
Block a user