IsCreated() 공개 메소드

Is the render texture actually created?

public IsCreated ( ) : bool
리턴 bool
예제 #1
0
 static public int IsCreated(IntPtr l)
 {
     try {
         UnityEngine.RenderTexture self = (UnityEngine.RenderTexture)checkSelf(l);
         var ret = self.IsCreated();
         pushValue(l, ret);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static public int IsCreated(IntPtr l)
 {
     try{
         UnityEngine.RenderTexture self = (UnityEngine.RenderTexture)checkSelf(l);
         System.Boolean            ret  = self.IsCreated();
         pushValue(l, ret);
         return(1);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
예제 #3
0
 static int QPYX_IsCreated_YXQP(IntPtr L_YXQP)
 {
     try
     {
         ToLua.CheckArgsCount(L_YXQP, 1);
         UnityEngine.RenderTexture QPYX_obj_YXQP = (UnityEngine.RenderTexture)ToLua.CheckObject <UnityEngine.RenderTexture>(L_YXQP, 1);
         bool QPYX_o_YXQP = QPYX_obj_YXQP.IsCreated();
         LuaDLL.lua_pushboolean(L_YXQP, QPYX_o_YXQP);
         return(1);
     }
     catch (Exception e_YXQP)                {
         return(LuaDLL.toluaL_exception(L_YXQP, e_YXQP));
     }
 }
 static int IsCreated(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         UnityEngine.RenderTexture obj = (UnityEngine.RenderTexture)ToLua.CheckObject(L, 1, typeof(UnityEngine.RenderTexture));
         bool o = obj.IsCreated();
         LuaDLL.lua_pushboolean(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
예제 #5
0
 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));
 }
	static int IsCreated(IntPtr L)
	{
#if UNITY_EDITOR
        ToluaProfiler.AddCallRecord("UnityEngine.RenderTexture.IsCreated");
#endif
		try
		{
			ToLua.CheckArgsCount(L, 1);
			UnityEngine.RenderTexture obj = (UnityEngine.RenderTexture)ToLua.CheckObject<UnityEngine.RenderTexture>(L, 1);
			bool o = obj.IsCreated();
			LuaDLL.lua_pushboolean(L, o);
			return 1;
		}
		catch (Exception e)
		{
			return LuaDLL.toluaL_exception(L, e);
		}
	}
예제 #7
0
		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;
				}		
			}
		}
예제 #8
0
    // 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;
    }
예제 #9
0
 /// 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);
     }
 }
예제 #10
0
        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();

        }
예제 #11
0
		/// <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;
			}
			
			shaderCamera.CopyFrom(refCam);
			//shaderCamera.projectionMatrix = mainCam.projectionMatrix;		// Uncomment this line if you have problems using Highlighting System with custom projection matrix on your camera
			shaderCamera.cullingMask = layerMask;
			shaderCamera.rect = new Rect(0f, 0f, 1f, 1f);
			shaderCamera.renderingPath = RenderingPath.Forward;
			shaderCamera.depthTextureMode = DepthTextureMode.None;
			shaderCamera.hdr = false;
			shaderCamera.useOcclusionCulling = false;
			shaderCamera.backgroundColor = new Color(0, 0, 0, 0);
			shaderCamera.clearFlags = CameraClearFlags.Nothing;
			shaderCamera.SetTargetBuffers(highlightingBuffer.colorBuffer, depthBuffer);

			// Get rid of "Tiled GPU Perf warning" if we're not in debug mode
			#if !DEBUG_ENABLED
			frameBuffer.MarkRestoreExpected();
			#endif
			shaderCamera.Render();

			// Extinguish all highlighters
			for (int i = 0; i < highlighters.Count; i++)
			{
				highlighters[i].Extinguish();
			}

			// Highlighting buffer rendering finished. Reset currently active HighlightingBase
			current = null;

			// Create two buffers for blurring the image
			int width = highlightingBuffer.width / _downsampleFactor;
			int height = highlightingBuffer.height / _downsampleFactor;
			RenderTexture buffer = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default, 1);
			RenderTexture buffer2 = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default, 1);
			if (!buffer.IsCreated())
			{
				buffer.useMipMap = false;
				buffer.wrapMode = TextureWrapMode.Clamp;
			}
			if (!buffer2.IsCreated())
			{
				buffer2.useMipMap = false;
				buffer2.wrapMode = TextureWrapMode.Clamp;
			}
			
			// Copy highlighting buffer to the smaller texture
			Graphics.Blit(highlightingBuffer, buffer, blitMaterial);
			
			// Blur the small texture
			bool oddEven = true;
			for (int i = 0; i < iterations; i++)
			{
				if (oddEven) { FourTapCone(buffer, buffer2, i); }
				else { FourTapCone(buffer2, buffer, i); }
				oddEven = !oddEven;
			}
			
			// Upscale blurred texture and cut stencil from it
			Graphics.SetRenderTarget(highlightingBuffer.colorBuffer, depthBuffer);
			cutMaterial.SetTexture(ShaderPropertyID._MainTex, oddEven ? buffer : buffer2);
			DoubleBlit(cutMaterial, 0, cutMaterial, 1);

			// Cleanup
			RenderTexture.ReleaseTemporary(buffer);
			RenderTexture.ReleaseTemporary(buffer2);
		}
