[RenderMonkey] Edge Detection
// Vertex Shader
struct VS_INPUT
{
float4 mPosition: POSITION;
float2 mUV : TEXCOORD0;
};
struct VS_OUTPUT
{
float4 mPosition: POSITION;
float2 mUV : TEXCOORD0;
};
VS_OUTPUT vs_main(VS_INPUT Input)
{
VS_OUTPUT Output;
Output.mPosition = Input.mPosition;
Output.mUV = Input.mUV;
return Output;
}
// Pixel Shader
// 외곽 검출
struct PS_INPUT
{
float2 mUV : TEXCOORD0;
};
sampler2D SceneSampler;
float3x3 Kx = { -1, 0, 1, -2, 0, 2, -1, 0, 1 };
float3x3 Ky = { 1, 2, 1, 0, 0, 0, -1, -2, -1 };
float2 gPixelOffset;
float4 ps_main(PS_INPUT Input) : COLOR
{
float Lx = 0;
float Ly = 0;
for (int y = -1; y <= 1; ++y)
{
for (int x = -1; x <= 1; ++x)
{
float2 offset = float2(x, y) * gPixelOffset;
float3 tex = tex2D(SceneSampler, Input.mUV + offset).rgb;
float luminance = dot(tex, float3(0.3, 0.59, 0.11));
Lx += luminance * Kx[y + 1][x + 1];
Ly += luminance * Ky[y + 1][x + 1];
}
}
float L = sqrt((Lx * Lx) + (Ly * Ly));
return float4(L.xxx, 1);
}
// Pixel Shader
// 엠보싱
struct PS_INPUT
{
float2 mUV : TEXCOORD0;
};
sampler2D SceneSampler;
float3x3 K = { -2, -1, 0, -1, 0, 1, 0, 1, 2 };
float2 gPixelOffset;
float4 ps_main(PS_INPUT Input) : COLOR
{
float res = 0;
for (int y = -1; y <= 1; ++y)
{
for (int x = -1; x <= 1; ++x)
{
float2 offset = float2(x, y) * gPixelOffset;
float3 tex = tex2D(SceneSampler, Input.mUV + offset).rgb;
float luminance = dot(tex, float3(0.3, 0.59, 0.11));
res += luminance * K[y + 1][x + 1];
}
}
res += 0.5f;
return float4(res.xxx, 1);
}
color Conversion 추가 되어 있음 : https://asatala.tistory.com/84
'Study > RenderMonkey - 2019년 백업' 카테고리의 다른 글
[RenderMonkey] Color Conversion (1) | 2023.12.06 |
---|---|
[RenderMonkey] Shadow 2/2 (1) | 2023.12.06 |
[RenderMonkey] Shadow 1/2 (0) | 2023.12.06 |
[RenderMonkey] Vertex Animation (1) | 2023.12.06 |
[RenderMonkey] UV Animation (1) | 2023.12.06 |