帮助理解像素化效果

发布于 2024-11-04 14:06:08 字数 1877 浏览 0 评论 0原文

我是 HLSL 新手,我正在尝试理解像素化样本。然而,我还没有找到关于几个操作是如何进行的参考。这是着色器示例:

//--------------------------------------------------------------------------------------
// 
// WPF ShaderEffect HLSL -- PixelateEffect
//
//--------------------------------------------------------------------------------------

//-----------------------------------------------------------------------------------------
// Shader constant register mappings (scalars - float, double, Point, Color, Point3D, etc.)
//-----------------------------------------------------------------------------------------

float HorizontalPixelCounts : register(C0);
float VerticalPixelCounts : register(C1);

//--------------------------------------------------------------------------------------
// Sampler Inputs (Brushes, including ImplicitInput)
//--------------------------------------------------------------------------------------

sampler2D implicitInputSampler : register(S0);


//--------------------------------------------------------------------------------------
// Pixel Shader
//--------------------------------------------------------------------------------------

float4 main(float2 uv : TEXCOORD) : COLOR
{
  float2 brickCounts = { HorizontalPixelCounts, VerticalPixelCounts };
  float2 brickSize = 1.0 / brickCounts;

  // Offset every other row of bricks
  float2 offsetuv = uv;
  bool oddRow = floor(offsetuv.y / brickSize.y) % 2.0 >= 1.0;
  if (oddRow)
  {
      offsetuv.x += brickSize.x / 2.0;
  }

  float2 brickNum = floor(offsetuv / brickSize);
  float2 centerOfBrick = brickNum * brickSize + brickSize / 2;
  float4 color = tex2D(implicitInputSampler, centerOfBrick);

  return color;
}

我无法理解正在发生的计算:

float2 brickNum = floor(offsetuv / brickSize);

我不知道如何计算两个向量之间的除法,而且我也不知道如何计算向量。 (我假设两个 float2 相除返回一个 float2)。

有什么想法吗?

I'm new a HLSL and I'm trying to understand a pixelate sample. However, I haven't been able to find a reference about how a couple of operations are. Here is the shader example:

//--------------------------------------------------------------------------------------
// 
// WPF ShaderEffect HLSL -- PixelateEffect
//
//--------------------------------------------------------------------------------------

//-----------------------------------------------------------------------------------------
// Shader constant register mappings (scalars - float, double, Point, Color, Point3D, etc.)
//-----------------------------------------------------------------------------------------

float HorizontalPixelCounts : register(C0);
float VerticalPixelCounts : register(C1);

//--------------------------------------------------------------------------------------
// Sampler Inputs (Brushes, including ImplicitInput)
//--------------------------------------------------------------------------------------

sampler2D implicitInputSampler : register(S0);


//--------------------------------------------------------------------------------------
// Pixel Shader
//--------------------------------------------------------------------------------------

float4 main(float2 uv : TEXCOORD) : COLOR
{
  float2 brickCounts = { HorizontalPixelCounts, VerticalPixelCounts };
  float2 brickSize = 1.0 / brickCounts;

  // Offset every other row of bricks
  float2 offsetuv = uv;
  bool oddRow = floor(offsetuv.y / brickSize.y) % 2.0 >= 1.0;
  if (oddRow)
  {
      offsetuv.x += brickSize.x / 2.0;
  }

  float2 brickNum = floor(offsetuv / brickSize);
  float2 centerOfBrick = brickNum * brickSize + brickSize / 2;
  float4 color = tex2D(implicitInputSampler, centerOfBrick);

  return color;
}

I haven't been able to understand what computation is happening in:

float2 brickNum = floor(offsetuv / brickSize);

I'm not sure what how to compute the division between the two vectors, and also I don't know how to compute the floor of a vector. (I'm assuming that division of two float2 returns a float2).

Any idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

海夕 2024-11-11 14:06:08

HLSL 运算符和函数通常与具有 x 和 y 的 float2 等结构一起使用。

地板内部的除法返回一个 float2,其中 xyx 除以 x 的结果代码>x和yy。 Floor 将返回一个 float2,其中结果的 xyx 的下限值,输入的y(除法的结果)。

float3和其他类似结构也是如此。

HLSL operators and functions often work with structures like float2 which has an x and y.

The division inside the floor returns a float2 where the x and y are the result of dividing the x with x and y with y. And floor will return a float2 where the x and y of the result are the floored value of the x and y of the input (the result of the division).

The same is true for float3 and other similar structures.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文