方案: 本篇主要介绍Texture方案:使用安卓系统封装的camera2+GLSurefaceView,采集到OES纹理,使用FBO复制成Texture2D纹理离屏渲染,将纹理ID交给TRTCSDK编码传输 :采样器 采集 aCoord的像素 //赋值给 gl_FragColor 就可以了 gl_FragColor = texture2D(vTexture,aCoord); } 再实例化CameraFilter float; varying vec2 aCoord; uniform sampler2D vTexture; void main(){ gl_FragColor=texture2D 比如美颜操作、水印操作等,都需要处理纹理,将处理之后的Texture2D纹理渲染出来。 image.png 注意,目前TRTCSDK,传输纹理格式,仅支持Texture2D格式,不支持OES格式,而android系统carmera2采集的纹理格式,是OES格式的。
frame.height = 720; frame.timestamp = 0; TRTCCloud.sendCustomVideoData(frame); 三、Texture2D 方案: 本篇主要介绍Texture方案:使用安卓系统封装的camera2+GLSurefaceView,采集到OES纹理,使用FBO复制成Texture2D纹理离屏渲染,将纹理ID交给TRTCSDK编码传输 float; varying vec2 aCoord; uniform sampler2D vTexture; void main(){ gl_FragColor=texture2D 比如美颜操作、水印操作等,都需要处理纹理,将处理之后的Texture2D纹理渲染出来。 注意,目前TRTCSDK,传输纹理格式,仅支持Texture2D格式,不支持OES格式,而android系统carmera2采集的纹理格式,是OES格式的。
frame.height = 720; frame.timestamp = 0; TRTCCloud.sendCustomVideoData(frame); 三、Texture2D 方案: 本篇主要介绍Texture方案:使用安卓系统封装的camera2+GLSurefaceView,采集到OES纹理,使用FBO复制成Texture2D纹理离屏渲染,将纹理ID交给TRTCSDK编码传输 float; varying vec2 aCoord; uniform sampler2D vTexture; void main(){ gl_FragColor=texture2D 比如美颜操作、水印操作等,都需要处理纹理,将处理之后的Texture2D纹理渲染出来。 注意,目前TRTCSDK,传输纹理格式,仅支持Texture2D格式,不支持OES格式,而android系统carmera2采集的纹理格式,是OES格式的。
Texture2D与Sprite互转
//转化后大小跟屏幕一样大
Sprite prite = Sprite.Create(要转换的Texture2D,
new Rect(0 Texture和Texture2D转化
1️⃣ Texture转Texture2D
a、编辑器模式下
///
cloud1Texture; Texture2D cloud2Texture; Texture2D sunTexture; Texture2D moonTexture; Texture2D groundTexture ; Texture2D tankTexture; Texture2D alienTexture; Texture2D badguy_blue; Texture2D badguy_red; Texture2D badguy_green; Texture2D badguy_orange; Texture2D mountainsTexture; Texture2D hillsTexture; Texture2D <Texture2D>(“moon”); groundTexture = ScreenManager.Game.Content.Load<Texture2D>(“ground”); <Texture2D>(“badguy_blue”); badguy_red = ScreenManager.Game.Content.Load<Texture2D>(“badguy_red”
解决Texture2D提示压缩格式问题,无法转byte[] public static Texture2D DeCompress(Texture2D source) { RenderTexture */ public static Texture2D ResizeTexture(Texture2D source, int newWidth, int newHeight) { FilterMode ConvertTexture(Texture2D orgText, int width, int height) { Texture2D newTex = new Texture2D(width size. */ public static Texture2D CutTexture(Texture2D source, int cutWidth, int cutHeight, int cutOffX Texture2D 90度旋转 public static Texture2D RotateTexture(Texture2D orgTex, bool rotLeft) { FilterMode
).r; lowp float topLeftIntensity = texture2D(inputImageTexture, topLeftTextureCoordinate).r; lowp float bottomRightIntensity = texture2D(inputImageTexture, bottomRightTextureCoordinate).r; = texture2D(inputImageTexture, rightTextureCoordinate).r; lowp float bottomIntensity = texture2D (inputImageTexture, textureCoordinate).r; float bottomLeftIntensity = texture2D(inputImageTexture = texture2D(inputImageTexture, leftTextureCoordinate).r; float rightIntensity = texture2D(inputImageTexture
{ public: texture2d() { gpu_texture = texture_create(); } ~texture2d { public: texture2d() { rhi::texture_create(this); } ~texture2d 第三种方案和第二种方案有一个通病,就是一个texture2d资源同时需要至少两个对象来表示,render层的texture2d和vulkan层的gpu_texture2d, 这会造成内存碎片问题。 伪码如下: //-----render/texture2d.h namespace render { class texture2d { pubilc: static texture2d *create(int width, int height); static void destroy(texture2d *tex); protected: texture2d
(inputImageTexture, textureCoordinate).rgb; mediump vec3 leftTextureColor = texture2D(inputImageTexture ).rgb; mediump vec3 topTextureColor = texture2D(inputImageTexture, topTextureCoordinate).rgb; mediump vec3 bottomTextureColor = texture2D(inputImageTexture, bottomTextureCoordinate).rgb; gl_FragColor ).rgb; vec3 rightTextureColor = texture2D(inputImageTexture, rightTextureCoordinate).rgb; vec3 topTextureColor = texture2D(inputImageTexture, topTextureCoordinate).rgb; vec3 bottomTextureColor = texture2D(inputImageTexture
]).rgb * 0.05; sum += texture2D(inputImageTexture, blurCoordinates[1]).rgb * 0.09; sum += texture2D [3]).rgb * 0.15; sum += texture2D(inputImageTexture, blurCoordinates[4]).rgb * 0.18; sum += texture2D [6]).rgb * 0.12; sum += texture2D(inputImageTexture, blurCoordinates[7]).rgb * 0.09; sum += texture2D [1]).rgb * 0.09; sum += texture2D(inputImageTexture, blurCoordinates[2]).rgb * 0.12; sum += texture2D [4]).rgb * 0.18; sum += texture2D(inputImageTexture, blurCoordinates[5]).rgb * 0.15; sum += texture2D
(inputImageTexture, textureCoordinate); lowp float redCurveValue = texture2D(toneCurveTexture, vec2 (textureColor.r, 0.0)).r; lowp float greenCurveValue = texture2D(toneCurveTexture, vec2(textureColor.g , 0.0)).g; lowp float blueCurveValue = texture2D(toneCurveTexture, vec2(textureColor.b, 0.0)).b; , 0.0)).r; float greenCurveValue = texture2D(toneCurveTexture, vec2(textureColor.g, 0.0)).g; float blueCurveValue = texture2D(toneCurveTexture, vec2(textureColor.b, 0.0)).b; gl_FragColor =
(s_textureY, uv).r; u = texture2D(s_textureU, uv).r; v = texture2D(s_textureV, uv).r; u = float u_offset; uniform vec2 texSize; vec4 YuvToRgb(vec2 uv) { float y, u, v, r, g, b; y = texture2D (s_textureY, uv).r; u = texture2D(s_textureU, uv).r; v = texture2D(s_textureV, uv).r; u = (s_textureY, uv).r; u = texture2D(s_textureU, uv).r; v = texture2D(s_textureV, uv).r; u = (s_textureY, uv).r; u = texture2D(s_textureU, uv).r; v = texture2D(s_textureV, uv).r; u =
(s_textureY, uv).r; u = texture2D(s_textureU, uv).r; v = texture2D(s_textureV, uv).r; u = float u_offset; uniform vec2 texSize; vec4 YuvToRgb(vec2 uv) { float y, u, v, r, g, b; y = texture2D (s_textureY, uv).r; u = texture2D(s_textureU, uv).r; v = texture2D(s_textureV, uv).r; u = (s_textureY, uv).r; u = texture2D(s_textureU, uv).r; v = texture2D(s_textureV, uv).r; u = (s_textureY, uv).r; u = texture2D(s_textureU, uv).r; v = texture2D(s_textureV, uv).r; u =
Material m_material; public GameObject m_Cube; public WebCamTexture cameraTexture; Texture2D void Start() { m_material = Slice.GetComponent<MeshRenderer>().material; rt = new Texture2D (mPreviewWidth, mPreviewHeight, TextureFormat.RGB565, false); temp = new Texture2D(mPreviewWidth new Size(); Point center = new Point(); private Mat DetectFace(CascadeClassifier cascade, Texture2D temp; Texture2D GetTexture2D(WebCamTexture wct) { temp.SetPixels(wct.GetPixels());
System.Collections; using System.Collections.Generic; class LowMemoryTrigger : MonoBehaviour { List<Texture2D > _textures; private void Start() { _textures = new List<Texture2D>(); Application.lowMemory void Update() { // allocate textures until we run out of memory _textures.Add(new Texture2D private void OnLowMemory() { // release all cached textures _textures = new List<Texture2D
varying highp vec2 lowerRightInputTextureCoordinate; void main() { float upperLeftIntensity = texture2D (inputImageTexture, upperLeftInputTextureCoordinate).r; float upperRightIntensity = texture2D(inputImageTexture ).r; float lowerRightIntensity = texture2D(inputImageTexture, lowerRightInputTextureCoordinate). (inputImageTexture, upperLeftInputTextureCoordinate).r; float upperRightIntensity = texture2D(inputImageTexture ).r; float lowerRightIntensity = texture2D(inputImageTexture, lowerRightInputTextureCoordinate).
).r; float bottomRightIntensity = texture2D(inputImageTexture, bottomRightTextureCoordinate).r; float leftIntensity = texture2D(inputImageTexture, leftTextureCoordinate).r; float rightIntensity = texture2D(inputImageTexture, rightTextureCoordinate).r; float bottomIntensity = texture2D(inputImageTexture , bottomTextureCoordinate).r; float topIntensity = texture2D(inputImageTexture, topTextureCoordinate ).rgb; mediump vec3 topTextureColor = texture2D(inputImageTexture, topTextureCoordinate).rgb;
varying highp vec2 lowerRightInputTextureCoordinate; void main() { highp vec4 upperLeftColor = texture2D (inputImageTexture, upperLeftInputTextureCoordinate); highp vec4 upperRightColor = texture2D(inputImageTexture ); highp vec4 lowerRightColor = texture2D(inputImageTexture, lowerRightInputTextureCoordinate); (inputImageTexture, upperLeftInputTextureCoordinate); vec4 upperRightColor = texture2D(inputImageTexture ); vec4 lowerRightColor = texture2D(inputImageTexture, lowerRightInputTextureCoordinate);
varying highp vec2 lowerRightInputTextureCoordinate; void main() { highp vec4 upperLeftColor = texture2D (inputImageTexture, upperLeftInputTextureCoordinate); highp vec4 upperRightColor = texture2D(inputImageTexture ); highp vec4 lowerRightColor = texture2D(inputImageTexture, lowerRightInputTextureCoordinate); (inputImageTexture, upperLeftInputTextureCoordinate); vec4 upperRightColor = texture2D(inputImageTexture ); vec4 lowerRightColor = texture2D(inputImageTexture, lowerRightInputTextureCoordinate);
Selection.activeGameObject.GetComponent<Image>(); //Image中Sprite不为空则获取其texture Texture2D texture2D = image.sprite ? RawImage rawImage = Selection.activeGameObject.AddComponent<RawImage>(); rawImage.texture = texture2D Selection.activeGameObject.GetComponent<Image>(); //Image中Sprite不为空则获取其texture Texture2D texture2D = image.sprite ?