private float3[] GetScreenPixelPositions() { TDCamera camera = this.scene.camera; float worldNearPlaneHeight = camera.nearPlaneDistance * math.tan(camera.verticalFOV * Mathf.Deg2Rad * 0.5f) * 2.0f; float worldNearPlaneWidth = camera.aspectRatio * worldNearPlaneHeight; worldHeightPerPixel = worldNearPlaneHeight / camera.pixelResolution.y; worldWidthPerPixel = worldNearPlaneWidth / camera.pixelResolution.x; float3 worldLowerLeftCorner = camera.position + camera.forward * camera.nearPlaneDistance - camera.right * 0.5f * worldNearPlaneWidth - camera.up * 0.5f * worldNearPlaneHeight; float3[] pixelPositions = new float3[(int)camera.pixelResolution.x * (int)camera.pixelResolution.y]; for (int i = 0; i < camera.pixelResolution.x; ++i) { for (int j = 0; j < camera.pixelResolution.y; ++j) { float3 currentPixelPosition = worldLowerLeftCorner + camera.right * worldWidthPerPixel * i + camera.up * worldHeightPerPixel * j; pixelPositions[i * (int)camera.pixelResolution.y + j] = currentPixelPosition; } } return(pixelPositions); }
private void GPUPrepare() { TDCamera camera = this.scene.camera; float worldNearPlaneHeight = camera.nearPlaneDistance * math.tan(camera.verticalFOV * Mathf.Deg2Rad * 0.5f) * 2.0f; float worldNearPlaneWidth = camera.aspectRatio * worldNearPlaneHeight; worldHeightPerPixel = worldNearPlaneHeight / camera.pixelResolution.y; worldWidthPerPixel = worldNearPlaneWidth / camera.pixelResolution.x; pixelResolutionX = (int)this.scene.camera.pixelResolution.x; pixelResolutionY = (int)this.scene.camera.pixelResolution.y; kernelHandle = cs.FindKernel("CSMain"); gpuTexture = new RenderTexture(pixelResolutionX, pixelResolutionY, 24); gpuTexture.enableRandomWrite = true; gpuTexture.Create(); gpuTexture.filterMode = FilterMode.Point; cs.SetInt("numIterations", numIterations); cs.SetInt("numSpheres", this.scene.spheres.Count); cs.SetInt("pixelResolutionX", pixelResolutionX); cs.SetInt("pixelResolutionY", pixelResolutionY); cs.SetInt("sampleRate", this.renderConfiguration.sampleRate); cs.SetFloat("widthPerPixel", worldWidthPerPixel); cs.SetFloat("heightPerPixel", worldHeightPerPixel); cs.SetVector("cameraPosition", new Vector3(this.scene.camera.position.x, this.scene.camera.position.y, this.scene.camera.position.z)); cs.SetVector("ambientLight", new Vector3(this.ambientLight.x, this.ambientLight.y, this.ambientLight.z)); ComputeBuffer screenPixelPositionBuffer = new ComputeBuffer(pixelResolutionX * pixelResolutionY, 3 * 4); screenPixelPositionBuffer.SetData(this.GetScreenPixelPositions()); cs.SetBuffer(kernelHandle, "screenPixelPositions", screenPixelPositionBuffer); ComputeBuffer sphereBuffer = new ComputeBuffer(this.scene.spheres.Count, 13 * 4); sphereBuffer.SetData(this.scene.spheres); cs.SetBuffer(kernelHandle, "spheres", sphereBuffer); this.SphericalFib(ref this.sphereicalFibSamples); ComputeBuffer sampleBuffer = new ComputeBuffer(32768, 3 * 4); sampleBuffer.SetData(this.sphereicalFibSamples); cs.SetBuffer(kernelHandle, "sphericalSamples", sampleBuffer); cs.SetTexture(kernelHandle, "Texture", gpuTexture); }
public static TDScene LoadScene() { TDCamera camera = new TDCamera(Camera.main); List <TDSphere> spheres = new List <TDSphere>(); TDSceneSphere[] sceneSpheres = MonoBehaviour.FindObjectsOfType <TDSceneSphere>(); foreach (TDSceneSphere sceneSphere in sceneSpheres) { spheres.Add(new TDSphere(sceneSphere.transform.position, new Unity.Mathematics.float3(sceneSphere.albedo.r, sceneSphere.albedo.g, sceneSphere.albedo.b), sceneSphere.emissionIntensity * new Unity.Mathematics.float3(sceneSphere.emission.r, sceneSphere.emission.g, sceneSphere.emission.b), sceneSphere.transform.lossyScale.x * 0.5f, TDLoader.GetMaterialIndex(sceneSphere.material), sceneSphere.fuzz, sceneSphere.refractiveIndex)); } return(new TDScene(camera, spheres)); }
private void Update() { if (maincam == null) { maincam = GameManager.gm.mainCamera.GetComponent <TDCamera>(); } if (healthPoints <= 0 && isAlive) { Death(); } AntiPauseActions(); if (Time.timeScale != 0) { if (attackTimer < attackSpeed) { attackTimer += Time.deltaTime; } /********************************************************* * ANYTHING IN THIS STATEMENT WILL ADHERE TO PAUSING **********************************************************/ targetObj = SelectCollider.Target; KeyboardInput(); MouseInput(); if (buildingMode) { BuildingMode(); } /**************************************************************** * NOTHING AFTER THIS ADHERES TO PAUSING * **************************************************************/ } }
private void Start() { healthPoints = maxHealth; maincam = Camera.main.GetComponent <TDCamera>(); }
public void SetCamera(TDCamera cam) { maincam = cam; }