public void GenerateHaltonSequence() { #if UNITY_EDITOR HaltonSequenceData data = new HaltonSequenceData(3000); HaltonSequence seq = new HaltonSequence(); for (int i = 0; i < 3000; i++) { Vector3 value = seq.m_CurrentPos; while (value.x + value.z > 1f) { seq.Increment(); value = seq.m_CurrentPos; } data.xArray[i] = value.x; data.yArray[i] = value.z; seq.Increment(); } using (System.IO.MemoryStream ms = new MemoryStream()) { BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(ms, data); byte[] bytes = ms.ToArray(); File.WriteAllBytes("Assets/Tutorial/Pathfinding/Resources/HaltonSequence.bytes", bytes); } AssetDatabase.Refresh(); #endif }
private Vector3 GetRandomPos() { _haltonSeq.Increment(); Vector3 rand = _haltonSeq.m_CurrentPos; Vector3 pos = new Vector3(rand.x * mapSizeX, 0, rand.y * mapSizeZ); pos.y = Utility.GetTerrainHeight(pos) + yOffset; return(pos); }
void LateUpdate() { thisCamera.depthTextureMode = DepthTextureMode.Depth; if (thisCamera.pixelWidth != screenX || thisCamera.pixelHeight != screenY) { Debug.Log("Resizing Screen"); ResetBuffers(); } // auto focus RaycastHit hit; Ray afRay; int hits = 0; int taps = 10; float invTaps = 1.0f / taps; float newAFDepth = 0; for (int i = 0; i <= taps; i++) { for (int j = 0; j <= taps; j++) { Vector3 screenPos = Vector3.zero; screenPos.x = (screenX / taps) * i; screenPos.y = (screenY / taps) * j; afRay = thisCamera.ScreenPointToRay(screenPos); if (Physics.Raycast(afRay, out hit, 100)) { newAFDepth += Vector3.Magnitude(Vector3.Scale(thisCamera.transform.position - hit.point, thisCamera.transform.forward)); hits += 1; } } } if (hits > 0) { AutoFocalDepth = newAFDepth / hits; } // Save the current camera matrixes _CURRENT_P_MATRIX = thisCamera.projectionMatrix; _CURRENT_V_MATRIX = thisCamera.worldToCameraMatrix; _CURRENT_VP_MATRIX = thisCamera.projectionMatrix * thisCamera.worldToCameraMatrix; _CURRENT_VP_INVERSE_MATRIX = _CURRENT_VP_MATRIX.inverse; // Set the view projection matrix for this camera for motion blur Shader.SetGlobalMatrix("_CURRENT_VP_MATRIX", _CURRENT_VP_MATRIX); if (Application.isPlaying && useTAA) { // Jitter the current projection matrix with a halton sequence // This needs to be done on the camera and not the vertex shader because the shadows will flicker positionsequence.Increment(); hspos += 1; Matrix4x4 JITTER_MATRIX_P = thisCamera.projectionMatrix; //JITTER_MATRIX_P.m02 += ( positionsequence.m_CurrentPos.x * 2.0f - 1.0f ) / thisCamera.pixelWidth; //JITTER_MATRIX_P.m12 += ( positionsequence.m_CurrentPos.y * 2.0f - 1.0f ) / thisCamera.pixelHeight; JITTER_MATRIX_P[0, 2] += (positionsequence.m_CurrentPos.x * 2.0f - 1.0f) / thisCamera.pixelWidth; JITTER_MATRIX_P[1, 2] += (positionsequence.m_CurrentPos.y * 2.0f - 1.0f) / thisCamera.pixelHeight; thisCamera.projectionMatrix = JITTER_MATRIX_P; if (hspos > 16) { positionsequence.Reset(); hspos = 0; } } }