public void BitField32_Get_Set() { var test = new BitField32(); uint bits; bits = test.GetBits(0, 32); Assert.AreEqual(0x0, bits); test.SetBits(0, true); bits = test.GetBits(0, 32); Assert.AreEqual(0x1, bits); test.SetBits(0, true, 32); bits = test.GetBits(0, 32); Assert.AreEqual(0xffffffff, bits); Assert.IsTrue(test.TestAll(0, 32)); test.SetBits(0, false, 32); bits = test.GetBits(0, 32); Assert.AreEqual(0x0, bits); test.SetBits(15, true, 7); Assert.IsTrue(test.TestAll(15, 7)); test.SetBits(3, true, 3); Assert.IsTrue(test.TestAll(3, 3)); bits = test.GetBits(0, 32); Assert.AreEqual(0x3f8038, bits); bits = test.GetBits(0, 15); Assert.AreEqual(0x38, bits); Assert.IsFalse(test.TestNone(0, 32)); Assert.IsFalse(test.TestAll(0, 32)); Assert.IsTrue(test.TestAny(0, 32)); }
public void BitField32_Throws() { var test = new BitField32(); for (byte i = 0; i < 32; ++i) { Assert.DoesNotThrow(() => { test.GetBits(i, (byte)(32 - i)); }); } Assert.Throws <ArgumentException>(() => { test.GetBits(0, 33); }); Assert.Throws <ArgumentException>(() => { test.GetBits(1, 32); }); }
void OnEnable() { #if (UNITY_5_0) title = "UV Inspector"; #else titleContent = new GUIContent("UV Inspector"); #endif this.minSize = new Vector2(350, 400); previewUVSet = (UVSet)EditorPrefs.GetInt("nTools.UVInspector.previewUVSet", (int)previewUVSet); subMeshToggleField = EditorPrefs.GetInt("nTools.UVInspector.subMeshToggleField", subMeshToggleField.bitfield); showVertexColors = EditorPrefs.GetBool("nTools.UVInspector.showVertexColors", showVertexColors); showGrid = EditorPrefs.GetBool("nTools.UVInspector.showGrid", showGrid); showSubmeshesByOne = EditorPrefs.GetBool("nTools.UVInspector.showSubmeshesByOne", showSubmeshesByOne); tilePreviewTexture = EditorPrefs.GetBool("nTools.UVInspector.tilePreviewTexture", tilePreviewTexture); previewTextureSource = (PreviewTextureSource)EditorPrefs.GetInt("nTools.UVInspector.previewTextureSource", (int)previewTextureSource); customPreviewTexture = (Texture2D)AssetDatabase.LoadAssetAtPath(EditorPrefs.GetString("nTools.UVInspector.customPreviewTexture", ""), typeof(Texture2D)); previewTextureTintColor = IntToColor(EditorPrefs.GetInt("nTools.UVInspector.previewTextureTintColor", ColorToInt(previewTextureTintColor))); preferredTextureProperty = EditorPrefs.GetString("nTools.UVInspector.preferredTextureProperty", preferredTextureProperty); previewTextureChannels = (ColorChannels)EditorPrefs.GetInt("nTools.UVInspector.previewTextureChannels", (int)previewTextureChannels); settingsFoldout = EditorPrefs.GetBool("nTools.UVInspector.settingsFoldout", settingsFoldout); previewFoldout = EditorPrefs.GetBool("nTools.UVInspector.previewFoldout", previewFoldout); if (!LoadMaterials()) { Debug.LogWarning("UV Inspector Error: shaders not found. Reimport asset."); Close(); return; } #if NO_ON_SELECTION_CHANGED if (EditorApplication.update != OnEditorUpdate) { EditorApplication.update += OnEditorUpdate; } #else if (Selection.selectionChanged != OnSelectionChanged) { Selection.selectionChanged += OnSelectionChanged; } #endif LoadMeshes(); }
public void Execute(int jobId) { int2 tileId = new int2(jobId % m_TileCount.x, jobId / m_TileCount.x); int2 bigTileId = tileId / m_LastPhaseToCurTileScale; int2 bigTileCount = (m_TileCount + m_LastPhaseToCurTileScale - new int2(1, 1)) / m_LastPhaseToCurTileScale; int bigTileBufferID = bigTileId.x + bigTileId.y * bigTileCount.x; int lightCount = 0; m_ResTileLightIndicesMask[jobId].Clear(); BitField32 lightIndicies = new BitField32(); for (int lightIndex = 0; lightIndex < m_LightPos.Length; lightIndex++) { if (m_SrcTileLightIndicesMask[bigTileBufferID].IsSet(lightIndex)) { float3 lightPosition = m_LightPos[lightIndex]; var range = m_LightAffectingRange[lightIndex]; var tileIsLit = CullingUtls.PlaneSphereInclusion(m_ClusterInfo.ClusterXPlaneNormal[tileId.x], m_ClusterInfo.ClusterXPlanePoints[tileId.x], lightPosition, range) && // plane left CullingUtls.PlaneSphereInclusion(-m_ClusterInfo.ClusterXPlaneNormal[tileId.x + 1], m_ClusterInfo.ClusterXPlanePoints[tileId.x + 1], lightPosition, range) &&// plane right CullingUtls.PlaneSphereInclusion(m_ClusterInfo.ClusterYPlaneNormal[tileId.y], m_ClusterInfo.ClusterYPlanePoints[tileId.y], lightPosition, range) && // plane top CullingUtls.PlaneSphereInclusion(-m_ClusterInfo.ClusterYPlaneNormal[tileId.y + 1], m_ClusterInfo.ClusterYPlanePoints[tileId.y + 1], lightPosition, range); uint unsignedLightIndex = (uint)lightIndex; if (tileIsLit) { lightIndicies.SetBits(lightIndex, true); m_TileLightIndicesMinMax[jobId] = new uint2(min(unsignedLightIndex, m_TileLightIndicesMinMax[jobId].x), max(unsignedLightIndex, m_TileLightIndicesMinMax[jobId].y)); lightCount += 1; } } } m_ResTileLightIndicesMask[jobId] = lightIndicies; m_TileLightCount[jobId] = lightCount; }
public void BitField32_Count_Leading_Trailing() { var test = new BitField32(); Assert.AreEqual(0, test.CountBits()); Assert.AreEqual(32, test.CountLeadingZeros()); Assert.AreEqual(32, test.CountTrailingZeros()); test.SetBits(31, true); Assert.AreEqual(1, test.CountBits()); Assert.AreEqual(0, test.CountLeadingZeros()); Assert.AreEqual(31, test.CountTrailingZeros()); test.SetBits(0, true); Assert.AreEqual(2, test.CountBits()); Assert.AreEqual(0, test.CountLeadingZeros()); Assert.AreEqual(0, test.CountTrailingZeros()); test.SetBits(31, false); Assert.AreEqual(1, test.CountBits()); Assert.AreEqual(31, test.CountLeadingZeros()); Assert.AreEqual(0, test.CountTrailingZeros()); }
// Context public void Execute(ScriptableRenderContext context, CullingResults cullingResults, Camera camera) { int smallTileSizeX = 64; int smallTileSizeY = 64; int bigTileSizeX = 256; int bigTileSizeY = 256; m_SmallTileCount.x = (camera.scaledPixelWidth + smallTileSizeX - 1) / smallTileSizeX; m_SmallTileCount.y = (camera.scaledPixelHeight + smallTileSizeY - 1) / smallTileSizeY; m_SmallTileCount.z = 1; m_BigTileCount.x = (camera.scaledPixelWidth + bigTileSizeX - 1) / bigTileSizeX; m_BigTileCount.y = (camera.scaledPixelHeight + bigTileSizeY - 1) / bigTileSizeY; m_BigTileCount.z = 1; int additionalLightCount = 0; int sortedLightIndex = 0; for (int i = 0; i < cullingResults.visibleLights.Length; i++) { if (cullingResults.visibleLights[i].light.type == LightType.Point || cullingResults.visibleLights[i].lightType == LightType.Spot) { additionalLightCount++; } } m_LightComparer.ViewCamera = camera; m_LightComparer.CameraForward = camera.transform.forward; m_SortedLights = new NativeArray <VisibleLight>(additionalLightCount, Allocator.TempJob); m_LightTileIndices = new NativeArray <TileLightIndex>(m_SmallTileCount.x * m_SmallTileCount.y, Allocator.TempJob); m_SmallTileIndices = new NativeArray <BitField32>(m_SmallTileCount.x * m_SmallTileCount.y, Allocator.TempJob); m_BigTileIndices = new NativeArray <BitField32>(m_BigTileCount.x * m_BigTileCount.y, Allocator.TempJob); m_LightZBinningIndices = new NativeArray <TileLightIndex>(ZBinningCount, Allocator.TempJob); for (int i = 0; i < cullingResults.visibleLights.Length; i++) { if (cullingResults.visibleLights[i].light.type == LightType.Point || cullingResults.visibleLights[i].lightType == LightType.Spot) { m_SortedLights[sortedLightIndex] = cullingResults.visibleLights[i]; sortedLightIndex++; } } //cullingResults.visibleLights.CopyTo(m_SortedLights); m_SortedLights.Sort(m_LightComparer); // wish the sorting works well var lightPos = new NativeArray <float3>(m_SortedLights.Length, Allocator.TempJob); // switch to float4 if neeed to use uniform buffer var lightRange = new NativeArray <float>(m_SortedLights.Length, Allocator.TempJob); var tileLightCount = new NativeArray <int>(m_SmallTileCount.x * m_SmallTileCount.y, Allocator.TempJob); var bigTileLightIndicesMinMax = new NativeArray <uint2>(m_BigTileCount.x * m_BigTileCount.y, Allocator.TempJob); var tileLightIndicesMinMax = new NativeArray <uint2>(m_SmallTileCount.x * m_SmallTileCount.y, Allocator.TempJob); for (var i = 0; i < m_SortedLights.Length; i++) { lightPos[i] = m_SortedLights[i].light.transform.position; lightRange[i] = m_SortedLights[i].range; } m_SmallClusterInfo.Update(m_SmallTileCount, camera); m_BigClusterInfo.Update(m_BigTileCount, camera); m_ZBinningInfo.Update(ZBinningCount, camera); TileInfo tileInfo = new TileInfo(); tileInfo.BigTileCount = m_BigTileCount.xy; tileInfo.BigTileSize = new int2(bigTileSizeX, bigTileSizeY); tileInfo.SmallTileCount = m_SmallTileCount.xy; tileInfo.SmallTileSize = new int2(smallTileSizeX, smallTileSizeY); // BroadPhaseJob(); // NarrowPhaseJob(); NativeArray <BitField32> dummpyLightTileIndices = new NativeArray <BitField32>(m_BigTileCount.x * m_BigTileCount.y, Allocator.TempJob); _mOnePhaseJobData.Prepare(lightPos, lightRange, m_LightTileIndices, tileLightCount, tileLightIndicesMinMax, m_SmallTileCount, m_SmallClusterInfo); // BroadPhase() // FillData() // NarrowPhase() var bitFiledOnes = new BitField32(~0U); for (var i = 0; i < m_BigTileIndices.Length; i++) { dummpyLightTileIndices[i] = bitFiledOnes; m_BigTileIndices[i] = bitFiledOnes; } m_BroadPhaseJobData.Prepare(lightPos, lightRange, dummpyLightTileIndices, m_BigTileIndices, tileLightCount, tileLightIndicesMinMax, m_BigClusterInfo, m_BigTileCount.xy, new int2(1, 1)); m_NarrowPhaseJobData.Prepare(lightPos, lightRange, m_BigTileIndices, m_SmallTileIndices, tileLightCount, tileLightIndicesMinMax, m_SmallClusterInfo, m_SmallTileCount.xy, new int2(bigTileSizeX / smallTileSizeX, bigTileSizeY / smallTileSizeY)); //m_NarrowPhaseJobHandle = _mOnePhaseJobData.Schedule(m_LightTileIndices.Length, m_LightTileIndices.Length); m_NarrowPhaseJobHandle = m_BroadPhaseJobData.Schedule(m_BigTileCount.x * m_BigTileCount.y, m_BigTileCount.x * m_BigTileCount.y); m_NarrowPhaseJobHandle.Complete(); m_NarrowPhaseJobHandle = m_NarrowPhaseJobData.Schedule(m_SmallTileCount.x * m_SmallTileCount.y, m_SmallTileCount.x * m_SmallTileCount.y); m_NarrowPhaseJobHandle.Complete(); // start jobs // wait for jobs to be finished // build structured buffer BuildSSBO(context, m_SortedLights, tileLightCount, tileLightIndicesMinMax, new float4(smallTileSizeX, smallTileSizeY, 1.0f / smallTileSizeX, 1.0f / smallTileSizeY), m_SmallTileCount.x, m_SmallTileCount.y); // set to command // Clean Up dummpyLightTileIndices.Dispose(); bigTileLightIndicesMinMax.Dispose(); tileLightIndicesMinMax.Dispose(); tileLightCount.Dispose(); lightPos.Dispose(); lightRange.Dispose(); m_SmallTileIndices.Dispose(); m_ZBinningInfo.Dispose(); m_BigClusterInfo.Dispose(); m_SmallClusterInfo.Dispose(); m_LightZBinningIndices.Dispose(); m_BigTileIndices.Dispose(); m_LightTileIndices.Dispose(); m_SortedLights.Dispose(); }