2014-04-12 6 views
0

HLSL에서 가우시안 블러 쉐이더를 구현하려고하는데 코드가 정확하지만 결과 이미지가 모두 흰색 인 경우 결과 색상을 1000으로 다이빙하여 더러운 해킹을하지 않는 한. 색상이 변경되는대로 바로 잘못된 것입니다, 지금은 뭔가를 보여줍니다가우시안 블러 쉐이더가 흐리게 처리되지 않습니다

enter image description here

sampler2D input : register(s0); 

// new HLSL shader 
// modify the comment parameters to reflect your shader parameters 

/// <summary>Explain the purpose of this variable.</summary> 
/// <minValue>0,0/minValue> 
/// <maxValue>1024,1024</maxValue> 
/// <defaultValue>599,124</defaultValue> 
float2 InputSize : register(C0); 

const float pi = 3.141592f; 

float4 main(float2 uv : TEXCOORD) : COLOR 
{ 
    float4 color = tex2D(input , uv.xy); 

    float sigma = 1.4; 
    float sigmaSq = sigma * sigma; 
    int kernel = 21; 
    int radius = kernel/2; 

    for(int i = -radius; i <= radius; i++) 
    { 
     float x = 1.0f/radius * i; 
     float xSq = x * x; 
     float gb = 1.0f/sqrt(2.0f * pi * sigmaSq) * exp(-(xSq/(2.0f * sigmaSq))); 
     float2 st = float2(1.0f/InputSize.x * i, 0.0f); 
     float3 c = tex2D(input, uv + st).xyz; 
     color.xyz += (c * gb)/1000.0; 
    } 
    return color; 
} 

내가 here에서 공식을 가져다 here에서 내 코드를 영감을.

이 내 기준 영상 나는이 이미지에 비해 단지 X 축에 그것을했다

enter image description here

주 (시그마 = 5 및 크기 = 21 AForge.NET로 만든)입니다, 나는 그것을 올바른 것으로 만들기 위해 노력하고있다. 당신이 시도하려는 경우

그리고 원래의 이미지, 당신은 Shazzam의 쉐이더 코드를 붙여 넣을 수 있습니다 :

enter image description here

답변

0

http://www.embege.com/gauss/

enter image description here

sampler2D input : register(s0); 

// new HLSL shader 
// modify the comment parameters to reflect your shader parameters 

/// <summary>Explain the purpose of this variable.</summary> 
/// <minValue>1, 1/minValue> 
/// <maxValue>1024, 1024</maxValue> 
/// <defaultValue>599, 124</defaultValue> 
float2 InputSize : register(C0); 