예제 #12
0
        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;
        }
예제 #13
0
        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;
        }
예제 #14
0
        /// <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:
                            if (basicSettings.colorModeBox != (int)ViewerConstants.COLORMODE.HIDE)
                            {
                                renderRects(matrix);
                            }break;
                        case (int)CustomModeSettings.OVERRIDE_TYPES.STATIC:
                            if (customMode.staticSettings.colorModeBox != (int)ViewerConstants.COLORMODE.HIDE)
                            {
                                renderRects(matrix);
                            }break;
                        case (int)CustomModeSettings.OVERRIDE_TYPES.FUNCTION:
                            renderRects(matrix);
                            break;
                    }
                }
                
                //now render center of mass
                if (customMode == null)
                {
                    if (basicSettings.displayCOM) 
                    {
                        renderCOM(matrix);
                    }
                }
                else
                {
                    switch (customMode.MinimodesOverride)
                    {
                        case (int)CustomModeSettings.OVERRIDE_TYPES.AS_BASIC:
                            if (basicSettings.displayCOM) 
                            {
                                renderCOM(matrix);
                            } break;
                        case (int)CustomModeSettings.OVERRIDE_TYPES.STATIC:
                            if (customMode.staticSettings.displayCOM)
                            {
                                renderCOM(matrix);
                            } break;
                        case (int)CustomModeSettings.OVERRIDE_TYPES.FUNCTION:
                            if (customMode.displayCOMDelegate(customMode))
                            {
                                renderCOM(matrix);
                            } break;
                    }
                }
                //first, render the ground
                if (customMode == null)
                {
                    if (basicSettings.displayGround != (int)ViewerConstants.GROUND_DISPMODE.OFF)
                    {
                        renderGround(matrix);
                    }
                }
                else
                {
                    switch (customMode.MinimodesOverride)
                    {
                        case (int)CustomModeSettings.OVERRIDE_TYPES.AS_BASIC:
                            if (basicSettings.displayGround != (int)ViewerConstants.GROUND_DISPMODE.OFF)
                            {
                                renderGround(matrix);
                            } break;
                        case (int)CustomModeSettings.OVERRIDE_TYPES.STATIC:
                            if (customMode.staticSettings.displayGround != (int)ViewerConstants.GROUND_DISPMODE.OFF)
                            {
                                renderGround(matrix);
                            } break;
                        case (int)CustomModeSettings.OVERRIDE_TYPES.FUNCTION:
                            if (customMode.displayGroundDelegate(customMode) != (int)ViewerConstants.GROUND_DISPMODE.OFF)
                            {
                                renderGround(matrix);
                            } break;
                    }
                }
                //first, render the ground
                if (customMode == null)
                {
                    if (basicSettings.displayAxes)
                    {
                        renderAxes(matrix);
                    }
                }
                else
                {
                    switch (customMode.MinimodesOverride)
                    {
                        case (int)CustomModeSettings.OVERRIDE_TYPES.AS_BASIC:
                            if (basicSettings.displayAxes)
                            {
                                renderAxes(matrix);
                            } break;
                        case (int)CustomModeSettings.OVERRIDE_TYPES.STATIC:
                            if (customMode.staticSettings.displayAxes)
                            {
                                renderAxes(matrix);
                            } break;
                        case (int)CustomModeSettings.OVERRIDE_TYPES.FUNCTION:
                            if (customMode.displayAxesDelegate(customMode))
                            {
                                renderAxes(matrix);
                            } break;
                    }
                }
                
                /*if (settings.displayCOP)
                {
                    renderCOP(matrix);
                }*/
                //then set the max stages (for the stage coloring)
                stagesLastTime = stagesThisTimeMax;
                //undo stuff
                GL.wireframe = false;
                GL.PopMatrix();
                RenderTexture.active = backupRenderTexture;
            }
        }
예제 #15
0
 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);
 }
예제 #16
0
        /*
        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));
        }
예제 #17
0
        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);
        }