本文整理汇总了C#中UnityEngine.RenderTexture类的典型用法代码示例。如果您正苦于以下问题:C# RenderTexture类的具体用法?C# RenderTexture怎么用?C# RenderTexture使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RenderTexture类属于UnityEngine命名空间,在下文中一共展示了RenderTexture类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MultiPassBlur
protected virtual void MultiPassBlur(RenderTexture source, RenderTexture destination)
{
int w = Mathf.FloorToInt((float)source.width / Downscaling);
int h = Mathf.FloorToInt((float)source.height / Downscaling);
Vector2 horizontal = new Vector2(1f / w, 0f);
Vector2 vertical = new Vector2(0f, 1f / h);
RenderTexture rt1 = RenderTexture.GetTemporary(w, h, 0, source.format);
RenderTexture rt2 = RenderTexture.GetTemporary(w, h, 0, source.format);
Material.SetVector("_Direction", horizontal);
Graphics.Blit(source, rt1, Material);
Material.SetVector("_Direction", vertical);
Graphics.Blit(rt1, rt2, Material);
for (int i = 1; i < Passes; i++)
{
Material.SetVector("_Direction", horizontal);
Graphics.Blit(rt2, rt1, Material);
Material.SetVector("_Direction", vertical);
Graphics.Blit(rt1, rt2, Material);
}
Graphics.Blit(rt2, destination);
RenderTexture.ReleaseTemporary(rt1);
RenderTexture.ReleaseTemporary(rt2);
}
示例2: OnRenderImage
public void OnRenderImage(RenderTexture source, RenderTexture destination)
{
CheckResources();
originalTex = new Texture2D(source.width, source.height);
// change texture. every white pixel should be transparent after this
int y = 0;
while (y < originalTex.height)
{
int x = 0;
while (x < originalTex.width)
{
Color colorAtPixel = new Color();
colorAtPixel = originalTex.GetPixel(x, y);
if (colorAtPixel[0] == 1 && colorAtPixel[1] == 1 && colorAtPixel[2] == 1 && colorAtPixel[3] == 1)
{
originalTex.SetPixel(x, y, Color.clear);
}
else
{
originalTex.SetPixel(x, y, new Color(colorAtPixel[0], colorAtPixel[1], colorAtPixel[2], colorAtPixel[3] ));
}
++x;
}
++y;
}
originalTex.Apply();
transparentMaterial.SetTexture("_MainTex", originalTex);
Graphics.Blit(source, destination, transparentMaterial, 0);
}
示例3: OnRenderImage
void OnRenderImage(RenderTexture source, RenderTexture destination)
{
if (_material == null)
{
_material = new Material(_shader);
_material.hideFlags = HideFlags.DontSave;
}
var cam = GetComponent<Camera>();
var aspect = new Vector4(cam.aspect, 1.0f / cam.aspect, 1, 0);
_material.SetVector("_CameraAspect", aspect);
_material.SetFloat("_LateralShift", _lateralShift);
_material.SetFloat("_AxialStrength", _axialStrength);
_material.SetFloat("_AxialShift", _axialShift);
if (_axialStrength == 0)
{
_material.DisableKeyword("AXIAL_SAMPLE_LOW");
_material.DisableKeyword("AXIAL_SAMPLE_HIGH");
}
else if (_axialQuality == QualityLevel.Low)
{
_material.EnableKeyword("AXIAL_SAMPLE_LOW");
_material.DisableKeyword("AXIAL_SAMPLE_HIGH");
}
else
{
_material.DisableKeyword("AXIAL_SAMPLE_LOW");
_material.EnableKeyword("AXIAL_SAMPLE_HIGH");
}
Graphics.Blit(source, destination, _material, 0);
}
示例4: FlyingCamera
public FlyingCamera(Part thatPart, RenderTexture screen, float aspect)
{
ourVessel = thatPart.vessel;
ourPart = thatPart;
screenTexture = screen;
cameraAspect = aspect;
}
示例5: Cleanup
public void Cleanup()
{
if (this.m_Camera)
{
UnityEngine.Object.DestroyImmediate(this.m_Camera.gameObject, true);
}
if (this.m_RenderTexture)
{
UnityEngine.Object.DestroyImmediate(this.m_RenderTexture);
this.m_RenderTexture = null;
}
if (this.m_RenderTextureGammaCorrect)
{
UnityEngine.Object.DestroyImmediate(this.m_RenderTextureGammaCorrect);
this.m_RenderTextureGammaCorrect = null;
}
Light[] light = this.m_Light;
for (int i = 0; i < light.Length; i++)
{
Light light2 = light[i];
if (light2)
{
UnityEngine.Object.DestroyImmediate(light2.gameObject, true);
}
}
}
示例6: OnRenderImage
protected override void OnRenderImage(RenderTexture source, RenderTexture destination)
{
Material.SetVector("_RedClamp", Red);
Material.SetVector("_GreenClamp", Green);
Material.SetVector("_BlueClamp", Blue);
Graphics.Blit(source, destination, Material);
}
示例7: OnRenderImage
void OnRenderImage(RenderTexture src, RenderTexture dst)
{
if (m_material == null)
{
m_material = new Material(m_shader);
}
if (m_edge_highlighting)
{
m_material.EnableKeyword("ENABLE_EDGE_HIGHLIGHTING");
}
else
{
m_material.DisableKeyword("ENABLE_EDGE_HIGHLIGHTING");
}
if (m_mul_smoothness)
{
m_material.EnableKeyword("ENABLE_SMOOTHNESS_ATTENUAION");
}
else
{
m_material.DisableKeyword("ENABLE_SMOOTHNESS_ATTENUAION");
}
m_material.SetVector("_Color", GetLinearColor());
m_material.SetVector("_Params1", new Vector4(m_fresnel_bias, m_fresnel_scale, m_fresnel_pow, m_intensity));
m_material.SetVector("_Params2", new Vector4(m_edge_intensity, m_edge_threshold, m_edge_radius, 0.0f));
Graphics.Blit(src, dst, m_material);
}
示例8: PostScreenshot
IEnumerator PostScreenshot()
{
yield return new WaitForEndOfFrame();
var cam = Camera.current;
var renderTexture = new RenderTexture(Screen.width, Screen.height, 24);
cam.targetTexture = renderTexture;
cam.Render();
cam.targetTexture = null;
Texture2D screenshot = new Texture2D(renderTexture.width, renderTexture.height, TextureFormat.RGB24, false);
screenshot.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0);
screenshot.Apply();
Debug.Log("Screenshot taken...");
Imvu.Login().Then(
userModel => userModel.GetPersonalFeed()
).Then(
feedCollection => {
return feedCollection.PostImage(screenshot);
}
).Then(
_ => Debug.Log("Screenshot posted!")
).Catch(
error => Debug.Log(error.message)
);
}
示例9: OnRenderImage
void OnRenderImage(RenderTexture src, RenderTexture dest)
{
int desiredDepth = Math.Max(src.depth, dest.depth);
for (int i = 0; i < temp.Length; i++)
{
if (onRenderImageMethods.Count > i + 1)
{
if (temp[i] != null &&
(temp[i].width != dest.width || temp[i].height != dest.height || temp[i].depth != desiredDepth || temp[i].format != dest.format))
{
Destroy(temp[i]);
temp[i] = null;
}
if (temp[i] == null)
temp[i] = new RenderTexture(dest.width, dest.height, desiredDepth, dest.format);
}
}
var sequence = new List<RenderTexture>();
sequence.Add(src);
for (int i = 0; i < onRenderImageMethods.Count - 1; i++)
sequence.Add(i % 2 == 0 ? temp[0] : temp[1]);
sequence.Add(dest);
for (int i = 0; i < onRenderImageMethods.Count; i++)
onRenderImageMethods[i].Method.Invoke(onRenderImageMethods[i].Instance, new object[] { sequence[i], sequence[i + 1] });
}
示例10: OnRenderImage
protected override void OnRenderImage(RenderTexture source, RenderTexture destination)
{
Material.SetVector("_Red", m_Channels[(int)RedSource]);
Material.SetVector("_Green", m_Channels[(int)GreenSource]);
Material.SetVector("_Blue", m_Channels[(int)BlueSource]);
Graphics.Blit(source, destination, Material);
}
示例11: OnRenderImage
void OnRenderImage(RenderTexture source, RenderTexture destination) {
base.material.SetFloat("_Speed", speed);
base.material.SetFloat("_Thickness", thickness);
base.material.SetFloat("_Luminance", luminance);
base.material.SetFloat("_Darkness", darkness);
Graphics.Blit (source, destination, material);
}
示例12: OnRenderImage
protected override void OnRenderImage(RenderTexture source, RenderTexture destination)
{
Material.SetVector("_Params", new Vector4(Sharpness * 0.01f, Darkness * 0.02f, Contrast * 0.01f, EdgeBlending * 0.01f));
Material.SetVector("_Coeffs", ContrastCoeff);
Material.SetVector("_Center", Center);
Graphics.Blit(source, destination, Material);
}
示例13: Blur
// flat blur
void Blur(RenderTexture from ,RenderTexture to , int iterations , int blurPass, float spread )
{
RenderTexture tmp = RenderTexture.GetTemporary (to.width, to.height, 0);
if (iterations < 2) {
dofBlurMaterial.SetVector ("offsets", new Vector4 (0.0f, spread * oneOverBaseSize, 0.0f, 0.0f));
tmp.DiscardContents ();
Graphics.Blit (from, tmp, dofBlurMaterial, blurPass);
dofBlurMaterial.SetVector ("offsets", new Vector4 (spread / widthOverHeight * oneOverBaseSize, 0.0f, 0.0f, 0.0f));
to.DiscardContents ();
Graphics.Blit (tmp, to, dofBlurMaterial, blurPass);
}
else {
dofBlurMaterial.SetVector ("offsets", new Vector4 (0.0f, spread * oneOverBaseSize, 0.0f, 0.0f));
tmp.DiscardContents ();
Graphics.Blit (from, tmp, dofBlurMaterial, blurPass);
dofBlurMaterial.SetVector ("offsets", new Vector4 (spread / widthOverHeight * oneOverBaseSize, 0.0f, 0.0f, 0.0f));
to.DiscardContents ();
Graphics.Blit (tmp, to, dofBlurMaterial, blurPass);
dofBlurMaterial.SetVector ("offsets", new Vector4 (spread / widthOverHeight * oneOverBaseSize, spread * oneOverBaseSize, 0.0f, 0.0f));
tmp.DiscardContents ();
Graphics.Blit (to, tmp, dofBlurMaterial, blurPass);
dofBlurMaterial.SetVector ("offsets", new Vector4 (spread / widthOverHeight * oneOverBaseSize, -spread * oneOverBaseSize, 0.0f, 0.0f));
to.DiscardContents ();
Graphics.Blit (tmp, to, dofBlurMaterial, blurPass);
}
RenderTexture.ReleaseTemporary (tmp);
}
示例14: PipeTextures
protected void PipeTextures()
{
RefreshTextureScript rts = this.GetComponent<RefreshTextureScript>();
if (rts != null) {
this.source = rts.toReplace;
} else {
//grab original base texture. this is source.
this.source = this.renderer.material.GetTexture("_MainTex");
}
if ((this.source as RenderTexture) != null) {
RenderTexture s = this.source as RenderTexture;
//create new destination texture.
this.destination = new RenderTexture(s.width,s.height,s.depth);
} else {
this.destination = new RenderTexture(source.width,source.height,24);
}
//assign destination texture to existing shader.
if (rts != null) {
rts.toReplace = this.destination;
} else {
this.renderer.material.SetTexture("_MainTex",this.destination);
}
}
示例15: OnRenderImage
void OnRenderImage( RenderTexture source, RenderTexture destination )
{
if( CheckResources() == false )
{
Graphics.Blit( source, destination );
return;
}
cloudsMaterial.SetFloat( "_ForwardIntegrator", m_distTravelledForward );
Vector4 camPos = new Vector4( transform.position.x, transform.position.y, transform.position.z, 0.0f );
cloudsMaterial.SetVector( "_CamPos", camPos );
Vector4 camForward = new Vector4( transform.forward.x, transform.forward.y, transform.forward.z, 0.0f );
cloudsMaterial.SetVector( "_CamForward", camForward );
Vector4 camRight = new Vector4( transform.right.x, transform.right.y, transform.right.z, 0.0f );
cloudsMaterial.SetVector( "_CamRight", camRight );
/*
Vector4 spherePos = Vector4.zero;
if( sphere )
spherePos.Set( sphere.position.x, sphere.position.y, sphere.position.z, 0.0f );
cloudsMaterial.SetVector( "_SphereCenter", spherePos );
*/
cloudsMaterial.SetTexture( "_NoiseTex", noiseTexture );
Graphics.Blit( source, destination, cloudsMaterial, 0 );
cloudsMaterial.SetFloat( "_SamplesCurvature", m_samplesCurvature );
//cloudsMaterial.SetFloat( "_CenterOfRot", centerOfRot );
float fov = Mathf.Max( Camera.main.aspect, 1.0f ) * Camera.main.fieldOfView * Mathf.Deg2Rad;
cloudsMaterial.SetFloat( "_HalfFov", fov/2.0f );
}