c# - 仅在特定高度显示着色器
问题描述
我按照草教程https://www.youtube.com/watch?v=cHe7N42zE1k进行操作,最后我将着色器拖放到网格上并显示草。我希望草只在某个高度开始显示。
在上图中,您可以看到通过这种方法将草置于水下。那么你能根据高度决定从哪里开始着色器吗?
解决方案
在几何着色器(Grass.shader)中,它一直在发射刀片:
for (int i = 0; i < BLADE_SEGMENTS; i++)
{
float t = i / (float)BLADE_SEGMENTS;
float segmentHeight = height * t;
float segmentWidth = width * (1 - t);
float segmentForward = pow(t, _BladeCurve) * forward;
// Select the facing-only transformation matrix for the root of the blade.
float3x3 transformMatrix = i == 0 ? transformationMatrixFacing : transformationMatrix;
triStream.Append(GenerateGrassVertex(pos, segmentWidth, segmentHeight, segmentForward, float2(0, t), transformMatrix));
triStream.Append(GenerateGrassVertex(pos, -segmentWidth, segmentHeight, segmentForward, float2(1, t), transformMatrix));
}
// Add the final vertex as the tip.
triStream.Append(GenerateGrassVertex(pos, 0, height, forward, float2(0.5, 1), transformationMatrix));
您可以在此处添加一个条件来告诉您的 GS 在位置低于某个阈值时不要发出。
if (pos.y > minHeightThreshold)
{
for (int i = 0; i < BLADE_SEGMENTS; i++)
{
float t = i / (float)BLADE_SEGMENTS;
float segmentHeight = height * t;
float segmentWidth = width * (1 - t);
float segmentForward = pow(t, _BladeCurve) * forward;
// Select the facing-only transformation matrix for the root of the blade.
float3x3 transformMatrix = i == 0 ? transformationMatrixFacing : transformationMatrix;
triStream.Append(GenerateGrassVertex(pos, segmentWidth, segmentHeight, segmentForward, float2(0, t), transformMatrix));
triStream.Append(GenerateGrassVertex(pos, -segmentWidth, segmentHeight, segmentForward, float2(1, t), transformMatrix));
}
// Add the final vertex as the tip.
triStream.Append(GenerateGrassVertex(pos, 0, height, forward, float2(0.5, 1), transformationMatrix));
}
推荐阅读
- printing - Ghostscript 打印驱动程序强制 cmyk 而不是 rgb?
- python - 这个 python wrapper() 函数是如何工作的?
- git - 使用 GitHub 用户推送到 Github,而不是添加一些名称
- regression - R中的混合数据采样(midas_r)
- typescript - Npm install 在 React-Native 中给出错误
- postgresql - 如何杀死他们的进程不再存在的查询
- python - Python拆分第一个“中间”和最后一个单词
- android - 线性布局在 Android Studio 4.1 中不可点击
- marklogic - 如何在 marklogic 中获取 marklogic 数据库备份文件的大小?
- c++ - 了解单线程中 C++ 原子的内存排序