PS_OUTPUT output; const float
sampler tex0; struct PS_INPUT { float2 base : TEXCOORD0; }; struct PS_OUTPUT { float4 diffuse : COLOR0; }; PS_OUTPUT Main (PS_INPUT input) { PS_OUTPUT output; const float W =320.0f; const float H =240.0f; const float du=1.0f/(W-1); const float dv=1.0f/(H-1); const float2 c[9] = { float2(-du, -dv), float2(0.0f, -dv), float2(du, -dv), float2(-du, 0.0f), float2(0.0f, 0.0f), float2(du, 0.0f), float2(-du, dv), float2(0.0f, dv), float2(du, dv) }; float3 col[9]; for (int i=0; i<9; i++) { col[i] = tex2D(tex0, input.base+c[i]); } float lum[9]; float3 gray = (0.30f, 0.59f, 0.11f) ; for (int i=0; i<9; i++) { lum[i] = dot(col[i], gray); } float res1 = 0.0f; float res2 = 0.0f; const float sobel1[9] = { 1, 2, 1, 0, 0, 0, -1, -2, -1}; const float sobel2[9] = {-1, 0, 1, -2, 0, 2, -1, 0, 1}; const float tisnenie[9] = {0, 1, 0, -1, 0, 1, 0, -1, 0}; for (int i=0; i<9; i++) { res1+=lum[i]*sobel1[i]; res2+=lum[i]*sobel2[i]; res+=lum[i]*tisnenie[i]; } output.diffuse = sqrt(res1*res1+res2*res2); //output.diffuse = res+0.5f; return output; }; |
Пример 6.1. |
Закрыть окно |
sampler tex0;
struct PS_INPUT
{
float2 base : TEXCOORD0;
};
struct PS_OUTPUT
{
float4 diffuse : COLOR0;
};
PS_OUTPUT Main (PS_INPUT input)
{
PS_OUTPUT output;
const float W =320.0f;
const float H =240.0f;
const float du=1.0f/(W-1);
const float dv=1.0f/(H-1);
const float2 c[9] = {
float2(-du, -dv), float2(0.0f, -dv), float2(du, -dv),
float2(-du, 0.0f), float2(0.0f, 0.0f), float2(du, 0.0f),
float2(-du, dv), float2(0.0f, dv), float2(du, dv)
};
float3 col[9];
for (int i=0; i<9; i++) {
col[i] = tex2D(tex0, input.base+c[i]);
}
float lum[9];
float3 gray = (0.30f, 0.59f, 0.11f) ;
for (int i=0; i<9; i++) {
lum[i] = dot(col[i], gray);
}
float res1 = 0.0f;
float res2 = 0.0f;
const float sobel1[9] = { 1, 2, 1, 0, 0, 0, -1, -2, -1};
const float sobel2[9] = {-1, 0, 1, -2, 0, 2, -1, 0, 1};
const float tisnenie[9] = {0, 1, 0, -1, 0, 1, 0, -1, 0};
for (int i=0; i<9; i++) {
res1+=lum[i]*sobel1[i];
res2+=lum[i]*sobel2[i];
res+=lum[i]*tisnenie[i];
}
output.diffuse = sqrt(res1*res1+res2*res2);
//output.diffuse = res+0.5f;
return output;
};