本文整理汇总了C#中UnityEngine.RenderTexture.IsCreated方法的典型用法代码示例。如果您正苦于以下问题:C# RenderTexture.IsCreated方法的具体用法?C# RenderTexture.IsCreated怎么用?C# RenderTexture.IsCreated使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.RenderTexture
的用法示例。
在下文中一共展示了RenderTexture.IsCreated方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadFromRenderTexture
public static void ReadFromRenderTexture(RenderTexture tex, int channels, ComputeBuffer buffer, ComputeShader readData)
{
if (tex == null)
{
Debug.Log("CBUtility::ReadFromRenderTexture - RenderTexture is null");
return;
}
if (buffer == null)
{
Debug.Log("CBUtility::ReadFromRenderTexture - buffer is null");
return;
}
if (readData == null)
{
Debug.Log("CBUtility::ReadFromRenderTexture - Computer shader is null");
return;
}
if (channels < 1 || channels > 4)
{
Debug.Log("CBUtility::ReadFromRenderTexture - Channels must be 1, 2, 3, or 4");
return;
}
if (!tex.IsCreated())
{
Debug.Log("CBUtility::ReadFromRenderTexture - tex has not been created (Call Create() on tex)");
return;
}
int num = 1;
int num2 = readData.FindKernel(CBUtility.readNames2D[channels - 1, 0]);
readData.SetTexture(num2, CBUtility.readNames2D[channels - 1, 1], tex);
readData.SetBuffer(num2, CBUtility.readNames2D[channels - 1, 2], buffer);
if (num2 == -1)
{
Debug.Log("CBUtility::ReadFromRenderTexture - could not find kernels");
return;
}
int width = tex.width;
int height = tex.height;
readData.SetInt("_Width", width);
readData.SetInt("_Height", height);
readData.SetInt("_Depth", num);
int num3 = (width % 8 != 0) ? 1 : 0;
int num4 = (height % 8 != 0) ? 1 : 0;
int num5 = (num % 8 != 0) ? 1 : 0;
readData.Dispatch(num2, Mathf.Max(1, width / 8 + num3), Mathf.Max(1, height / 8 + num4), Mathf.Max(1, num / 8 + num5));
}
示例2: UpdateFaceTexture
private void UpdateFaceTexture() {
if(_targetCube == null) return;
if(faceTexture == null || faceTexture.width != _targetCube.width) {
if(faceTexture) Texture2D.DestroyImmediate(faceTexture);
faceTexture = new Texture2D(_targetCube.width, _targetCube.width, TextureFormat.ARGB32, true, false);
//attempt to make an HDR render texture for RGBM capture
RT = RenderTexture.GetTemporary(_targetCube.width, _targetCube.width, 24, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
RT.Release();
RT.isCubemap = false;
RT.useMipMap = false;
RT.generateMips = false;
RT.Create();
if(!RT.IsCreated() && !RT.Create()) {
Debug.LogWarning("Failed to create HDR RenderTexture, capturing in LDR mode.");
RenderTexture.ReleaseTemporary(RT);
RT = null;
}
}
}
示例3: Start
// Use this for initialization
void Start()
{
float ratio = (float)Screen.width / (float)Screen.height;
int renderWidth = Mathf.RoundToInt ((float)renderHeight * ratio);
if (halve) {
renderWidth = renderWidth / 2;
}
renderTexture = new RenderTexture(renderWidth, renderHeight, 16);
renderTexture.isPowerOfTwo = renderWidth%2 == 0 && renderHeight%2 == 0;
renderTexture.anisoLevel = 0;
renderTexture.filterMode = FilterMode.Point;
if (!renderTexture.IsCreated()) {
renderTexture.Create();
}
Camera cam = whichCamera;
if (cam == null) {
cam = Camera.main;
}
cam.targetTexture = renderTexture;
renderedMaterial.mainTexture = renderTexture;
}
示例4: PostRender
/// Presents the #StereoScreen to the device for distortion correction and display.
/// @note This function is only used if #DistortionCorrection is set to _Native_,
/// and it only has an effect if the device supports it.
public void PostRender(RenderTexture stereoScreen)
{
if (NativeDistortionCorrectionSupported && stereoScreen != null && stereoScreen.IsCreated()) {
device.PostRender(stereoScreen);
}
}
示例5: CreateMap
void CreateMap(ref RenderTexture map, string name, RenderTextureFormat format, int size, int ansio)
{
if (map != null)
{
if (!map.IsCreated()) map.Create();
return;
}
map = new RenderTexture(size, size, 0, format, RenderTextureReadWrite.Linear);
map.filterMode = FilterMode.Trilinear;
map.wrapMode = TextureWrapMode.Repeat;
map.anisoLevel = ansio;
map.useMipMap = true;
map.hideFlags = HideFlags.HideAndDontSave;
map.name = "Ceto Wave Spectrum " + name + " Texture";
map.Create();
}
示例6: RenderHighlighting
/// <summary>
/// Render highlighting to the highlightingBuffer using frameBuffer.depthBuffer.
/// </summary>
/// <param name="frameBuffer">Frame buffer RenderTexture, depthBuffer of which will be used to occlude highlighting.</param>
public void RenderHighlighting(RenderTexture frameBuffer)
{
// Release highlightingBuffer if it wasn't released already
if (highlightingBuffer != null)
{
RenderTexture.ReleaseTemporary(highlightingBuffer);
highlightingBuffer = null;
}
if (!isSupported || !enabled || !go.activeInHierarchy) { return; }
int aa = QualitySettings.antiAliasing;
if (aa == 0) { aa = 1; }
bool depthAvailable = true;
// Check if frameBuffer.depthBuffer is not available, contains garbage (when MSAA is enabled) or doesn't have stencil bits (when depth is 16 or 0)
if (frameBuffer == null || frameBuffer.depth < 24) { depthAvailable = false; }
// Reset aa value to 1 in case mainCam is in DeferredLighting Rendering Path
if (refCam.actualRenderingPath == RenderingPath.DeferredLighting) { aa = 1; }
// In case MSAA is enabled in forward/vertex lit rendeirng paths - depth buffer contains garbage
else if (aa > 1) { depthAvailable = false; }
// Check if framebuffer depth data availability has changed
if (isDepthAvailable != depthAvailable)
{
isDepthAvailable = depthAvailable;
// Update ZWrite value for all highlighting shaders correspondingly (isDepthAvailable ? ZWrite Off : ZWrite On)
Highlighter.SetZWrite(isDepthAvailable ? 0f : 1f);
if (isDepthAvailable)
{
Debug.LogWarning("HighlightingSystem : Framebuffer depth data is available back again and will be used to occlude highlighting. Highlighting occluders disabled.");
}
else
{
Debug.LogWarning("HighlightingSystem : Framebuffer depth data is not available and can't be used to occlude highlighting. Highlighting occluders enabled.");
}
}
// Set global depth offset properties for highlighting shaders to the values which has this HighlightingBase component
Highlighter.SetOffsetFactor(offsetFactor);
Highlighter.SetOffsetUnits(offsetUnits);
// Set this component as currently active HighlightingBase before enabling Highlighters
current = this;
// Turn on highlighting shaders on all highlighter components
int count = 0;
for (int i = 0; i < highlighters.Count; i++)
{
if (highlighters[i].Highlight()) { count++; }
}
// Do nothing in case no Highlighters is currently visible
if (count == 0)
{
current = null;
return;
}
// If frameBuffer.depthBuffer is not available
int w = Screen.width;
int h = Screen.height;
int depth = 24; // because stencil will be rendered to the highlightingBuffer.depthBuffer
// If frameBuffer.depthBuffer is available
if (isDepthAvailable)
{
w = frameBuffer.width;
h = frameBuffer.height;
depth = 0; // because stencil will be rendered to frameBuffer.depthBuffer
}
// Setup highlightingBuffer RenderTexture
highlightingBuffer = RenderTexture.GetTemporary(w, h, depth, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default, aa);
if (!highlightingBuffer.IsCreated())
{
highlightingBuffer.filterMode = FilterMode.Point;
highlightingBuffer.useMipMap = false;
highlightingBuffer.wrapMode = TextureWrapMode.Clamp;
}
// Clear highlightingBuffer colorBuffer and clear depthBuffer only in case frameBuffer depth data is not available
RenderTexture.active = highlightingBuffer;
GL.Clear((isDepthAvailable ? false : true), true, Color.clear);
// Use depth data from frameBuffer in case it is available. Use highlightingBuffer.depthBuffer otherwise
RenderBuffer depthBuffer = isDepthAvailable ? frameBuffer.depthBuffer : highlightingBuffer.depthBuffer;
if (!shaderCameraGO)
{
shaderCameraGO = new GameObject("HighlightingCamera");
shaderCameraGO.hideFlags = HideFlags.HideAndDontSave;
shaderCamera = shaderCameraGO.AddComponent<Camera>();
shaderCamera.enabled = false;
}
//.........这里部分代码省略.........
示例7: DrawGauge
private void DrawGauge(RenderTexture screen)
{
if (NavUtilLib.GlobalVariables.Settings.enableDebugging)
{
Debug.Log("NavUtils: NavUtilLibApp.DrawGauge()");
}
NavUtilLib.GlobalVariables.FlightData.updateNavigationData();
RenderTexture pt = RenderTexture.active;
RenderTexture.active = screen;
if (!screen.IsCreated()) screen.Create();
NavUtilLib.DisplayData.DrawHSI(screen, 1);
//write text to screen
//write runway info
if (rwyHover)
NavUtilLib.TextWriter.addTextToRT(screen, "→Runway: " + NavUtilLib.GlobalVariables.FlightData.selectedRwy.ident, new Vector2(20, screen.height - 40), NavUtilLib.GlobalVariables.Materials.Instance.whiteFont, .64f);
else
NavUtilLib.TextWriter.addTextToRT(screen, " Runway: " + NavUtilLib.GlobalVariables.FlightData.selectedRwy.ident, new Vector2(20, screen.height - 40), NavUtilLib.GlobalVariables.Materials.Instance.whiteFont, .64f);
if (gsHover)
NavUtilLib.TextWriter.addTextToRT(screen, "→Glideslope: " + string.Format("{0:F1}", NavUtilLib.GlobalVariables.FlightData.selectedGlideSlope) + "° Elevation: " + string.Format("{0:F0}", NavUtilLib.GlobalVariables.FlightData.selectedRwy.altMSL) + "m", new Vector2(20, screen.height - 64), NavUtilLib.GlobalVariables.Materials.Instance.whiteFont, .64f);
else
NavUtilLib.TextWriter.addTextToRT(screen, " Glideslope: " + string.Format("{0:F1}", NavUtilLib.GlobalVariables.FlightData.selectedGlideSlope) + "° Elevation: " + string.Format("{0:F0}", NavUtilLib.GlobalVariables.FlightData.selectedRwy.altMSL) + "m", new Vector2(20, screen.height - 64), NavUtilLib.GlobalVariables.Materials.Instance.whiteFont, .64f);
NavUtilLib.TextWriter.addTextToRT(screen, NavUtilLib.Utils.numberFormatter((float)NavUtilLib.Utils.makeAngle0to360(FlightGlobals.ship_heading), true).ToString(), new Vector2(584, screen.height - 102), NavUtilLib.GlobalVariables.Materials.Instance.whiteFont, .64f);
NavUtilLib.TextWriter.addTextToRT(screen, NavUtilLib.Utils.numberFormatter((float)NavUtilLib.Utils.makeAngle0to360(NavUtilLib.GlobalVariables.FlightData.bearing), true).ToString(), new Vector2(584, screen.height - 131), NavUtilLib.GlobalVariables.Materials.Instance.whiteFont, .64f);
NavUtilLib.TextWriter.addTextToRT(screen, NavUtilLib.Utils.numberFormatter((float)NavUtilLib.Utils.makeAngle0to360(NavUtilLib.GlobalVariables.FlightData.selectedRwy.hdg), true).ToString(), new Vector2(35, screen.height - 124), NavUtilLib.GlobalVariables.Materials.Instance.whiteFont, .64f);
NavUtilLib.TextWriter.addTextToRT(screen, NavUtilLib.Utils.numberFormatter((float)NavUtilLib.GlobalVariables.FlightData.dme / 1000, false).ToString(), new Vector2(45, screen.height - 563), NavUtilLib.GlobalVariables.Materials.Instance.whiteFont, .64f);
if (closeHover)
NavUtilLib.TextWriter.addTextToRT(screen, " Close HSI", new Vector2(340, 15), NavUtilLib.GlobalVariables.Materials.Instance.whiteFont, .64f);
RenderTexture.active = pt;
}
示例8: capture
public bool capture(Texture targetCube, Vector3 position, Quaternion rotation, bool HDR, bool linear, bool convolve)
{
if(targetCube == null) return false;
bool tempRT = false;
if(cubeRT == null) {
tempRT = true;
//everything's captured to an HDR buffer right now
cubeRT = RenderTexture.GetTemporary(targetCube.width, targetCube.width, 24, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
cubeRT.isCubemap = true;
cubeRT.useMipMap = true;
cubeRT.generateMips = true;
if(!cubeRT.IsCreated() && !cubeRT.Create()) {
cubeRT = RenderTexture.GetTemporary(targetCube.width, targetCube.width, 24, RenderTextureFormat.Default, RenderTextureReadWrite.Linear);
cubeRT.isCubemap = true;
cubeRT.useMipMap = true;
cubeRT.generateMips = true;
}
}
if(!cubeRT.IsCreated() && !cubeRT.Create()) return false;
GameObject go = null;
Camera cam = null;
go = new GameObject("_temp_probe");
cam = go.AddComponent<Camera>();
mset.SkyManager mgr = mset.SkyManager.Get();
if(mgr && mgr.ProbeCamera) {
cam.CopyFrom (mgr.ProbeCamera);
} else if(Camera.main) {
cam.CopyFrom (Camera.main);
}
cam.renderingPath = renderPath;
cam.useOcclusionCulling = false;
cam.hdr = true;
go.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideAndDontSave;
go.SetActive(true);
go.transform.position = position;
//capture entire scene in HDR
Shader.SetGlobalVector("_UniformOcclusion", this.exposures);
cam.RenderToCubemap(cubeRT);
Shader.SetGlobalVector("_UniformOcclusion", Vector4.one);
Matrix4x4 matrix = Matrix4x4.identity;
matrix.SetTRS(position, rotation, Vector3.one);
//render cubeRT converting it to RGBM
Material skyMat = new Material(Shader.Find("Hidden/Marmoset/RGBM Cube"));
bool dstRGBM = HDR;
bool srcRGBM = false;
copy_internal(targetCube, cubeRT, dstRGBM, srcRGBM, linear, cam, skyMat, matrix);
if( convolve ) {
convolve_internal(targetCube, cubeRT, HDR, false, linear, cam, skyMat, matrix);
}
//make sure the old sky and matrix vars are bound again
if(mgr) mgr.GlobalSky = mgr.GlobalSky;
Material.DestroyImmediate(skyMat);
GameObject.DestroyImmediate(go);
if(tempRT) RenderTexture.ReleaseTemporary(cubeRT);
return true;
}
示例9: renderToTexture
/// <summary>
/// render the vessel diagram to a texture.
/// </summary>
/// <param name="renderTexture">Texture to render to.</param>
void renderToTexture(RenderTexture renderTexture)
{
//render not when invisible, grasshopper.
if (basicSettings.screenVisible)
{
//switch rendering to the texture
RenderTexture backupRenderTexture = RenderTexture.active;
if (!renderTexture.IsCreated())
renderTexture.Create();
renderTexture.DiscardContents();
RenderTexture.active = renderTexture;
//setup viewport and such
GL.PushMatrix();
GL.LoadPixelMatrix(0, renderTexture.width, 0, renderTexture.height);
GL.Viewport(new Rect(0, 0, renderTexture.width, renderTexture.height));
//clear the texture
GL.Clear(true, true, Color.black);
//set up the screen position and scaling matrix
Matrix4x4 matrix = Matrix4x4.TRS(new Vector3(basicSettings.scrOffX, basicSettings.scrOffY, 0), Quaternion.identity, new Vector3(basicSettings.scaleFact, basicSettings.scaleFact, 1));
//dunno what this does, but I trust in the stolen codes
lineMaterial.SetPass(0);
while (partQueue.Count > 0)
{
Part next = partQueue.Dequeue();
if (next != null)
{
renderPart(next, matrix, true);
}
}
GL.Clear(true, false, Color.black);
if (partQueue.Count == 0)
{
if (!FlightGlobals.ActiveVessel.isEVA)
{
partQueue.Enqueue(FlightGlobals.ActiveVessel.rootPart);
}
}
//lineMaterial.SetPass(1);
//turn on wireframe, since triangles would get filled othershipwise
GL.wireframe = true;
//now render each part (assumes root part is in the queue)
while (partQueue.Count > 0)
{
Part next = partQueue.Dequeue();
if (next != null)
{
renderPart(next, matrix, false);
}
}
//now render engine exhaust indicators
if (customMode == null)
{
if (basicSettings.displayEngines)
{
renderEngineThrusts(matrix);
}
}
else
{
switch (customMode.MinimodesOverride)
{
case (int)CustomModeSettings.OVERRIDE_TYPES.AS_BASIC:
if (basicSettings.displayEngines)
{
renderEngineThrusts(matrix);
} break;
case (int)CustomModeSettings.OVERRIDE_TYPES.STATIC:
if (customMode.staticSettings.displayEngines)
{
renderEngineThrusts(matrix);
} break;
case (int)CustomModeSettings.OVERRIDE_TYPES.FUNCTION:
if (customMode.displayEnginesDelegate(customMode))
{
renderEngineThrusts(matrix);
} break;
}
}
//now render the bounding boxes (so theyre on top)
if (customMode == null)
{
if (basicSettings.colorModeBox != (int)ViewerConstants.COLORMODE.HIDE)
{
renderRects(matrix);
}
}
else
{
switch (customMode.ColorModeOverride)
{
case (int)CustomModeSettings.OVERRIDE_TYPES.AS_BASIC:
//.........这里部分代码省略.........
示例10: ReadFromRenderTexture
/*
static string[,] readNames3D = new string[,]
{
{"read3DC1", "_Tex3D", "_Buffer3DC1"},
{"read3DC2", "_Tex3D", "_Buffer3DC2"},
{"read3DC3", "_Tex3D", "_Buffer3DC3"},
{"read3DC4", "_Tex3D", "_Buffer3DC4"}
};
*/
public static void ReadFromRenderTexture(RenderTexture tex, int channels, ComputeBuffer buffer, ComputeShader readData)
{
if(tex == null)
{
Debug.Log("CBUtility::ReadFromRenderTexture - RenderTexture is null");
return;
}
if(buffer == null)
{
Debug.Log("CBUtility::ReadFromRenderTexture - buffer is null");
return;
}
if(readData == null)
{
Debug.Log("CBUtility::ReadFromRenderTexture - Computer shader is null");
return;
}
if(channels < 1 || channels > 4)
{
Debug.Log("CBUtility::ReadFromRenderTexture - Channels must be 1, 2, 3, or 4");
return;
}
if(!tex.IsCreated())
{
Debug.Log("CBUtility::ReadFromRenderTexture - tex has not been created (Call Create() on tex)");
return;
}
int kernel = -1;
int depth = 1;
//if(tex.isVolume)
//{
// depth = tex.volumeDepth;
// kernel = readData.FindKernel(readNames3D[channels - 1, 0]);
// readData.SetTexture(kernel, readNames3D[channels - 1, 1], tex);
// readData.SetBuffer(kernel, readNames3D[channels - 1, 2], buffer);
//}
//else
//{
kernel = readData.FindKernel(readNames2D[channels - 1, 0]);
readData.SetTexture(kernel, readNames2D[channels - 1, 1], tex);
readData.SetBuffer(kernel, readNames2D[channels - 1, 2], buffer);
//}
if(kernel == -1)
{
Debug.Log("CBUtility::ReadFromRenderTexture - could not find kernels");
return;
}
int width = tex.width;
int height = tex.height;
//set the compute shader uniforms
readData.SetInt("_Width", width);
readData.SetInt("_Height", height);
readData.SetInt("_Depth", depth);
//run the compute shader. Runs in threads of 8 so non divisible by 8 numbers will need
//some extra threadBlocks. This will result in some unneeded threads running
int padX = (width%8 == 0) ? 0 : 1;
int padY = (height%8 == 0) ? 0 : 1;
int padZ = (depth%8 == 0) ? 0 : 1;
readData.Dispatch(kernel, Mathf.Max(1,width/8 + padX), Mathf.Max(1, height/8 + padY), Mathf.Max(1, depth/8 + padZ));
}
示例11: ReadSingleFromRenderTexture
public static void ReadSingleFromRenderTexture(RenderTexture tex, float x, float y, float z, ComputeBuffer buffer, ComputeShader readData, bool useBilinear)
{
if(tex == null)
{
Debug.Log("CBUtility::ReadSingleFromRenderTexture - RenderTexture is null");
return;
}
if(buffer == null)
{
Debug.Log("CBUtility::ReadSingleFromRenderTexture - buffer is null");
return;
}
if(readData == null)
{
Debug.Log("CBUtility::ReadSingleFromRenderTexture - Computer shader is null");
return;
}
if(!tex.IsCreated())
{
Debug.Log("CBUtility::ReadSingleFromRenderTexture - tex has not been created (Call Create() on tex)");
return;
}
int kernel = -1;
int depth = 1;
//if(tex.isVolume)
//{
// depth = tex.volumeDepth;
//
// if(useBilinear)
// kernel = readData.FindKernel("readSingle3D");
// else
// kernel = readData.FindKernel("readSingleBilinear3D");
//
// readData.SetTexture(kernel, "_Tex3D", tex);
// readData.SetBuffer(kernel, "BufferSingle3D", buffer);
//}
//else
//{
if(useBilinear)
kernel = readData.FindKernel("readSingle2D");
else
kernel = readData.FindKernel("readSingleBilinear2D");
readData.SetTexture(kernel, "_Tex2D", tex);
readData.SetBuffer(kernel, "BufferSingle2D", buffer);
//}
if(kernel == -1)
{
Debug.Log("CBUtility::ReadSingleFromRenderTexture - could not find kernels");
return;
}
int width = tex.width;
int height = tex.height;
//used for point sampling
readData.SetInt("_IdxX", (int)x);
readData.SetInt("_IdxY", (int)y);
readData.SetInt("_IdxZ", (int)z);
//used for bilinear sampling
readData.SetVector("_UV", new Vector4( x / (float)(width-1), y / (float)(height-1), z / (float)(depth-1), 0.0f));
readData.Dispatch(kernel, 1, 1, 1);
}
示例12: ReadSingleFromRenderTexture
public static void ReadSingleFromRenderTexture(RenderTexture tex, float x, float y, float z, ComputeBuffer buffer, ComputeShader readData, bool useBilinear)
{
if (tex == null)
{
Debug.Log("CBUtility::ReadSingleFromRenderTexture - RenderTexture is null");
return;
}
if (buffer == null)
{
Debug.Log("CBUtility::ReadSingleFromRenderTexture - buffer is null");
return;
}
if (readData == null)
{
Debug.Log("CBUtility::ReadSingleFromRenderTexture - Computer shader is null");
return;
}
if (!tex.IsCreated())
{
Debug.Log("CBUtility::ReadSingleFromRenderTexture - tex has not been created (Call Create() on tex)");
return;
}
int num = 1;
int num2;
if (useBilinear)
{
num2 = readData.FindKernel("readSingle2D");
}
else
{
num2 = readData.FindKernel("readSingleBilinear2D");
}
readData.SetTexture(num2, "_Tex2D", tex);
readData.SetBuffer(num2, "BufferSingle2D", buffer);
if (num2 == -1)
{
Debug.Log("CBUtility::ReadSingleFromRenderTexture - could not find kernels");
return;
}
int width = tex.width;
int height = tex.height;
readData.SetInt("_IdxX", (int)x);
readData.SetInt("_IdxY", (int)y);
readData.SetInt("_IdxZ", (int)z);
readData.SetVector("_UV", new Vector4(x / (float)(width - 1), y / (float)(height - 1), z / (float)(num - 1), 0f));
readData.Dispatch(num2, 1, 1, 1);
}