static const float kernel[441] = { 
{ 
0.0001253219113395547, 0.00018325629967027186, 0.000257465496677347, 0.00034754206833684524, 0.0004507377648081042, 0.0005616538403243442, 0.0006724217297003478, 0.0007734690974565646, 0.0008548155525392126, 0.0009076743942415001, 0.0009260106333131518, 0.0009076743942415001, 0.0008548155525392126, 0.0007734690974565646, 0.0006724217297003478, 0.0005616538403243442, 0.0004507377648081042, 0.00034754206833684524, 0.000257465496677347, 0.00018325629967027186, 0.0001253219113395547, 
0.00018325629967027186, 0.000267972862924577, 0.00037648782810231063, 0.0005082054107090616, 0.0006591068873549146, 0.0008212977553028339, 0.0009832719329415178, 0.0011310319416143256, 0.0012499836092867847, 0.0013272782789233823, 0.00135409107874604, 0.0013272782789233823, 0.0012499836092867847, 0.0011310319416143256, 0.0009832719329415178, 0.0008212977553028339, 0.0006591068873549146, 0.0005082054107090616, 0.00037648782810231063, 0.000267972862924577, 0.00018325629967027186, 
0.000257465496677347, 0.00037648782810231063, 0.0005289456669688587, 0.0007140019672870738, 0.0009260106333131518, 0.001153880302447998, 0.001381445533054985, 0.0015890406012215013, 0.0017561614601114424, 0.0018647564199807886, 0.0019024269984878957, 0.0018647564199807886, 0.0017561614601114424, 0.0015890406012215013, 0.001381445533054985, 0.001153880302447998, 0.0009260106333131518, 0.0007140019672870738, 0.0005289456669688587, 0.00037648782810231063, 0.000257465496677347, 
0.00034754206833684524, 0.0005082054107090616, 0.0007140019672870738, 0.0009638018441690448, 0.0012499836092867847, 0.0015575754891478846, 0.0018647564199807886, 0.0021449804511547003, 0.0023705700144569524, 0.0025171578774949516, 0.002568007839679253, 0.0025171578774949516, 0.0023705700144569524, 0.0021449804511547003, 0.0018647564199807886, 0.0015575754891478846, 0.0012499836092867847, 0.0009638018441690448, 0.0007140019672870738, 0.0005082054107090616, 0.00034754206833684524, 
0.0004507377648081042, 0.0006591068873549146, 0.0009260106333131518, 0.0012499836092867847, 0.0016211413507230966, 0.0020200665141290397, 0.002418458705376228, 0.002781889682412439, 0.003074463574296922, 0.003264577784210943, 0.0033305266300735804, 0.003264577784210943, 0.003074463574296922, 0.002781889682412439, 0.002418458705376228, 0.0020200665141290397, 0.0016211413507230966, 0.0012499836092867847, 0.0009260106333131518, 0.0006591068873549146, 0.0004507377648081042, 
0.0005616538403243442, 0.0008212977553028339, 0.001153880302447998, 0.0015575754891478846, 0.0020200665141290397, 0.0025171578774949516, 0.003013585116655789, 0.003466448000315246, 0.0038310175189698874, 0.004067914412097752, 0.004150091734336279, 0.004067914412097752, 0.0038310175189698874, 0.003466448000315246, 0.003013585116655789, 0.0025171578774949516, 0.0020200665141290397, 0.0015575754891478846, 0.001153880302447998, 0.0008212977553028339, 0.0005616538403243442, 
0.0006724217297003478, 0.0009832719329415178, 0.001381445533054985, 0.0018647564199807886, 0.002418458705376228, 0.003013585116655789, 0.003607916426905765, 0.004150091734336279, 0.004586560692134574, 0.004870177765856866, 0.004968561882895685, 0.004870177765856866, 0.004586560692134574, 0.004150091734336279, 0.003607916426905765, 0.003013585116655789, 0.002418458705376228, 0.0018647564199807886, 0.001381445533054985, 0.0009832719329415178, 0.0006724217297003478, 
0.0007734690974565646, 0.0011310319416143256, 0.0015890406012215013, 0.0021449804511547003, 0.002781889682412439, 0.003466448000315246, 0.004150091734336279, 0.004773741784860959, 0.005275800591030858, 0.005602037879842168, 0.005715206551895624, 0.005602037879842168, 0.005275800591030858, 0.004773741784860959, 0.004150091734336279, 0.003466448000315246, 0.002781889682412439, 0.0021449804511547003, 0.0015890406012215013, 0.0011310319416143256, 0.0007734690974565646, 
0.0008548155525392126, 0.0012499836092867847, 0.0017561614601114424, 0.0023705700144569524, 0.003074463574296922, 0.0038310175189698874, 0.004586560692134574, 0.005275800591030858, 0.005830661382773607, 0.0061912093467597126, 0.006316280071950432, 0.0061912093467597126, 0.005830661382773607, 0.005275800591030858, 0.004586560692134574, 0.0038310175189698874, 0.003074463574296922, 0.0023705700144569524, 0.0017561614601114424, 0.0012499836092867847, 0.0008548155525392126, 
0.0009076743942415001, 0.0013272782789233823, 0.0018647564199807886, 0.0025171578774949516, 0.003264577784210943, 0.004067914412097752, 0.004870177765856866, 0.005602037879842168, 0.0061912093467597126, 0.006574052351702679, 0.0067068570186131155, 0.006574052351702679, 0.0061912093467597126, 0.005602037879842168, 0.004870177765856866, 0.004067914412097752, 0.003264577784210943, 0.0025171578774949516, 0.0018647564199807886, 0.0013272782789233823, 0.0009076743942415001, 
0.0009260106333131518, 0.00135409107874604, 0.0019024269984878957, 0.002568007839679253, 0.0033305266300735804, 0.004150091734336279, 0.004968561882895685, 0.005715206551895624, 0.006316280071950432, 0.0067068570186131155, 0.006842344517756951, 0.0067068570186131155, 0.006316280071950432, 0.005715206551895624, 0.004968561882895685, 0.004150091734336279, 0.0033305266300735804, 0.002568007839679253, 0.0019024269984878957, 0.00135409107874604, 0.0009260106333131518, 
0.0009076743942415001, 0.0013272782789233823, 0.0018647564199807886, 0.0025171578774949516, 0.003264577784210943, 0.004067914412097752, 0.004870177765856866, 0.005602037879842168, 0.0061912093467597126, 0.006574052351702679, 0.0067068570186131155, 0.006574052351702679, 0.0061912093467597126, 0.005602037879842168, 0.004870177765856866, 0.004067914412097752, 0.003264577784210943, 0.0025171578774949516, 0.0018647564199807886, 0.0013272782789233823, 0.0009076743942415001, 
0.0008548155525392126, 0.0012499836092867847, 0.0017561614601114424, 0.0023705700144569524, 0.003074463574296922, 0.0038310175189698874, 0.004586560692134574, 0.005275800591030858, 0.005830661382773607, 0.0061912093467597126, 0.006316280071950432, 0.0061912093467597126, 0.005830661382773607, 0.005275800591030858, 0.004586560692134574, 0.0038310175189698874, 0.003074463574296922, 0.0023705700144569524, 0.0017561614601114424, 0.0012499836092867847, 0.0008548155525392126, 
0.0007734690974565646, 0.0011310319416143256, 0.0015890406012215013, 0.0021449804511547003, 0.002781889682412439, 0.003466448000315246, 0.004150091734336279, 0.004773741784860959, 0.005275800591030858, 0.005602037879842168, 0.005715206551895624, 0.005602037879842168, 0.005275800591030858, 0.004773741784860959, 0.004150091734336279, 0.003466448000315246, 0.002781889682412439, 0.0021449804511547003, 0.0015890406012215013, 0.0011310319416143256, 0.0007734690974565646, 
0.0006724217297003478, 0.0009832719329415178, 0.001381445533054985, 0.0018647564199807886, 0.002418458705376228, 0.003013585116655789, 0.003607916426905765, 0.004150091734336279, 0.004586560692134574, 0.004870177765856866, 0.004968561882895685, 0.004870177765856866, 0.004586560692134574, 0.004150091734336279, 0.003607916426905765, 0.003013585116655789, 0.002418458705376228, 0.0018647564199807886, 0.001381445533054985, 0.0009832719329415178, 0.0006724217297003478, 
0.0005616538403243442, 0.0008212977553028339, 0.001153880302447998, 0.0015575754891478846, 0.0020200665141290397, 0.0025171578774949516, 0.003013585116655789, 0.003466448000315246, 0.0038310175189698874, 0.004067914412097752, 0.004150091734336279, 0.004067914412097752, 0.0038310175189698874, 0.003466448000315246, 0.003013585116655789, 0.0025171578774949516, 0.0020200665141290397, 0.0015575754891478846, 0.001153880302447998, 0.0008212977553028339, 0.0005616538403243442, 
0.0004507377648081042, 0.0006591068873549146, 0.0009260106333131518, 0.0012499836092867847, 0.0016211413507230966, 0.0020200665141290397, 0.002418458705376228, 0.002781889682412439, 0.003074463574296922, 0.003264577784210943, 0.0033305266300735804, 0.003264577784210943, 0.003074463574296922, 0.002781889682412439, 0.002418458705376228, 0.0020200665141290397, 0.0016211413507230966, 0.0012499836092867847, 0.0009260106333131518, 0.0006591068873549146, 0.0004507377648081042, 
0.00034754206833684524, 0.0005082054107090616, 0.0007140019672870738, 0.0009638018441690448, 0.0012499836092867847, 0.0015575754891478846, 0.0018647564199807886, 0.0021449804511547003, 0.0023705700144569524, 0.0025171578774949516, 0.002568007839679253, 0.0025171578774949516, 0.0023705700144569524, 0.0021449804511547003, 0.0018647564199807886, 0.0015575754891478846, 0.0012499836092867847, 0.0009638018441690448, 0.0007140019672870738, 0.0005082054107090616, 0.00034754206833684524, 
0.000257465496677347, 0.00037648782810231063, 0.0005289456669688587, 0.0007140019672870738, 0.0009260106333131518, 0.001153880302447998, 0.001381445533054985, 0.0015890406012215013, 0.0017561614601114424, 0.0018647564199807886, 0.0019024269984878957, 0.0018647564199807886, 0.0017561614601114424, 0.0015890406012215013, 0.001381445533054985, 0.001153880302447998, 0.0009260106333131518, 0.0007140019672870738, 0.0005289456669688587, 0.00037648782810231063, 0.000257465496677347, 
0.00018325629967027186, 0.000267972862924577, 0.00037648782810231063, 0.0005082054107090616, 0.0006591068873549146, 0.0008212977553028339, 0.0009832719329415178, 0.0011310319416143256, 0.0012499836092867847, 0.0013272782789233823, 0.00135409107874604, 0.0013272782789233823, 0.0012499836092867847, 0.0011310319416143256, 0.0009832719329415178, 0.0008212977553028339, 0.0006591068873549146, 0.0005082054107090616, 0.00037648782810231063, 0.000267972862924577, 0.00018325629967027186, 
0.0001253219113395547, 0.00018325629967027186, 0.000257465496677347, 0.00034754206833684524, 0.0004507377648081042, 0.0005616538403243442, 0.0006724217297003478, 0.0007734690974565646, 0.0008548155525392126, 0.0009076743942415001, 0.0009260106333131518, 0.0009076743942415001, 0.0008548155525392126, 0.0007734690974565646, 0.0006724217297003478, 0.0005616538403243442, 0.0004507377648081042, 0.00034754206833684524, 0.000257465496677347, 0.00018325629967027186, 0.0001253219113395547, 
}}; 

float4 main(float2 uv : TEXCOORD) : COLOR 
{ 
    float4 color = float4(0,0,0,0); 
    float w = 1.0f/InputSize.x; 
    float h = 1.0f/InputSize.y; 
    int width = 21; 
    int center = width/2; 
    for(int x = -center; x <= center; x++) 
    for(int y = -center; y <= center; y++) 
    { 
     //float2 p = float2((x - center) * w, (y - center) * h); 
     //float4 c = tex2D(input, saturate(uv.xy + p)); 
     float4 c = tex2D(input, saturate(uv.xy + float2(x * w, y * h))); 
     int offset = (y + center) * width + (x + center); 
     float g = kernel[offset]; 
     color += c * g; 
    } 
    return color; 
}