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

discuz 手机网站模板别墅装修公司排名前十强

discuz 手机网站模板,别墅装修公司排名前十强,深圳建设网站需要多少钱,网站备案账户名如何查询试了一下在unity中使用raytrace方式实现体积光, 运行效果如下 raytrace开销较大,采样加到200几乎卡得跑不动了 首先在光源处拍摄场景(unity对mainlight做了这个处理,并且是级联可设置) 基本原理是在全屏路径下,根据场景深度,还原出世界坐标 根据世界坐标判断是哪个裁切球 (…

试了一下在unity中使用raytrace方式实现体积光,

运行效果如下

raytrace开销较大,采样加到200几乎卡得跑不动了

首先在光源处拍摄场景(unity对mainlight做了这个处理,并且是级联可设置)

基本原理是在全屏路径下,根据场景深度,还原出世界坐标

根据世界坐标判断是哪个裁切球

(如果不是级联阴影,比如spotlight就不需要这个操作)

然后将世界坐标变换到光源观察坐标light_view_pos

再根据投影矩阵对应到光源纹理的深度纹理

比较当前点在光源摄像机的深度,判断是不是处于遮挡(即阴影)

原理和纹理阴影的处理方式类似

附shader代码如下

Shader "lsc/RaytraceShader"
{Properties{_MainTex ("Texture", 2D) = "white" {}_raytrace_step_count("rayrace step count", Int) = 5_scale("scale", float) = 1.0}SubShader{// No culling or depthCull Off ZWrite Off ZTest AlwaysPass{HLSLPROGRAM#pragma vertex vert#pragma fragment frag#pragma multi_compile _ _MAIN_LIGHT_SHADOWS#pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE#pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS#pragma multi_compile_fragment _ _SHADOWS_SOFT#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"struct appdata{float4 vertex : POSITION;float2 uv : TEXCOORD0;};struct v2f{float2 uv : TEXCOORD0;float4 vertex : SV_POSITION;float4 screen_pos : TEXCOORD1;};float4x4 _mtx_view_inv;float4x4 _mtx_proj_inv;TEXTURE2D_X_FLOAT(_CameraDepthTexture);SAMPLER(sampler_CameraDepthTexture);v2f vert (appdata v){v2f o;VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz);o.vertex = vertexInput.positionCS;o.screen_pos = ComputeScreenPos(o.vertex);o.uv = v.uv;return o;}sampler2D _MainTex;int _raytrace_step_count;float _scale;float4 cal_world_pos_by_dep(float ndc_dep, float2 screen_space, out float4 view_pos){// 取出非线性深度与视深度float linearDepthZ = LinearEyeDepth(ndc_dep, _ZBufferParams);// 屏幕转ndcfloat4 ndc_pos;ndc_pos.xy = screen_space * 2.0 - 1.0;ndc_pos.zw = float2(ndc_dep, 1);// 添加齐次因子ndc_pos = ndc_pos * linearDepthZ;// 转成观察与世界坐标view_pos = mul(_mtx_proj_inv, ndc_pos);float4 world_pos = mul(_mtx_view_inv, float4(view_pos.xyz, 1));return world_pos;}float4 frag (v2f i) : SV_Target{float4 col = tex2D(_MainTex, i.uv);// 插值后的屏幕坐标去除齐次因子float2 screen_space = i.screen_pos.xy / i.screen_pos.w;// 取出非线性深度float org_depth = SAMPLE_TEXTURE2D_X(_CameraDepthTexture, sampler_CameraDepthTexture, screen_space).x;// 计算世界坐标float4 view_pos;float4 world_pos = cal_world_pos_by_dep(org_depth, screen_space, view_pos);float3 cam_wpos = GetCameraPositionWS();float3 v_step = (world_pos - cam_wpos) / _raytrace_step_count;float3 rt_start = cam_wpos;float shadow_atten = 0;UNITY_LOOPfor (int i = 0; i < _raytrace_step_count; i++)//循环,超级低效{float4 shadow_coord = TransformWorldToShadowCoord(rt_start);rt_start += v_step;Light mainLight = GetMainLight(shadow_coord);//这样产生了级联阴影采样shadow_atten += mainLight.shadowAttenuation;}shadow_atten = (shadow_atten / _raytrace_step_count) * _scale;col.rgb = col.rgb * shadow_atten;return col;}ENDHLSL}}
}

对应的urp管线cs代码

using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
using System;public class RayTraceFogRenderPassFeature : ScriptableRendererFeature
{class CustomRenderPass : ScriptableRenderPass{public Material raytrace_material_;public RenderTargetIdentifier render_target_color_;public RenderTargetHandle temp_render_target_;public int raytrace_count_ = 5;public float scale_ = 1.0f;// This method is called before executing the render pass.// It can be used to configure render targets and their clear state. Also to create temporary render target textures.// When empty this render pass will render to the active camera render target.// You should never call CommandBuffer.SetRenderTarget. Instead call <c>ConfigureTarget</c> and <c>ConfigureClear</c>.// The render pipeline will ensure target setup and clearing happens in a performant manner.public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData){}// Here you can implement the rendering logic.// Use <c>ScriptableRenderContext</c> to issue drawing commands or execute command buffers// https://docs.unity3d.com/ScriptReference/Rendering.ScriptableRenderContext.html// You don't have to call ScriptableRenderContext.submit, the render pipeline will call it at specific points in the pipeline.public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData){if (!raytrace_material_)return;raytrace_material_.SetInt("_raytrace_step_count", raytrace_count_);raytrace_material_.SetFloat("_scale", scale_);{Camera cam = renderingData.cameraData.camera;var mtx_view_inv = cam.worldToCameraMatrix.inverse;var mtx_proj_inv = cam.projectionMatrix.inverse;raytrace_material_.SetMatrix("_mtx_view_inv", mtx_view_inv);raytrace_material_.SetMatrix("_mtx_proj_inv", mtx_proj_inv);}const string CommandBufferTag = "raytrace fog Pass";var cmd = CommandBufferPool.Get(CommandBufferTag);RenderTextureDescriptor opaqueDesc = renderingData.cameraData.cameraTargetDescriptor;opaqueDesc.depthBufferBits = 0;cmd.GetTemporaryRT(temp_render_target_.id, opaqueDesc);// 通过材质,将计算结果存入临时缓冲区cmd.Blit(render_target_color_, temp_render_target_.Identifier(), raytrace_material_);// 再从临时缓冲区存入主纹理cmd.Blit(temp_render_target_.Identifier(), render_target_color_);// 执行命令缓冲区context.ExecuteCommandBuffer(cmd);// 释放命令缓存CommandBufferPool.Release(cmd);// 释放临时RTcmd.ReleaseTemporaryRT(temp_render_target_.id);}// Cleanup any allocated resources that were created during the execution of this render pass.public override void OnCameraCleanup(CommandBuffer cmd){}}CustomRenderPass m_ScriptablePass;public Material raytrace_material_;public int raytrace_count_ = 5;public float scale_ = 1.0f;/// <inheritdoc/>public override void Create(){m_ScriptablePass = new CustomRenderPass();// Configures where the render pass should be injected.m_ScriptablePass.renderPassEvent = RenderPassEvent.AfterRenderingOpaques;}// Here you can inject one or multiple render passes in the renderer.// This method is called when setting up the renderer once per-camera.public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData){m_ScriptablePass.render_target_color_ = renderer.cameraColorTarget;m_ScriptablePass.raytrace_material_ = raytrace_material_;m_ScriptablePass.raytrace_count_ = raytrace_count_;m_ScriptablePass.scale_ = scale_;renderer.EnqueuePass(m_ScriptablePass);}
}

http://www.yayakq.cn/news/226527/

相关文章:

  • 建设机械网站案例分析seo优化深圳
  • 中国专业的网站建设站长网站优点
  • 网站建设的原则有哪些内容十佳工业设计公司
  • 霍邱网站设计化妆品网站设计论文
  • 宁波高端品牌网站建设硬件开发和嵌入式的区别
  • 东莞做网站建设公司网站如何做定级备案
  • 一个企业网站文章多少适合优化关键词排名哪家好
  • 编程网站哪个好性男女做视频网站
  • 贵州建设项目门户网站合肥seo排名公司
  • 360网站推广官网硅钙钾镁肥在局网站 作风建设
  • iis5 新建网站网站开发不让搜索引擎
  • c2c网站有哪些平台做网站放广告收益
  • 网站建设服务合同模板下载产品设计去哪里找工作
  • 小程序appsecret在哪里看seo优化几个关键词
  • 网站开发干啥的百度指数对比
  • 交三百能在网站上找兼职做的南宁市网站建设
  • 网站建设工作量统计表ppt中网站布局图怎么做
  • wordpress 站点身份国外空间设计网站
  • 做网站面临的困难泰钢材企业网站源码
  • 网站建设创业计划书模板范文word可以制作网页吗
  • 做网站创业风险分析做娱乐网站少10个页面
  • 用python开发网站做网站不推广有效果吗
  • 行业公司网站建设企业管理系统有
  • 做分析报表的网站网站备案信息批量查询
  • 免费素材网站mixkit怎么用wordpress找东西
  • 松山湖做网站征婚网站 女 做茶叶生意
  • 开发网站赚钱项目分享平台
  • 公司做网站宣传怎么做知名市场调研公司
  • 做网站推广优化哪家好双井网站建设
  • 个人商城网站怎么做服务好的网站建设