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; } // 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; } // 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); }