private void OnRenderImage(RenderTexture source, RenderTexture destination) { if (!EffectMaterial) { Graphics.Blit(source, destination); // do nothing return; } // pass frustum rays to shader EffectMaterial.SetMatrix("_FrustumCornersES", GetFrustumCorners(CurrentCamera)); EffectMaterial.SetMatrix("_CameraInvViewMatrix", CurrentCamera.cameraToWorldMatrix); EffectMaterial.SetVector("_CameraWS", CurrentCamera.transform.position); // pass textures to shader EffectMaterial.SetTexture("_rgbTex", rgb_tex); EffectMaterial.SetTexture("_zTex", z_tex); // pass eye intrinsics & extrinsics to shader EffectMaterial.SetMatrix("_eyeExtrinsics", EyeDataCollection.eyes[0].Extrinsics); EffectMaterial.SetMatrix("_eyeIntrinsics", EyeDataCollection.eyes[0].Intrinsics); EffectMaterial.SetVector("_eyeUV", EyeDataCollection.eyes[0].UV); CustomGraphicsBlit(source, destination, EffectMaterial, 0); // use given effect shader as image effec }
void OnRenderImage(RenderTexture source, RenderTexture destination) { if (!EffectMaterial) { Graphics.Blit(source, destination); // do nothing return; } // pass frustum rays to shader EffectMaterial.SetMatrix("_FrustumCornersES", GetFrustumCorners(CurrentCamera)); EffectMaterial.SetMatrix("_CameraInvViewMatrix", CurrentCamera.cameraToWorldMatrix); EffectMaterial.SetVector("_CameraWS", CurrentCamera.transform.position); EffectMaterial.SetVector("_LightDir", SunLight ? SunLight.forward : Vector3.down); EffectMaterial.SetTexture("_ColorRamp", _ColorRamp); // Construct a Model Matrix for the Torus Matrix4x4 MatTorus = Matrix4x4.TRS( Vector3.right * Mathf.Sin(Time.time) * 5, Quaternion.identity, Vector3.one); MatTorus *= Matrix4x4.TRS( Vector3.zero, Quaternion.Euler(new Vector3(0, 0, (Time.time * 200) % 360)), Vector3.one); // Send the torus matrix to our shader EffectMaterial.SetMatrix("_MatTorus_InvModel", MatTorus.inverse); CustomGraphicsBlit(source, destination, EffectMaterial, 0); // Replace Graphics.Blit with CustomGraphicsBlit }
void OnRenderImage(RenderTexture source, RenderTexture destination) { if (!EffectMaterial) { Graphics.Blit(source, destination); // do nothing return; } Matrix4x4 MatTorus = Matrix4x4.TRS( Vector3.right * Mathf.Sin(Time.time) * 5, Quaternion.identity, Vector3.one); MatTorus *= Matrix4x4.TRS( Vector3.zero, Quaternion.Euler(new Vector3(0, 0, (Time.time * 200) % 360)), Vector3.one); // pass frustum rays to shader EffectMaterial.SetVector("_CameraWS", CurrentCamera.transform.position); EffectMaterial.SetMatrix("_CameraInvViewMatrix", CurrentCamera.cameraToWorldMatrix); EffectMaterial.SetMatrix("_FrustumCornersES", GetFrustumCorners(CurrentCamera)); EffectMaterial.SetVector("_LightDir", SunLight ? SunLight.forward : Vector3.down); EffectMaterial.SetFloat("move", move); EffectMaterial.SetFloat("eegData", gameObject.GetComponent <Muse>().eeg_data[0]); EffectMaterial.SetFloat("time", Time.time); EffectMaterial.SetTexture("_ColorRamp", _ColorRamp); CustomGraphicsBlit(source, destination, EffectMaterial, 0); }
private void Update() { if (!rgb_Tex || !z_Tex) { RefreshTextures(); } if (frustum.IsPointInsideFrustum(Camera.main.transform.position, 0.1f)) { EffectMaterial.EnableKeyword("CAMERA_INSIDE"); EffectMaterial.DisableKeyword("CAMERA_OUTSIDE"); EffectMaterial.SetFloat("_Cull", 1); } else { EffectMaterial.EnableKeyword("CAMERA_OUTSIDE"); EffectMaterial.DisableKeyword("CAMERA_INSIDE"); EffectMaterial.SetFloat("_Cull", 2); } EffectMaterial.SetFloat("_farClip", frustum.farClip); EffectMaterial.SetFloat("_nearClip", frustum.nearClip); EffectMaterial.SetTexture("_MainTex", rgb_Tex); EffectMaterial.SetTexture("_zTex", z_Tex); EffectMaterial.SetVector("_eyeFwd", transform.forward); }
void OnRenderImage(RenderTexture source, RenderTexture destination) { if (!EffectMaterial) { Graphics.Blit(source, destination); // do nothing return; } // Set any custom shader variables here. For example, you could do: // EffectMaterial.SetFloat("_MyVariable", 13.37f); // This would set the shader uniform _MyVariable to value 13.37 EffectMaterial.SetVector("_LightDir", lightTransform ? lightTransform.forward : Vector3.down); //// Construct a Model Matrix for the Torus //Matrix4x4 MatTorus = Matrix4x4.TRS( // Vector3.right * Mathf.Sin(Time.time) * 5, // Quaternion.identity, // Vector3.one); //MatTorus *= Matrix4x4.TRS( // Vector3.zero, // Quaternion.Euler(new Vector3(0, 0, (Time.time * 200) % 360)), // Vector3.one); //// Send the torus matrix to our shader //EffectMaterial.SetMatrix("_MatTorus_InvModel", MatTorus.inverse); EffectMaterial.SetColor("_Color", mainColor); if (matColorRamp) { EffectMaterial.SetTexture("_ColorRamp_Material", matColorRamp); } if (perfColorRamp) { EffectMaterial.SetTexture("_ColorRamp_PerfMap", perfColorRamp); } if (densColorRamp) { EffectMaterial.SetTexture("_ColorRamp_Density", densColorRamp); } EffectMaterial.SetFloat("_DrawDistance", rayMarchMaxDist); if (EffectMaterial.IsKeywordEnabled("DEBUG_PERFORMANCE") != debugPerformance) { if (debugPerformance) { EffectMaterial.EnableKeyword("DEBUG_PERFORMANCE"); } else { EffectMaterial.DisableKeyword("DEBUG_PERFORMANCE"); } } EffectMaterial.SetMatrix("_FrustumCornersES", GetFrustumCorners(CurrentCamera)); EffectMaterial.SetMatrix("_CameraInvViewMatrix", CurrentCamera.cameraToWorldMatrix); EffectMaterial.SetVector("_CameraWS", CurrentCamera.transform.position); CustomGraphicsBlit(source, destination, EffectMaterial, 0); }
void OnRenderImage(RenderTexture source, RenderTexture destination) { if (!EffectMaterial) { //位块传输,简单的赋值 Graphics.Blit(source, destination); // do nothing return; } // Set any custom shader variables here. For example, you could do: // EffectMaterial.SetFloat("_MyVariable", 13.37f); // This would set the shader uniform _MyVariable to value 13.37 //设置着色器参数 //光线方向,世界坐标系 EffectMaterial.SetVector("_LightDir", SunLight ? SunLight.forward : Vector3.down); // Construct a Model Matrix for the Torus Matrix4x4 MatTorus = Matrix4x4.TRS( Vector3.right * Mathf.Sin(Time.time) * 5, Quaternion.identity, Vector3.one); MatTorus *= Matrix4x4.TRS( Vector3.zero, Quaternion.Euler(new Vector3(0, 0, (Time.time * 200) % 360)), Vector3.one); // Send the torus matrix to our shader //圆环的模型转世界矩阵,定义了圆环的运动 EffectMaterial.SetMatrix("_MatTorus_InvModel", MatTorus.inverse); EffectMaterial.SetTexture("_ColorRamp_Material", _MaterialColorRamp); EffectMaterial.SetTexture("_ColorRamp_PerfMap", _PerfColorRamp); //rayMarch算法最大前进距离 EffectMaterial.SetFloat("_DrawDistance", _RaymarchDrawDistance); //性能调试开关 if (EffectMaterial.IsKeywordEnabled("DEBUG_PERFORMANCE") != _DebugPerformance) { if (_DebugPerformance) { EffectMaterial.EnableKeyword("DEBUG_PERFORMANCE"); } else { EffectMaterial.DisableKeyword("DEBUG_PERFORMANCE"); } } //视椎体顶点向量矩阵,摄像机坐标系 EffectMaterial.SetMatrix("_FrustumCornersES", GetFrustumCorners(CurrentCamera)); //摄像机转世界矩阵 EffectMaterial.SetMatrix("_CameraInvViewMatrix", CurrentCamera.cameraToWorldMatrix); //摄像机位置,世界坐标系 EffectMaterial.SetVector("_CameraWS", CurrentCamera.transform.position); CustomGraphicsBlit(source, destination, EffectMaterial, 0); }
void OnRenderImage(RenderTexture source, RenderTexture destination) { if (!EffectMaterial) { Graphics.Blit(source, destination); // do nothing return; } //if (!RenderMaterial) //{ // Graphics.Blit(source, destination); // do nothing // return; //} // pass frustum rays to shader EffectMaterial.SetMatrix("_FrustumCornersES", GetFrustumCorners(CurrentCamera)); EffectMaterial.SetMatrix("_CameraInvViewMatrix", CurrentCamera.cameraToWorldMatrix); EffectMaterial.SetVector("_cameraWS", CurrentCamera.transform.position); EffectMaterial.SetTexture("_cloudNoise3D", CloudTex3D); EffectMaterial.SetFloat("_cutoff", CutOff); EffectMaterial.SetFloat("_cloudScale", CloudScale); EffectMaterial.SetTexture("_heightTex", HeightTex); EffectMaterial.SetFloat("_cloudBase", CloudBase); EffectMaterial.SetFloat("_layerHeight", LayerHeight); EffectMaterial.SetTexture("_randomNoiseTex", BlueNoise); //EffectMaterial.SetVector("_lightDir", SkyLight.transform.forward); EffectMaterial.SetTexture("_detailTex", DetailTex); EffectMaterial.SetFloat("_edgeScale", EdgeScale); EffectMaterial.SetFloat("_erodeDepth", ErodeDepth); EffectMaterial.SetFloat("_coverage", Coverage); EffectMaterial.SetFloat("_BeerLaw", BeerLaw); EffectMaterial.SetFloat("_SilverIntensity", SilverIntensity); EffectMaterial.SetFloat("_SilverSpread", SilverSpread); EffectMaterial.SetTexture("_CurlNoise", CurlNoise); EffectMaterial.SetFloat("_CurlTile", CurlTile); EffectMaterial.SetFloat("_CurlStrength", CurlStrength); EffectMaterial.SetFloat("_CloudTopOffset", TopOffset); EffectMaterial.SetFloat("_MaxDistance", MaxDistance); EffectMaterial.SetTexture("_WeatherTex", WeatherTex); EffectMaterial.SetFloat("_WeatherTexSize", WeatherTexSize); EffectMaterial.SetFloat("_nearestRenderDistance", nearestRenderDistance); Matrix4x4 projectionMatrix = GL.GetGPUProjectionMatrix(_CurrentCamera.projectionMatrix, false); projectionMatrix = GL.GetGPUProjectionMatrix(_ShadowCamera.projectionMatrix, false); EffectMaterial.SetMatrix("_inverseVP", Matrix4x4.Inverse(projectionMatrix * _CurrentCamera.worldToCameraMatrix)); EffectMaterial.SetMatrix("_WorldToShadow", projectionMatrix * _ShadowCamera.worldToCameraMatrix); EffectMaterial.SetFloat("_WindSpeed", WindSpeed); EffectMaterial.SetFloat("_cloudDensity", CloudDensity); CustomGraphicsBlit(null, cloud, EffectMaterial, 0); RenderMaterial.SetTexture("cloudTexture", cloud); Graphics.Blit(source, destination, RenderMaterial); }
private void OnRenderImage(RenderTexture source, RenderTexture destination) { if (!EffectMaterial) { Graphics.Blit(source, destination); return; } EffectMaterial.SetTexture("_Mask", mask); CustomGraphicsBlit(source, destination, EffectMaterial, 0); }
void OnRenderImage(RenderTexture source, RenderTexture destination) { if (!EffectMaterial) { Graphics.Blit(source, destination); // do nothing return; } // Set any custom shader variables here. For example, you could do: // EffectMaterial.SetFloat("_MyVariable", 13.37f); // This would set the shader uniform _MyVariable to value 13.37 conductor?.PopulateUniforms(EffectMaterial); EffectMaterial.SetVector("_LightDir", SunLight ? SunLight.forward : Vector3.down); EffectMaterial.SetTexture("_ColorRamp_Material", _MaterialColorRamp); EffectMaterial.SetTexture("_ColorRamp_PerfMap", _PerfColorRamp); EffectMaterial.SetFloat("_DrawDistance", _RaymarchDrawDistance); if (EffectMaterial.IsKeywordEnabled("DEBUG_PERFORMANCE") != _DebugPerformance) { if (_DebugPerformance) { EffectMaterial.EnableKeyword("DEBUG_PERFORMANCE"); } else { EffectMaterial.DisableKeyword("DEBUG_PERFORMANCE"); } } EffectMaterial.SetMatrix("_FrustumCornersES", GetFrustumCorners(CurrentCamera)); EffectMaterial.SetMatrix("_CameraInvViewMatrix", CurrentCamera.cameraToWorldMatrix); EffectMaterial.SetVector("_CameraWS", CurrentCamera.transform.position); EffectMaterial.SetVector("_Resolution", new Vector2((float)Camera.main.pixelWidth, (float)Camera.main.pixelHeight)); CustomGraphicsBlit(source, destination, EffectMaterial, 0); }
void OnRenderImage(RenderTexture source, RenderTexture destination) { if (!EffectMaterial) { Graphics.Blit(source, destination); // do nothing return; } // pass frustum rays to shader EffectMaterial.SetMatrix("_FrustumCornersES", GetFrustumCorners(CurrentCamera)); EffectMaterial.SetMatrix("_CameraInvViewMatrix", CurrentCamera.cameraToWorldMatrix); EffectMaterial.SetVector("_CameraWS", CurrentCamera.transform.position); EffectMaterial.SetMatrix("_FrustumCornersES", GetFrustumCorners(CurrentCamera)); EffectMaterial.SetVector("_LightDir", SunLight ? SunLight.forward : Vector3.down); EffectMaterial.SetTexture("_ColorRamp", _ColorRamp); EffectMaterial.SetTexture("_ColorSky", _ColorSky); // Graphics.Blit(source, destination, EffectMaterial, 0); // use given effect shader as image effect CustomGraphicsBlit(source, destination, EffectMaterial, 0); // Replace Graphics.Blit with CustomGraphicsBlit }
void OnRenderImage(RenderTexture source, RenderTexture destination) { if (!EffectMaterial) { Graphics.Blit(source, destination); // do nothing return; } // Set any custom shader variables here. For example, you could do: // EffectMaterial.SetFloat("_MyVariable", 13.37f); // This would set the shader uniform _MyVariable to value 13.37 EffectMaterial.SetVector("_LightDir", SunLight ? SunLight.forward : Vector3.down); // Construct a Model Matrix for the Torus Matrix4x4 MatTorus = Matrix4x4.TRS( Vector3.right * Mathf.Sin(Time.time) * 5, Quaternion.identity, Vector3.one); MatTorus *= Matrix4x4.TRS( Vector3.zero, Quaternion.Euler(new Vector3(0, 0, (Time.time * 200) % 360)), Vector3.one); // Send the torus matrix to our shader EffectMaterial.SetMatrix("_MatTorus_InvModel", MatTorus.inverse); EffectMaterial.SetTexture("_ColorRamp_Material", _MaterialColorRamp); EffectMaterial.SetTexture("_ColorRamp_PerfMap", _PerfColorRamp); EffectMaterial.SetFloat("_DrawDistance", _RaymarchDrawDistance); if (EffectMaterial.IsKeywordEnabled("DEBUG_PERFORMANCE") != _DebugPerformance) { if (_DebugPerformance) { EffectMaterial.EnableKeyword("DEBUG_PERFORMANCE"); } else { EffectMaterial.DisableKeyword("DEBUG_PERFORMANCE"); } } EffectMaterial.SetMatrix("_FrustumCornersES", GetFrustumCorners(CurrentCamera)); EffectMaterial.SetMatrix("_CameraInvViewMatrix", CurrentCamera.cameraToWorldMatrix); EffectMaterial.SetVector("_CameraWS", CurrentCamera.transform.position); //Matrix4x4 partPos = new Matrix4x4( // new Vector4(-0.5f + (Mathf.Sin(Time.time)+1.0f)/2.0f, 0.5f - (Mathf.Sin(Time.time) + 1.0f) / 2.0f, 0.0f, 0.2f), // new Vector4(-0.5f, -0.5f, 0.0f, 0.2f), // new Vector4(0.5f, 0.5f, 0.0f, 0.2f), // new Vector4(0.5f, -0.5f, 0.0f, 0.2f) //); EffectMaterial.SetMatrix("_PartPos", pm.Particules); EffectMaterial.SetVector("_Resolution", new Vector2((float)Camera.main.pixelWidth, (float)Camera.main.pixelHeight)); CustomGraphicsBlit(source, destination, EffectMaterial, 0); }
void OnRenderImage(RenderTexture source, RenderTexture destination) { if (!EffectMaterial) { Graphics.Blit(source, destination); // do nothing return; } var cameraParams = new Vector4(currentCamera.sensorSize.x, currentCamera.sensorSize.y, currentCamera.focalLength, m_Aperture); if (currentCamera.transform.position != m_CameraPrevPos || currentCamera.transform.rotation != m_CameraPrevRot || m_Render == null || m_Render.width != destination.width || m_Render.height != destination.height || m_ShouldReset || m_Sun.intensity != m_SunPrevIntensity || m_Sun.color != m_SunPrevColor || m_Sun.transform.forward != m_SunPrevDir || cameraParams != m_PrevCameraParams || m_SunSize != m_SunPrevSize) { // Reset renderer //Debug.Log("Resetting renderer..."); if (m_Render == null || m_Render.width != destination.width || m_Render.height != destination.height) { m_Render = new RenderTexture(destination.width, destination.height, 0, RenderTextureFormat.ARGBFloat); } m_CameraPrevPos = currentCamera.transform.position; m_CameraPrevRot = currentCamera.transform.rotation; m_SunPrevIntensity = m_Sun.intensity; m_SunPrevColor = m_Sun.color; m_SunPrevDir = m_Sun.transform.forward; m_SunPrevSize = m_SunSize; m_PrevCameraParams = cameraParams; m_IntegrationCount = 0; m_ShouldReset = false; } if (m_Sun) { Vector3 sunColor = new Vector3(m_Sun.color.r, m_Sun.color.g, m_Sun.color.b) * m_Sun.intensity; EffectMaterial.SetVector("_SunColor", sunColor); EffectMaterial.SetVector("_SunDir", m_Sun.transform.forward); EffectMaterial.SetFloat("_SunSize", m_SunSize); } if (m_ReflectionProbe) { m_ReflectionProbe.RenderProbe(); EffectMaterial.SetTexture("_IBLTex", m_ReflectionProbe.texture); } EffectMaterial.SetVector("_CameraRight", currentCamera.transform.right); EffectMaterial.SetVector("_CameraUp", currentCamera.transform.up); EffectMaterial.SetVector("_CameraForward", currentCamera.transform.forward); EffectMaterial.SetVector("_CameraParams", cameraParams); EffectMaterial.SetFloat("_IntegrationCount", m_IntegrationCount); EffectMaterial.SetVector("_Random", new Vector4(Random.Range(-1f, 1f), Random.Range(-1f, 1f), Random.Range(-1f, 1f), Random.Range(-1f, 1f))); Graphics.Blit(source, m_Render, EffectMaterial, 0); m_IntegrationCount++; Graphics.Blit(m_Render, destination); }