当前位置: 首页 > news >正文

广州网站建设优化方案深圳品牌网站制作

广州网站建设优化方案,深圳品牌网站制作,wordpress get tags,网站设置英文怎么说这次我们将使用计算机着色器对图像进行后处理。 要进行后处理需要将渲染图像从cpu传递给gpu#xff0c;并在gpu对图像进行处理然后传回cpu。 首先创建一个后处理基类BasePP 首先声明需要用到的属性。 using System.Collections; using System.Collections.Generic; using …这次我们将使用计算机着色器对图像进行后处理。 要进行后处理需要将渲染图像从cpu传递给gpu并在gpu对图像进行处理然后传回cpu。 首先创建一个后处理基类BasePP 首先声明需要用到的属性。 using System.Collections; using System.Collections.Generic; using UnityEngine;[RequireComponent(typeof(Camera))] public class BasePP : MonoBehaviour {public ComputeShader shader null;protected string kernelName CSMain;protected Vector2Int texSize new Vector2Int(0,0);protected Vector2Int groupSize new Vector2Int();protected Camera thisCamera;protected RenderTexture output null;protected RenderTexture renderedSource null;protected int kernelHandle -1;protected bool init false;protected virtual void Init(){if (!SystemInfo.supportsComputeShaders){Debug.LogError(It seems your target Hardware does not support Compute Shaders.);return;}if (!shader){Debug.LogError(No shader);return;}kernelHandle shader.FindKernel(kernelName);thisCamera GetComponentCamera();if (!thisCamera){Debug.LogError(Object has no Camera);return;}CreateTextures();init true;}protected void ClearTexture(ref RenderTexture textureToClear){if (null ! textureToClear){textureToClear.Release();textureToClear null;}}protected virtual void ClearTextures(){ClearTexture(ref output);ClearTexture(ref renderedSource);}protected void CreateTexture(ref RenderTexture textureToMake, int divide1){textureToMake new RenderTexture(texSize.x/divide, texSize.y/divide, 0);textureToMake.enableRandomWrite true;textureToMake.Create();}protected virtual void CreateTextures(){}protected virtual void OnEnable(){Init();}protected virtual void OnDisable(){ClearTextures();init false;}protected virtual void OnDestroy(){ClearTextures();init false;}protected virtual void DispatchWithSource(ref RenderTexture source, ref RenderTexture destination){}protected void CheckResolution(out bool resChange ){resChange false;}protected virtual void OnRenderImage(RenderTexture source, RenderTexture destination){if (!init || shader null){Graphics.Blit(source, destination);}else{CheckResolution(out _);DispatchWithSource(ref source, ref destination);}}}初始化以后就会创建纹理但是这个函数还没有完善。 首先设置纹理的宽度和高度然后获取线程组的x和y的大小这里GetKernelThreadGroupSizes的都三个参数out _表示忽略z 轴的线程组尺寸这是 C# 语言中的一种方式用于表示对某个输出值不感兴趣不需要它的实际值。然后创建两张纹理并传递给shader。 protected virtual void CreateTextures(){texSize.x thisCamera.pixelWidth;//返回摄像机视口的宽度和高度texSize.y thisCamera.pixelHeight;if (shader){uint x, y;shader.GetKernelThreadGroupSizes(kernelHandle, out x, out y,out _);groupSize.x Mathf.CeilToInt((float)texSize.x / (float)x);groupSize.y Mathf.CeilToInt((float)texSize.y / (float)y);}CreateTexture(ref output);CreateTexture(ref renderedSource);shader.SetTexture(kernelHandle, source, renderedSource);shader.SetTexture(kernelHandle, output, output);} 下面就是要获取到渲染的纹理并传递到GPU OnRenderImage(RenderTexture source, RenderTexture destination)这个函数可以获取摄像机渲染后的图像到source并通过对原图像的一系列处理之后设置到destination上。 OnRenderImage 是 Unity 中的一个特殊回调函数用于在摄像机完成渲染之后对图像进行后处理。它是在摄像机渲染过程的最后阶段被自动调用的。你不需要手动调用这个函数而是由 Unity 引擎在渲染管线中自动调用。 protected virtual void OnRenderImage(RenderTexture source, RenderTexture destination){if (!init || shader null){Graphics.Blit(source, destination);}else{CheckResolution(out _);DispatchWithSource(ref source, ref destination);}} 接着我们继续完善checkresolution和dispatchwithsource函数。 如果没有设置texsize那么就执行createtextures函数设置纹理大小 protected void CheckResolution(out bool resChange ){resChange false;if (texSize.x ! thisCamera.pixelWidth || texSize.y ! thisCamera.pixelHeight){resChange true;CreateTextures();}} 首先将源纹理传递到shader然后给shader分配线程组然后将shader处理后的纹理传递到destination protected virtual void DispatchWithSource(ref RenderTexture source, ref RenderTexture destination){Graphics.Blit(source, renderedSource);shader.Dispatch(kernelHandle, groupSize.x, groupSize.y, 1);Graphics.Blit(output, destination);} 接着我们书写一个简单的后处理示例 我们只是在代码中将原图像的颜色乘上一个shade调整图像的亮度 void Highlight(uint3 id : SV_DispatchThreadID) {float4 srcColor source[id.xy];float4 color srcColor*shade;output[id.xy] color; } 效果展示 接着我们想要让角色周围高亮显示但是其它地方仍然是变暗一些。 首先在cpu获取角色的位置并且转换到屏幕坐标然后传递给shader。 protected override void OnRenderImage(RenderTexture source, RenderTexture destination){if (!init || shader null){Graphics.Blit(source, destination);}else{if (trackedObject thisCamera){Vector3 pos thisCamera.WorldToScreenPoint(trackedObject.position);//将世界坐标转换为屏幕坐标center.x pos.x;center.y pos.y;shader.SetVector(center, center);}bool resChange false;CheckResolution(out _);if (resChange) SetProperties();DispatchWithSource(ref source, ref destination);}} 在shader中检测像素是否在角色周围然后根据和角色的距离对颜色进行插值。如果距离大于半径完全是变暗的颜色小于半径就是高亮显示。 float inCircle( float2 pt, float2 center, float radius, float edgeWidth ){float len length(pt - center);return 1.0 - smoothstep(radius-edgeWidth, radius, len); }[numthreads(8, 8, 1)] void Highlight(uint3 id : SV_DispatchThreadID) {float4 srcColor source[id.xy];float4 shadedSrcColor srcColor*shade;float4 highlight inCircle((float2)id.xy,center.xy,radius,edgeWidth);float4 color lerp(shadedSrcColor,srcColor,highlight);output[id.xy] color; } 效果
http://www.dnsts.com.cn/news/33031.html

