static VoxelState GetSHTriLinear(ProbeVolume v, Vector3 worldPosition, ref float[] shData) { int voxelIndex = v.Grid.GetVoxelIndex(worldPosition); if (voxelIndex < 0) { return(VoxelState.Empty); } VoxelState voxelState = GetVoxelState(v, voxelIndex); if (voxelState != VoxelState.Valid) { return(VoxelState.Empty); } float[] weights = v.Grid.GetVoxelTriLinearWeight(worldPosition, voxelIndex); //Blend 4 regions var lerp1 = GetLerp(weights[0], v.GetSHData(voxelIndex, 0), v.GetSHData(voxelIndex, 1)); var lerp2 = GetLerp(weights[0], v.GetSHData(voxelIndex, 4), v.GetSHData(voxelIndex, 5)); var leftBlend = GetLerp(weights[1], lerp1, lerp2); //Blend 4 regions var lerp3 = GetLerp(weights[0], v.GetSHData(voxelIndex, 2), v.GetSHData(voxelIndex, 3)); var lerp4 = GetLerp(weights[0], v.GetSHData(voxelIndex, 6), v.GetSHData(voxelIndex, 7)); var rightBlend = GetLerp(weights[1], lerp3, lerp4); //Blend the 2 outputs into a final output var finalBlend = GetLerp(weights[2], leftBlend, rightBlend); shData = v.GetSHData(voxelIndex, 0); return(VoxelState.Valid); }
static VoxelState GetSHNearest(ProbeVolume volume, Vector3 worldPosition, ref float[] shData) { int voxelIndex = volume.Grid.GetVoxelIndex(worldPosition); if (voxelIndex < 0) { return(VoxelState.Empty); } VoxelState voxelState = GetVoxelState(volume, voxelIndex); if (voxelState != VoxelState.Valid) { return(voxelState); } int nearestIndex = volume.Grid.GetNearestLocalProbeIndex(worldPosition, voxelIndex); if (nearestIndex >= 0) { uint dataIndex = volume.IndexBuffer.GetSHDataIndex(nearestIndex, 0); bool isValid = volume.IndexBuffer.IsIndexValueValid(dataIndex); if (isValid) { shData = volume.DataBuffer.GetSHData((int)dataIndex); return(VoxelState.Valid); } } return(VoxelState.Empty); }
static List <Vertex> InitProbes(ProbeVolume volume) { List <Vertex> probes = new List <Vertex>(); var probeCount = volume.Grid.GetProbeCount(); for (uint x = 0; x < probeCount.X; x++) { for (uint y = 0; y < probeCount.Y; y++) { for (uint z = 0; z < probeCount.Z; z++) { int voxelIndex = volume.Grid.GetVoxelIndex(x, y, z); Vector3 positon = volume.Grid.GetVoxelPosition(x, y, z); for (int j = 0; j < 1; j++) { uint dataIndex = volume.IndexBuffer.GetSHDataIndex(voxelIndex, j); if (!volume.IndexBuffer.IsIndexValueValid(dataIndex)) { continue; } float[] data = volume.DataBuffer.GetSHData((int)dataIndex); var probe = new Vertex(); probe.Position = positon; probe.Coef0 = new Vector4(data[0], data[1], data[2], data[3]); probe.Coef1 = new Vector4(data[4], data[5], data[6], data[7]); probe.Coef2 = new Vector4(data[8], data[9], data[10], data[11]); probe.Coef3 = new Vector4(data[12], data[13], data[14], data[15]); probe.Coef4 = new Vector4(data[16], data[17], data[18], data[19]); probe.Coef5 = new Vector4(data[20], data[21], data[22], data[23]); probe.Coef6 = new Vector4(data[24], data[25], data[26], 0); probes.Add(probe); } } } } return(probes); }
static List <ProbeInstance> InitProbes(ProbeVolume volume) { List <ProbeInstance> probes = new List <ProbeInstance>(); var probeCount = volume.Grid.GetProbeCount(); for (uint x = 0; x < probeCount.X; x++) { for (uint y = 0; y < probeCount.Y; y++) { for (uint z = 0; z < probeCount.Z; z++) { int voxelIndex = volume.Grid.GetVoxelIndex(x, y, z); Vector3 positon = volume.Grid.GetVoxelPosition(x, y, z); for (int j = 0; j < 1; j++) { uint dataIndex = volume.IndexBuffer.GetSHDataIndex(voxelIndex, j); if (!volume.IndexBuffer.IsIndexValueValid(dataIndex)) { continue; } float[] data = volume.DataBuffer.GetSHData((int)dataIndex); var probe = new ProbeInstance(); probe.SHData = data; probe.Position = positon; probe.Size = 30; probe.BB = new BoundingBox() { Max = new Vector3(positon.X + 15, positon.Y + 15, positon.Z + 15), Min = new Vector3(positon.X - 15, positon.Y - 15, positon.Z - 15), }; probes.Add(probe); } } } } return(probes); }
static VoxelState GetVoxelState(ProbeVolume v, int voxelIndex) { const int numDivide = 8; for (int i = 0; i < numDivide; i++) { uint dataIndex = v.IndexBuffer.GetSHDataIndex(voxelIndex, i); bool isEmpty = v.IndexBuffer.IsIndexValueEmpty(dataIndex); if (isEmpty) { Console.WriteLine($"isEmpty at {i} dataIndex {dataIndex}"); } if (isEmpty) { return(VoxelState.Empty); } bool isInvisible = v.IndexBuffer.IsIndexValueInvisible(dataIndex); if (isInvisible) { Console.WriteLine($"isInvisible at {i} dataIndex {dataIndex}"); } if (isInvisible) { break; } //Data passed through 8 times with valid values if (i == numDivide - 1) { return(VoxelState.Valid); } } return(VoxelState.Invisible); }
public void LoadValues(AampFile aamp) { Params = new ProbeParams(); foreach (var val in aamp.RootNode.paramObjects) { if (val.HashString == "root_grid") { RootGrid = LoadGridData(val.paramEntries); } if (val.HashString == "param_obj") { foreach (var param in val.paramEntries) { if (param.HashString == "version") { Params.Version = (uint)param.Value; } if (param.HashString == "dir_light_indirect") { Params.IndirectDirectionLight = (float)param.Value; } if (param.HashString == "point_light_indirect") { Params.IndirectPointLight = (float)param.Value; } if (param.HashString == "spot_light_indirect") { Params.IndirectSpotLight = (float)param.Value; } if (param.HashString == "emission_scale") { Params.EmissionScale = (float)param.Value; } } } } foreach (var val in aamp.RootNode.childParams) { ProbeVolume box = new ProbeVolume(); Boxes.Add(box); foreach (var param in val.paramObjects) { if (param.HashString == "grid") { box.Grid = LoadGridData(param.paramEntries); } if (param.HashString == "param_obj") { foreach (var p in param.paramEntries) { if (p.HashString == "index") { box.Index = (uint)p.Value; } if (p.HashString == "type") { box.Type = (uint)p.Value; } } } if (param.HashString == "sh_data_buffer") { box.DataBuffer = LoadDataBuffer(param.paramEntries); } if (param.HashString == "sh_index_buffer") { box.IndexBuffer = LoadIndexBuffer(param.paramEntries); } } } }