- NoiseTextureGenerator
This commit is contained in:
Matias 2019-02-15 09:13:59 +01:00
Родитель f5e38b6da1
Коммит 2ca6ce1fa3
10 изменённых файлов: 176 добавлений и 28 удалений

8
Assets/Importing.meta Normal file
Просмотреть файл

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a9c03434ec9e4124b83fc4630dc53023
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Просмотреть файл

@ -0,0 +1,81 @@
using System;
using System.IO;
using UnityEngine;
public enum DataContentFormat
{
Int8,
Uint8,
Int16,
Uint16,
Int32,
Uint32
}
public class RawDatasetImporter
{
string filePath;
private int dimX;
private int dimY;
private int dimZ;
private DataContentFormat contentFormat;
public RawDatasetImporter(string filePath, int dimX, int dimY, int dimZ, DataContentFormat contentFormat)
{
this.filePath = filePath;
this.dimX = dimX;
this.dimY = dimY;
this.dimZ = dimZ;
this.contentFormat = contentFormat;
}
public VolumeDataset Import()
{
VolumeDataset dataset = new VolumeDataset();
FileStream fs = new FileStream(filePath, FileMode.Open);
BinaryReader reader = new BinaryReader(fs);
int uDimension = dimX * dimY * dimZ;
dataset.texture = new Texture3D(dimX, dimY, dimZ, TextureFormat.RGBAFloat, false);
dataset.colours = new Color[uDimension];
float minVal = float.PositiveInfinity;
float maxVal = float.NegativeInfinity;
float val = 0.0f;
for (int i = 0; i < uDimension; i++)
{
switch(contentFormat)
{
case DataContentFormat.Int8:
val = (float)reader.ReadByte();
break;
case DataContentFormat.Int16:
val = (float)reader.ReadInt16();
break;
case DataContentFormat.Int32:
val = (float)reader.ReadInt32();
break;
case DataContentFormat.Uint8:
val = (float)reader.ReadByte();
break;
case DataContentFormat.Uint16:
val = (float)reader.ReadUInt16();
break;
case DataContentFormat.Uint32:
val = (float)reader.ReadUInt32();
break;
}
minVal = Mathf.Min(minVal, val);
maxVal = Mathf.Max(maxVal, val);
dataset.colours[i] = new Color(val, 0.0f, 0.0f);
}
Debug.Log("Loaded dataset in range: " + minVal + " - " + maxVal);
Debug.Log(minVal + " - " + maxVal);
dataset.texture.SetPixels(dataset.colours);
dataset.texture.Apply();
return dataset;
}
}

Просмотреть файл

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 45cd99ee9f504d44ca6d48b0d06a6423
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Просмотреть файл

@ -16,41 +16,21 @@ public class VolumeRenderer : MonoBehaviour
ushort dimY = reader.ReadUInt16();
ushort dimZ = reader.ReadUInt16();
reader.Close();
fs.Close();
Debug.Log(dimX + ", " + dimY + ", " + dimZ);
int uDimension = dimX * dimY * dimZ;
Texture3D tex = new Texture3D(dimX, dimY, dimZ, TextureFormat.RGBAFloat, false);
Color[] cols = new Color[uDimension];
float minVal = float.PositiveInfinity;
float maxVal = float.NegativeInfinity;
for(int i = 0; i < uDimension; i++)
{
float val = (float)reader.ReadInt16();
minVal = Mathf.Min(minVal, val);
maxVal = Mathf.Max(maxVal, val);
cols[i] = new Color(val, 0.0f, 0.0f);
}
Debug.Log(minVal + " - " + maxVal);
tex.SetPixels(cols);
tex.Apply();
RawDatasetImporter importer = new RawDatasetImporter("DataFiles//manix.dat", dimX, dimY, dimZ, DataContentFormat.Int16);
VolumeDataset dataset = importer.Import();
Texture3D tex = dataset.texture;
const int noiseDimX = 512;
const int noiseDimY = 512;
Texture2D noiseTexture = new Texture2D(noiseDimX, noiseDimY);
Color[] noiseCols = new Color[noiseDimX * noiseDimY];
for(int iY = 0; iY < noiseDimY; iY++)
{
for (int iX = 0; iX < noiseDimX; iX++)
{
float pixVal = Random.Range(0.0f, 1.0f);
noiseCols[iX + iY * noiseDimX] = new Color(pixVal, pixVal, pixVal);
}
}
noiseTexture.SetPixels(noiseCols);
noiseTexture.Apply();
Texture2D noiseTexture = NoiseTextureGenerator.GenerateNoiseTexture(noiseDimX, noiseDimY);
tf = new TransferFunction();
tf.AddControlPoint(new TFColourControlPoint(0.0f, new Color(0.11f, 0.14f, 0.13f, 1.0f)));

8
Assets/Utils.meta Normal file
Просмотреть файл

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 25442e9d1d762de439428ed034dc4c09
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Просмотреть файл

@ -0,0 +1,22 @@
using UnityEngine;
public class NoiseTextureGenerator
{
public static Texture2D GenerateNoiseTexture(int noiseDimX, int noiseDimY)
{
Texture2D noiseTexture = new Texture2D(noiseDimX, noiseDimY);
Color[] noiseCols = new Color[noiseDimX * noiseDimY];
for (int iY = 0; iY < noiseDimY; iY++)
{
for (int iX = 0; iX < noiseDimX; iX++)
{
float pixVal = Random.Range(0.0f, 1.0f);
noiseCols[iX + iY * noiseDimX] = new Color(pixVal, pixVal, pixVal);
}
}
noiseTexture.SetPixels(noiseCols);
noiseTexture.Apply();
return noiseTexture;
}
}

Просмотреть файл

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ed6362746a619f540963023e61710552
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

8
Assets/VolumeData.meta Normal file
Просмотреть файл

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 71839df0988a2de4cb18650e448bb973
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Просмотреть файл

@ -0,0 +1,8 @@
using System;
using UnityEngine;
public class VolumeDataset
{
public Color[] colours = null;
public Texture3D texture = null;
}

Просмотреть файл

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6c292ee2920c4d64989a78d4ed9abb7e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: