0
我是新來的HLSL,我正在嘗試瞭解一個像素樣本。但是,我一直無法找到關於幾個操作如何的參考。這裏是着色器例子:幫助理解Pixelate效果
//--------------------------------------------------------------------------------------
//
// 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)。
有什麼想法?