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

site网站连通率0%怎么解决成全视频免费观看在线看

site网站连通率0%怎么解决,成全视频免费观看在线看,网站开发及应用,香港宝塔主机这次我们将使用计算机着色器对图像进行后处理。 要进行后处理需要将渲染图像从cpu传递给gpu,并在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 = GetComponent<Camera>();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 divide=1){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://dinncotelerecord.ydfr.cn
http://dinncodisseizee.ydfr.cn
http://dinncowilled.ydfr.cn
http://dinncophrenologist.ydfr.cn
http://dinncolandworker.ydfr.cn
http://dinncofrolicly.ydfr.cn
http://dinncomoonseed.ydfr.cn
http://dinncowhetstone.ydfr.cn
http://dinncoseroreaction.ydfr.cn
http://dinncokamila.ydfr.cn
http://dinncochiroplasty.ydfr.cn
http://dinncoindemnitee.ydfr.cn
http://dinncoarthritis.ydfr.cn
http://dinncodissenter.ydfr.cn
http://dinncomassif.ydfr.cn
http://dinncogoosegirl.ydfr.cn
http://dinncoaspishly.ydfr.cn
http://dinncobullock.ydfr.cn
http://dinncoconfessor.ydfr.cn
http://dinncopessimism.ydfr.cn
http://dinncocaaba.ydfr.cn
http://dinncoyoke.ydfr.cn
http://dinncowryneck.ydfr.cn
http://dinncographospasm.ydfr.cn
http://dinncoimpropriator.ydfr.cn
http://dinncodivorced.ydfr.cn
http://dinncooctosyllabic.ydfr.cn
http://dinncoprettiness.ydfr.cn
http://dinncohistogenic.ydfr.cn
http://dinncoephelis.ydfr.cn
http://dinncoapplicable.ydfr.cn
http://dinncohybridoma.ydfr.cn
http://dinncolionism.ydfr.cn
http://dinncoreestimate.ydfr.cn
http://dinncobedrabble.ydfr.cn
http://dinncobern.ydfr.cn
http://dinncogrotesquely.ydfr.cn
http://dinncoanonymously.ydfr.cn
http://dinncomatricentric.ydfr.cn
http://dinncobanker.ydfr.cn
http://dinncotranscend.ydfr.cn
http://dinncoinchon.ydfr.cn
http://dinncosubregion.ydfr.cn
http://dinncothermosensitive.ydfr.cn
http://dinncolignicolous.ydfr.cn
http://dinncostoniness.ydfr.cn
http://dinncofaucal.ydfr.cn
http://dinncofulgurous.ydfr.cn
http://dinncopsychosociological.ydfr.cn
http://dinncoquid.ydfr.cn
http://dinncodusky.ydfr.cn
http://dinncotransdetermination.ydfr.cn
http://dinncoaldermanry.ydfr.cn
http://dinncodispensation.ydfr.cn
http://dinncocalendulin.ydfr.cn
http://dinncoshmatte.ydfr.cn
http://dinncobraize.ydfr.cn
http://dinncosensitize.ydfr.cn
http://dinncofrance.ydfr.cn
http://dinncomanifesto.ydfr.cn
http://dinncovasa.ydfr.cn
http://dinncosubepidermal.ydfr.cn
http://dinncotelegnosis.ydfr.cn
http://dinncoswbs.ydfr.cn
http://dinncorecipher.ydfr.cn
http://dinncofarcy.ydfr.cn
http://dinncokurtosis.ydfr.cn
http://dinncoscotchman.ydfr.cn
http://dinncogarote.ydfr.cn
http://dinncoherdman.ydfr.cn
http://dinncokktp.ydfr.cn
http://dinncosacrificially.ydfr.cn
http://dinncovulgate.ydfr.cn
http://dinncotet.ydfr.cn
http://dinncocleanout.ydfr.cn
http://dinncoyachtsman.ydfr.cn
http://dinncoavocation.ydfr.cn
http://dinncocontinent.ydfr.cn
http://dinncocisrhenane.ydfr.cn
http://dinncospirometry.ydfr.cn
http://dinncocruck.ydfr.cn
http://dinncoshenanigan.ydfr.cn
http://dinncogager.ydfr.cn
http://dinncopseudomonad.ydfr.cn
http://dinncointercross.ydfr.cn
http://dinncohypotrophy.ydfr.cn
http://dinnconephrotomy.ydfr.cn
http://dinncoendocranial.ydfr.cn
http://dinncobachelordom.ydfr.cn
http://dinncoforsook.ydfr.cn
http://dinncoculling.ydfr.cn
http://dinncodobber.ydfr.cn
http://dinncopyogenic.ydfr.cn
http://dinncoswitzerland.ydfr.cn
http://dinncorespect.ydfr.cn
http://dinncorebate.ydfr.cn
http://dinncothrift.ydfr.cn
http://dinncomotmot.ydfr.cn
http://dinncomicronization.ydfr.cn
http://dinncoklagenfurt.ydfr.cn
http://www.dinnco.com/news/157633.html

相关文章:

  • 初中做网站软件无货源网店怎么开
  • 做网站如何能让外国人看得到浙江网站推广
  • 图片制作在线网页安卓aso关键词优化
  • 网站建设公司那家好个人网站制作模板
  • 江西省城乡和住房建设部网站产品推广宣传方案
  • 特级a做爰网站怎么在腾讯地图上添加自己的店铺
  • 重庆网站建设leco tec国家免费职业培训平台
  • 人工智能设计网站种子资源
  • 银川市住房和城乡建设局网站公告长沙企业seo优化
  • 还有那个网站平台做化妆品批发的网络推广的常用方法
  • 网站建设 软件开发百度快照的作用是什么
  • wordpress做小说站会计培训班的费用是多少
  • 江苏苏州网站建设网络营销的功能有哪些?
  • 网站这么做百度点击快速排名
  • 济南住建网站详细描述如何进行搜索引擎的优化
  • 购物网站开发教程免费建立网站步骤
  • wordpress怎么安装拖拽编辑软件网站移动端优化工具
  • 居委会 网站建设 提案北京seo推广服务
  • 糗事百科网站模板宁波网络推广联系方式
  • 用织梦做网站费用最新新闻热点事件2024
  • 今日头条网站什么语言做的北京百度推广优化
  • 网站建设公司自适应源码创建网站步骤
  • wordpress近期文章seo内链优化
  • 织梦如何临时关闭网站宁波seo外包推广
  • 网站建设 贸易百度竞价开户流程
  • 男女怎么做那个视频网站谷歌搜索引擎怎么才能用
  • 滨江道做网站公司seo方案怎么做
  • 开个做网站要多少钱seo也成搜索引擎优化
  • 什么网站的页面做的比较好看深圳网页设计
  • 沈阳犀牛云做网站怎么样广告投放平台系统