static public int RenderWithShader(IntPtr l) { try { UnityEngine.Camera self = (UnityEngine.Camera)checkSelf(l); UnityEngine.Shader a1; checkType(l, 2, out a1); System.String a2; checkType(l, 3, out a2); self.RenderWithShader(a1, a2); pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } }
static public int RenderWithShader(IntPtr l) { try{ UnityEngine.Camera self = (UnityEngine.Camera)checkSelf(l); UnityEngine.Shader a1; checkType(l, 2, out a1); System.String a2; checkType(l, 3, out a2); self.RenderWithShader(a1, a2); return(0); } catch (Exception e) { LuaDLL.luaL_error(l, e.ToString()); return(0); } }
public Color32 GetHitXY(Camera targetCamera, int x, int y) { RenderTexture rTex = new RenderTexture(Screen.width, Screen.height, 24); Texture2D screen = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false); RenderTexture oldTex = targetCamera.targetTexture; RenderTexture oldActive = RenderTexture.active; Color oldBack = targetCamera.backgroundColor; targetCamera.targetTexture = rTex; targetCamera.backgroundColor = Color.black; RenderTexture.active = rTex; targetCamera.RenderWithShader(altShader, tagName); screen.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0); targetCamera.backgroundColor = oldBack; targetCamera.targetTexture = oldTex; RenderTexture.active = oldActive; Destroy(rTex); Color32 result = screen.GetPixel(x, y); return result; }
RenderTexture UpdateOcclusionCamera(Camera source, Camera target, Shader replacement) { if(target.targetTexture) { Debug.LogError("Didn't expect existing render texture: " + target.name); RenderTexture.ReleaseTemporary(target.targetTexture); target.targetTexture = null; } // Start by copying everything from src, but then override quite a few things. target.CopyFrom(source); var pr = source.pixelRect; var rt = target.targetTexture = RenderTexture.GetTemporary( Mathf.RoundToInt(pr.width), Mathf.RoundToInt(pr.height), Application.isPlaying ? 24 : 16, // this avoids a bug that corrupts scene view depth RenderTextureFormat.ARGB2101010 ); target.renderingPath = RenderingPath.Forward; target.depthTextureMode = DepthTextureMode.None; target.clearFlags = CameraClearFlags.SolidColor; target.backgroundColor = Color.white; target.useOcclusionCulling = false; target.cullingMask = cullingMask; target.farClipPlane = maxDistance + 5f; target.RenderWithShader(replacement, "Special"); return rt; }
private void RenderReflectionFor(Camera cam, Camera reflectCamera) { if(!reflectCamera) return; SaneCameraSettings(reflectCamera); reflectCamera.backgroundColor = clearColor; GL.SetRevertBackfacing(true); Transform reflectiveSurface = reflectiveSurfaceHeight; Vector3 eulerA = cam.transform.eulerAngles; reflectCamera.transform.eulerAngles = new Vector3(-eulerA.x, eulerA.y, eulerA.z); reflectCamera.transform.position = cam.transform.position; Vector3 pos = reflectiveSurface.transform.position; pos.y = reflectiveSurface.position.y; Vector3 normal = reflectiveSurface.transform.up; float d = -Vector3.Dot(normal, pos) - clipPlaneOffset; Vector4 reflectionPlane = new Vector4(normal.x, normal.y, normal.z, d); Matrix4x4 reflection = Matrix4x4.zero; reflection = CalculateReflectionMatrix(reflection, reflectionPlane); oldpos = cam.transform.position; Vector3 newpos = reflection.MultiplyPoint (oldpos); reflectCamera.worldToCameraMatrix = cam.worldToCameraMatrix * reflection; Vector4 clipPlane = CameraSpacePlane(reflectCamera, pos, normal, 1.0f); Matrix4x4 projection = cam.projectionMatrix; projection = CalculateObliqueMatrix(projection, clipPlane); reflectCamera.projectionMatrix = projection; reflectCamera.transform.position = newpos; Vector3 euler = cam.transform.eulerAngles; reflectCamera.transform.eulerAngles = new Vector3(-euler.x, euler.y, euler.z); reflectCamera.RenderWithShader (replacementShader, "Reflection"); GL.SetRevertBackfacing(false); }