/// <summary> /// Update the scene environment reflections /// </summary> public void UpdateReflections() { if (!probeGameObject || !probeComponent) { UpdateReflectionProbe(); } // The Update function refreshes the Reflection Probe and copies the result to the default specular reflection Cubemap. // The texture associated with the real-time Reflection Probe is a render target and RenderSettings.customReflection is a Cubemap. We have to check the support if copying from render targets to Textures is supported. if ((SystemInfo.copyTextureSupport & CopyTextureSupport.RTToTexture) != 0) { // Wait until previous RenderProbe is finished before we refresh the Reflection Probe again. // renderId is a token used to figure out when the refresh of a Reflection Probe is finished. The refresh of a Reflection Probe can take mutiple frames when time-slicing is used. if (renderId == -1 || probeComponent.IsFinishedRendering(renderId)) { if (probeComponent.IsFinishedRendering(renderId)) { //Debug.Log("probeComponent.texture.width = " + probeComponent.texture.width + " blendedCubemap.width = "+ blendedCubemap.width); //Debug.Log("probeComponent.texture.height = " + probeComponent.texture.height + " blendedCubemap.height = " + blendedCubemap.height); //Debug.Log("probeComponent.resolution = " + probeComponent.resolution); // After the previous RenderProbe is finished, we copy the probe's texture to the cubemap and set it as a custom reflection in RenderSettings. if (probeComponent.texture.width == blendedCubemap.width && probeComponent.texture.height == blendedCubemap.height) { Graphics.CopyTexture(probeComponent.texture, blendedCubemap as Texture); //Debug.Log("Copying"); } RenderSettings.customReflection = blendedCubemap; } renderId = probeComponent.RenderProbe(); } } }
private void Update() { if (rf.IsFinishedRendering(RenderId)) { rf.RenderProbe(targetTexture = null); } }
IEnumerator RenderReflection() { while (true) { int i = reflectionProbe.RenderProbe(); yield return(new WaitWhile(() => reflectionProbe.IsFinishedRendering(i))); } }
public void Convert() { if (targetProbe != null) { if (texture != null) { DestroyImmediate(texture); } texture = new Texture2D(targetProbe.resolution * 4, targetProbe.resolution * 3) { wrapMode = TextureWrapMode.Clamp }; if (blitMat != null) { DestroyImmediate(blitMat); } blitMat = new Material(Shader.Find("Hiddent/HDRP/Tests/TexCubeToTex2D")); blitMat.SetFloat("_CorrectGamma", correctGamma ? 1 : 0); blitMat.SetFloat("_BoxLayout", boxLayout ? 1 : 0); RenderTexture dest = new RenderTexture(texture.width, texture.height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default); while (!targetProbe.IsFinishedRendering(renderID)) { } ; probeTexture = targetProbe.texture; Graphics.Blit(probeTexture, dest, blitMat); // Readback the rendered texture var oldActive = RenderTexture.active; RenderTexture.active = dest; texture.ReadPixels(new Rect(0, 0, texture.width, texture.height), 0, 0); RenderTexture.active = oldActive; texture.Apply(); GetComponent <RawImage>().texture = texture; } }
// Update is called once per frame void Update() { if (probe == null) { return; } if (probe.IsFinishedRendering(0)) { probe.RenderProbe(); } }
// Update is called once per frame void Update() { if (isReflesh) { renderID = probeComponent.RenderProbe(); //isButtonActive = false; isReflesh = false; } if (probeComponent.IsFinishedRendering(renderID)) { isButtonActive = true; } }
private IEnumerator ReflectionProbeUpdate() { var waiter = new WaitForEndOfFrame(); var currentSlice = -1; for (;;) { for (int i = 0; i < 2; i++) { yield return(waiter); } currentSlice = reflectionProbe.RenderProbe(); while (!reflectionProbe.IsFinishedRendering(currentSlice)) { yield return(waiter); } } }
void Update() { // if PlayTOD instance does not exist, switch refresh mode to every frame, then disable it-self if (playTOD == null) { TheProbe.refreshMode = UnityEngine.Rendering.ReflectionProbeRefreshMode.EveryFrame; enabled = false; } else { if (playTOD.UpdateProbes) { StartCoroutine(ProcessProbesCoroutine()); } if (TheProbe.IsFinishedRendering(RenderId)) { StopCoroutine(ProcessProbesCoroutine()); playTOD.UpdateProbes = false; } } }
/// <summary> /// Sets the probe settings /// </summary> public void SetProbeSettings() { ReflectionProbe reflectionProbe = gameObject.GetComponent <ReflectionProbe>(); reflectionProbe.timeSlicingMode = ReflectionProbeTimeSlicingMode.AllFacesAtOnce; reflectionProbe.boxProjection = m_boxProjection; reflectionProbe.hdr = m_useHDR; reflectionProbe.intensity = 1f; reflectionProbe.importance = 1; reflectionProbe.clearFlags = ReflectionProbeClearFlags.Skybox; reflectionProbe.center = new Vector3(0f, 0f, 0f); if (GameObject.Find("Ambient Water Sample")) { reflectionProbe.size = new Vector3(125f, 10000f, 125f); reflectionProbe.mode = ReflectionProbeMode.Realtime; reflectionProbe.refreshMode = ReflectionProbeRefreshMode.ViaScripting; } switch (m_probeResolution) { case ReflectionQuality.VeryLow: reflectionProbe.resolution = 32; reflectionProbe.shadowDistance = 5f; break; case ReflectionQuality.Low: reflectionProbe.resolution = 64; reflectionProbe.shadowDistance = 10f; break; case ReflectionQuality.Medium: reflectionProbe.resolution = 128; reflectionProbe.shadowDistance = 25f; break; case ReflectionQuality.High: reflectionProbe.resolution = 256; reflectionProbe.shadowDistance = 75f; break; case ReflectionQuality.VeryHigh: reflectionProbe.resolution = 512; reflectionProbe.shadowDistance = 100f; break; case ReflectionQuality.Ultra: reflectionProbe.resolution = 1024; reflectionProbe.shadowDistance = 150f; break; } switch (m_probeRenderDistance) { case RenderDistanceQuality.Close: reflectionProbe.farClipPlane = 250f; break; case RenderDistanceQuality.Near: reflectionProbe.farClipPlane = 500f; break; case RenderDistanceQuality.Far: reflectionProbe.farClipPlane = 1000f; break; case RenderDistanceQuality.VeryFar: reflectionProbe.farClipPlane = 2000f; break; case RenderDistanceQuality.ExtremelyFar: reflectionProbe.farClipPlane = 4000f; break; } if (reflectionProbe.IsFinishedRendering(m_renderID)) { m_renderID = reflectionProbe.RenderProbe(); } }
//-------------------------------------------------------------------------- public void Update() { #if UNITY_EDITOR if (Application.isPlaying == false && lastNightDuration == nightDuration && lastHour == hour && lastLongitude == longitude) { return; } if (lastNightDuration != nightDuration) { lastNightDuration = nightDuration; UpdateGradients(); } #endif lastHour = hour; lastLongitude = longitude; dt = Time.deltaTime; if (animate && Application.isPlaying) { hour += dt * 24.0f / (60 * dayMinutesDuration); } if (hour > 24) { hour -= 24; } isNight = hour < nightDuration / 2 || hour > 24 - (nightDuration / 2); hourEval = lightAngleCurve.Evaluate(hour); myLight.transform.position = mainCamera.position; myLight.transform.localEulerAngles = new Vector3(hourEval, 0, 0); myLight.transform.Rotate(Vector3.up, longitude); if (hour > 12) { myLight.transform.localEulerAngles = new Vector3(myLight.transform.localEulerAngles.x, myLight.transform.localEulerAngles.y + 180, 0); myLight.transform.localEulerAngles = new Vector3(myLight.transform.localEulerAngles.x, -myLight.transform.localEulerAngles.y, 0); } lightColor = gradientColor.Evaluate(hour / 24.0f); myLight.color = lightColor; gray = lightColor.grayscale; RenderSettings.ambientIntensity = gray; skyMaterial.SetFloat("_Exposure", gray * 1.3f); skyMaterial.SetColor("_SkyTint", lightColor); skyMaterial.SetColor("_GroundColor", lightColor * 0.5f); myLight.shadowStrength = gray; RenderSettings.ambientSkyColor = lightColor * 0.85f; RenderSettings.ambientEquatorColor = lightColor * 0.5f; RenderSettings.ambientGroundColor = lightColor * 0.015f; intensity = isNight ? 0 : gray; //always update probe when dawn t = intensity > 0 && intensity < 1 ? 1 : t + dt; if (probe.IsFinishedRendering(probeRenderID) && t >= 1) { t = 0; Graphics.CopyTexture(probe.texture, RenderSettings.customReflection as Cubemap); probeRenderID = probe.RenderProbe(); } }