File loading fixes: Added "skipBytes"-paramter to the importer, and moved the filepath into a separate variable.
This commit is contained in:
Родитель
e8f069980d
Коммит
6fe6f64227
|
@ -19,14 +19,16 @@ public class RawDatasetImporter
|
|||
private int dimY;
|
||||
private int dimZ;
|
||||
private DataContentFormat contentFormat;
|
||||
int skipBytes;
|
||||
|
||||
public RawDatasetImporter(string filePath, int dimX, int dimY, int dimZ, DataContentFormat contentFormat)
|
||||
public RawDatasetImporter(string filePath, int dimX, int dimY, int dimZ, DataContentFormat contentFormat, int skipBytes)
|
||||
{
|
||||
this.filePath = filePath;
|
||||
this.dimX = dimX;
|
||||
this.dimY = dimY;
|
||||
this.dimZ = dimZ;
|
||||
this.contentFormat = contentFormat;
|
||||
this.skipBytes = skipBytes;
|
||||
}
|
||||
|
||||
public VolumeDataset Import()
|
||||
|
@ -40,6 +42,8 @@ public class RawDatasetImporter
|
|||
FileStream fs = new FileStream(filePath, FileMode.Open);
|
||||
BinaryReader reader = new BinaryReader(fs);
|
||||
|
||||
reader.ReadBytes(skipBytes);
|
||||
|
||||
int uDimension = dimX * dimY * dimZ;
|
||||
dataset.texture = new Texture3D(dimX, dimY, dimZ, TextureFormat.RGBAFloat, false);
|
||||
dataset.data = new int[uDimension];
|
||||
|
|
|
@ -11,7 +11,8 @@ public class VolumeRenderer : MonoBehaviour
|
|||
|
||||
private void Start()
|
||||
{
|
||||
FileStream fs = new FileStream("DataFiles//manix.dat", FileMode.Open);
|
||||
string fileToLoad = "DataFiles//manix.dat";
|
||||
FileStream fs = new FileStream(fileToLoad, FileMode.Open);
|
||||
BinaryReader reader = new BinaryReader(fs);
|
||||
|
||||
ushort dimX = reader.ReadUInt16();
|
||||
|
@ -25,14 +26,21 @@ public class VolumeRenderer : MonoBehaviour
|
|||
|
||||
int uDimension = dimX * dimY * dimZ;
|
||||
|
||||
RawDatasetImporter importer = new RawDatasetImporter("DataFiles//manix.dat", dimX, dimY, dimZ, DataContentFormat.Int16);
|
||||
RawDatasetImporter importer = new RawDatasetImporter(fileToLoad, dimX, dimY, dimZ, DataContentFormat.Int16, 6);
|
||||
VolumeDataset dataset = importer.Import();
|
||||
volumeDataset = dataset;
|
||||
|
||||
Color[] cols = new Color[dataset.data.Length];
|
||||
for(int iData = 0; iData < dataset.data.Length; iData++)
|
||||
for(int iX = 0; iX < dataset.dimX; iX++)
|
||||
{
|
||||
cols[iData] = new Color((float)dataset.data[iData] / (float)dataset.maxDataValue, 0.0f, 0.0f);
|
||||
for (int iY = 0; iY < dataset.dimY; iY++)
|
||||
{
|
||||
for (int iZ = 0; iZ < dataset.dimZ; iZ++)
|
||||
{
|
||||
int iData = iX + iY * dimX + iZ * (dimX * dimY);
|
||||
cols[iData] = new Color((float)dataset.data[iData] / (float)dataset.maxDataValue, 0.0f, 0.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dataset.texture.SetPixels(cols);
|
||||
|
|
|
@ -82,7 +82,11 @@
|
|||
// Direct Volume Rendering
|
||||
fixed4 frag_dvr (v2f i)
|
||||
{
|
||||
#define NUM_STEPS 512//200
|
||||
#if TF2D_ON
|
||||
#define NUM_STEPS 512
|
||||
#else
|
||||
#define NUM_STEPS 1024
|
||||
#endif
|
||||
const float stepSize = 1.732f/*greatest distance in box*/ / NUM_STEPS;
|
||||
|
||||
float4 col = float4(i.vertexLocal.x, i.vertexLocal.y, i.vertexLocal.z, 1.0f);
|
||||
|
@ -106,7 +110,7 @@
|
|||
const float density = tex3Dlod(_DataTex, float4(currPos.x, currPos.y, currPos.z, 0.0f)).r;
|
||||
|
||||
#if TF2D_ON
|
||||
float3 gradient = getGradient(currPos, 0.005f);
|
||||
float3 gradient = getGradient(currPos, stepSize);
|
||||
float mag = length(gradient) / 1.75f;
|
||||
float4 src = tex2Dlod(_TFTex, float4(density, mag, 0.0f, 0.0f));
|
||||
#else
|
||||
|
@ -129,7 +133,7 @@
|
|||
// Maximum Intensity Projection mode
|
||||
fixed4 frag_mip(v2f i)
|
||||
{
|
||||
#define NUM_STEPS 1024//200
|
||||
#define NUM_STEPS 1024
|
||||
const float stepSize = 1.732f/*greatest distance in box*/ / NUM_STEPS;
|
||||
|
||||
float3 rayStartPos = i.vertexLocal + float3(0.5f, 0.5f, 0.5f);
|
||||
|
@ -160,7 +164,11 @@
|
|||
// TODO: Cast ray FROM the camera instead, since this is a waste of performance
|
||||
fixed4 frag_surf(v2f i)
|
||||
{
|
||||
#define NUM_STEPS 2048//200
|
||||
#if TF2D_ON
|
||||
#define NUM_STEPS 512
|
||||
#else
|
||||
#define NUM_STEPS 1024
|
||||
#endif
|
||||
const float stepSize = 1.732f/*greatest distance in box*/ / NUM_STEPS;
|
||||
|
||||
float3 rayStartPos = i.vertexLocal + float3(0.5f, 0.5f, 0.5f);
|
||||
|
@ -195,8 +203,8 @@
|
|||
lightReflection = lerp(0.0f, 1.5f, lightReflection);
|
||||
|
||||
// Maximum intensity projection
|
||||
float4 col = float4(lastDensity, 0.0f, 0.0f, lastDensity > 0.1f ? 1.0f : 0.0f);
|
||||
col = lightReflection * tex2Dlod(_TFTex, float4(lastDensity, 0.0f, 0.0f, 0.0f));
|
||||
|
||||
float4 col = lightReflection * tex2Dlod(_TFTex, float4(lastDensity, 0.0f, 0.0f, 0.0f));
|
||||
col.a = lastDensity > 0.1f ? 1.0f : 0.0f;
|
||||
|
||||
return col;
|
||||
|
|
Загрузка…
Ссылка в новой задаче