相关文章:

  • 北京移动端网站百度点击软件找名风
  • 哪个网站科技新闻好在百度备案网站
  • 旅行社网站营销建设英文wordpress变中文
  • 网站安全检测中心广告传媒公司黄页
  • 建设企业网站要多少钱如何增加网站的流量
  • 网站定制开发注意事项做网站的前端是做什么
  • 甘肃住房和城乡建设局网站网站title怎么修改
  • 自助建站信息发布网企业医院做网站的好处
  • 通州区网站建设固定ip做网站路由设置
  • 哪有免费做网站广西网站建设产品介绍
  • 专业做图片制作网站有哪些做免费的视频网站可以赚钱吗
  • 网站特殊字体国外专业做集装箱别墅网站
  • 公司网站可以不买域名吗网站图片设计制作
  • 北京康迪建设监理咨询有限公司网站东莞网络营销十年乐云seo
  • 营销策划的内容包括哪些seo网站推广策略
  • 海报设计论文seo技术培训南阳
  • 网站建设启凡如何建立外卖网站
  • 家教补习中心网站建设网站建设与熊掌号未来的关系
  • 怎么做网站推广方案软件工程专业学校排名
  • 做网站还有价值吗河南郑州最新新闻
  • 企业网站建设制作的域名费用桂林象鼻山的传说
  • 网站主机价格建设安全协会网站
  • 网站制作公司信科网络深圳市建局官网
  • 网站开发公司简介怎么写西宁市网站建设价格
  • 徐州网站建设案例网站快速被百度收录
  • 西安市精神文明建设网站中国十大门户网站
  • 网站如何收费有什么推广网站
  • 动易网站 青春wordpress 美化
  • 做空的网站有哪些代做ppt
  • 旅游网站定位淘宝网络推广怎么做