有没有专门做蛋糕的网站,无货源跨境电商怎么开店铺,潍坊网站优化,餐饮网站建设有什么好处因为马上就要进入下一个阶段#xff0c;制作动态编辑体积纹理的模块。
但在这之前#xff0c;要在这一章做最后一些整理。
首先#xff0c;我们完成没完成的部分。其次#xff0c;最后整理一下图表。最后#xff0c;本文附上正在用的贴图
完善Shader
还记得我们之前注…因为马上就要进入下一个阶段制作动态编辑体积纹理的模块。
但在这之前要在这一章做最后一些整理。
首先我们完成没完成的部分。其次最后整理一下图表。最后本文附上正在用的贴图
完善Shader
还记得我们之前注释掉了阶梯纹理修复的部分吗
在第二章第七节中我们已经修复了这个阶梯纹理。
CurPos LocalCamVec * (1 - FinalStepSize);//只留了它然而在第三章对Shader进行大幅修改时我们暂时将其注释掉并未继续处理。现在我们将重新着手修复这个阶梯纹理问题。
希望你还记得修复阶梯纹理的原理是将for循环的一步单独再以一个小步FinalStepSize执行一次。 因此基本上就是将for循环中的内容复制出来在for之后再运行一次。
//创建变量从0开始累加沿相机方向步进过程中的总密度
float accumdens 0;//Shadow部分
//创建变量透射率和光线的能量
float transmittance 1;
float3 lightenergy 0;
//基本和相机方向步进一样但这些都是常量不需要写进for里
Density * StepSize;
LightVector * ShadowStepSize;
ShadowDensity * ShadowStepSize;
//一个对数来计算阈值用来判断光线是否还值得计算
float shadowthresh -log(ShadowThreshold)/ShadowDensity;//使用 MaxSteps 作为最大步数进行循环每次循环执行以下操作
for (int i 0; i MaxSteps; i)
{float cursample PseudoVolumeTexture(Tex, TexSampler, saturate(CurPos), XYFrames, NumFrames).r;// 在当前步进位置进行纹理采样//Shadow部分if(cursample 0.001)//如果采样位置没有密度则跳过{float3 Lpos CurPos;//Lpos将作为光线步进的起始位置float shadowdist 0;//和之前的accumdens一样积累阴影//自阴影for(int s 0; s ShadowSteps; s){Lpos LightVector;//移动步进位置float Lsample PseudoVolumeTexture(Tex, TexSampler, saturate(Lpos), XYFrames, NumFrames).r;//采样//判断是否在框内不是则直接break退出forfloat3 shadowboxtest floor( 0.5 (abs(0.5-Lpos)));//float exitshadowbox shadowboxtest.x shadowboxtest.y shadowboxtest.z;float exitshadowbox dot(shadowboxtest,1);//简短的通道相加if(shadowdist shadowthresh || exitshadowbox 1) break;shadowdist Lsample;//累计}//接收阴影float3 dfpos 2 * (CurPos -0.5) * LocalObjectBoundsMax;//-0.5 * 2得到一个居中的Bounddfpos LWCToFloat(TransformLocalPositionToWorld(Parameters,dfpos)) - CameraPosWS;//将dfpos转换为世界空间需要LWC精度所以在代码里转换减去相机位置float dftracedist 1; //创建四个变量float dfshadow 1;//这是我们最终要的float curdist 0;float DistanceAlongTrace 0;for (int d 0; d DFSSteps; d)//又一次的光线步进{DistanceAlongTrace curdist;//增加距离curdist GetDistanceToNearestSurfaceGlobal(dfpos);//采样全局距离场他和蓝图里DistanceToNearestSurface是相同函数float SphereSize DistanceAlongTrace * LightTangent;//采样距离场软阴影的球形距离dfshadow min( saturate(curdist/SphereSize),dfshadow);//用小于它的结果来更新变量dfpos.xyz LightVectorWS * dftracedist * curdist;//继续移动位置dftracedist * 1.0001;//增加一个很小的因子}//更新样本和光能算法是BeersLaw函数cursample 1 -exp(-cursample * Density);lightenergy exp(-shadowdist * ShadowDensity) * cursample * transmittance * LightColor * dfshadow;//在结果上乘dfshadowtransmittance * 1-cursample;//环境光照部分shadowdist 0;//重置一下阴影距离继续利用它计算光照Lpos CurPos float3(0,0,0.025);//新位置float Lsample PseudoVolumeTexture(Tex, TexSampler, saturate(Lpos), XYFrames, NumFrames).r;//采样shadowdist Lsample;Lpos CurPos float3(0,0,0.05);Lsample PseudoVolumeTexture(Tex, TexSampler, saturate(Lpos), XYFrames, NumFrames).r;//采样shadowdist Lsample;Lpos CurPos float3(0,0,0.15);Lsample PseudoVolumeTexture(Tex, TexSampler, saturate(Lpos), XYFrames, NumFrames).r;//采样shadowdist Lsample;lightenergy exp(-shadowdist * AmbientDensity) *cursample * SkyColor * transmittance;//累计到光}CurPos -LocalCamVec;
}CurPos LocalCamVec * (1 - FinalStepSize);
float cursample PseudoVolumeTexture(Tex, TexSampler, saturate(CurPos), XYFrames, NumFrames).r;//从上面复制过来使用 FinalStepSize 结果再 Step 一次进行阶梯修复if(cursample 0.001){float3 Lpos CurPos;float shadowdist 0;for(int s 0; s ShadowSteps; s){Lpos LightVector;float Lsample PseudoVolumeTexture(Tex, TexSampler, saturate(Lpos), XYFrames, NumFrames).r;float3 shadowboxtest floor( 0.5 (abs(0.5-Lpos)));float exitshadowbox dot(shadowboxtest,1);if(shadowdist shadowthresh || exitshadowbox 1) break;shadowdist Lsample;}float3 dfpos 2 * (CurPos -0.5) * LocalObjectBoundsMax;dfpos LWCToFloat(TransformLocalPositionToWorld(Parameters,dfpos)) - CameraPosWS;float dftracedist 1; float dfshadow 1;float curdist 0;float DistanceAlongTrace 0;for (int d 0; d DFSSteps; d){DistanceAlongTrace curdist;curdist GetDistanceToNearestSurfaceGlobal(dfpos);float SphereSize DistanceAlongTrace * LightTangent;dfshadow min( saturate(curdist/SphereSize),dfshadow);dfpos.xyz LightVectorWS * dftracedist * curdist;dftracedist * 1.0001;}cursample 1 -exp(-cursample * Density);lightenergy exp(-shadowdist * ShadowDensity) * cursample * transmittance * LightColor * dfshadow;transmittance * 1-cursample;shadowdist 0;Lpos CurPos float3(0,0,0.025);float Lsample PseudoVolumeTexture(Tex, TexSampler, saturate(Lpos), XYFrames, NumFrames).r;shadowdist Lsample;Lpos CurPos float3(0,0,0.05);Lsample PseudoVolumeTexture(Tex, TexSampler, saturate(Lpos), XYFrames, NumFrames).r;shadowdist Lsample;Lpos CurPos float3(0,0,0.15);Lsample PseudoVolumeTexture(Tex, TexSampler, saturate(Lpos), XYFrames, NumFrames).r;shadowdist Lsample;lightenergy exp(-shadowdist * AmbientDensity) *cursample * SkyColor * transmittance;}return float4(lightenergy, transmittance);整理图表
老样子我们做整理消除意大利面可以让我们更直观的感受shader中的各种关系 将这一部分RayMarching的参数折叠为RayMarchingParameter 打包环境和常量参数Constant 整理自阴影距离场的变量SelfShadow 打包投影的参数ShadowRayParameter 最后整理一下ShadowRayMarching输入顺序按功能排序 当前Shader 抄抄党注目 模型 长宽高100cm轴居中双面双材质ID的Cube模型 本文附下载 预览贴图 长宽高100cm轴居中双面双材质ID的Cube模型。 本文附下载 材质球
M_VolRayMarching MI_VolRayMarching MI_VolRayMarching_Shadow #mermaid-svg-I9Geg3fLAUJV1dOq {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-I9Geg3fLAUJV1dOq .error-icon{fill:#552222;}#mermaid-svg-I9Geg3fLAUJV1dOq .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-I9Geg3fLAUJV1dOq .edge-thickness-normal{stroke-width:2px;}#mermaid-svg-I9Geg3fLAUJV1dOq .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-I9Geg3fLAUJV1dOq .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-I9Geg3fLAUJV1dOq .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-I9Geg3fLAUJV1dOq .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-I9Geg3fLAUJV1dOq .marker{fill:#333333;stroke:#333333;}#mermaid-svg-I9Geg3fLAUJV1dOq .marker.cross{stroke:#333333;}#mermaid-svg-I9Geg3fLAUJV1dOq svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-I9Geg3fLAUJV1dOq .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-I9Geg3fLAUJV1dOq .cluster-label text{fill:#333;}#mermaid-svg-I9Geg3fLAUJV1dOq .cluster-label span{color:#333;}#mermaid-svg-I9Geg3fLAUJV1dOq .label text,#mermaid-svg-I9Geg3fLAUJV1dOq span{fill:#333;color:#333;}#mermaid-svg-I9Geg3fLAUJV1dOq .node rect,#mermaid-svg-I9Geg3fLAUJV1dOq .node circle,#mermaid-svg-I9Geg3fLAUJV1dOq .node ellipse,#mermaid-svg-I9Geg3fLAUJV1dOq .node polygon,#mermaid-svg-I9Geg3fLAUJV1dOq .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-I9Geg3fLAUJV1dOq .node .label{text-align:center;}#mermaid-svg-I9Geg3fLAUJV1dOq .node.clickable{cursor:pointer;}#mermaid-svg-I9Geg3fLAUJV1dOq .arrowheadPath{fill:#333333;}#mermaid-svg-I9Geg3fLAUJV1dOq .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-I9Geg3fLAUJV1dOq .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-I9Geg3fLAUJV1dOq .edgeLabel{background-color:#e8e8e8;text-align:center;}#mermaid-svg-I9Geg3fLAUJV1dOq .edgeLabel rect{opacity:0.5;background-color:#e8e8e8;fill:#e8e8e8;}#mermaid-svg-I9Geg3fLAUJV1dOq .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-I9Geg3fLAUJV1dOq .cluster text{fill:#333;}#mermaid-svg-I9Geg3fLAUJV1dOq .cluster span{color:#333;}#mermaid-svg-I9Geg3fLAUJV1dOq div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-I9Geg3fLAUJV1dOq :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 父子关系 子实例材质 子实例材质 MI_VolRayMarching M_VolRayMarching MI_VolRayMarching_Shadow M_VolRayMarching
细节 图表 MI_VolRayMarching
父材质为M_VolRayMarching
MI_VolRayMarching_Shadow
父材质为MI_VolRayMarching
细节: