hallo

ich baue gerade an einem bloom shader.... der funktioniert aber noch net ganz.
ich weis net wie ich es beschreiben soll... die camera wird einfach nur eingefärbt, anstatt einen bloom effekt zu erzeugen ...

ich bin ein anfänger bei shadern aber ich denke es liegt am downsampler, weil ich nicht genau weis wie er aufgebaut ist... ich hab den downsampler aus einem anderen shader genommen (nvidia cg).

außerdem verwende ich sylex3

hier der code:

Code:
 

// Texturen
texture postTex1;
texture postTex2;

////////////////////////////////////////////////
//float Luminance = 0.1f;
//static const float fMiddleGray = 0.18f;
//static const float fWhiteCutoff = 0.4f;

float Luminance = 0.11f;
static const float fMiddleGray = 0.3f;
static const float fWhiteCutoff = 0.59f;

float2 WindowSize : VIEWPORTPIXELSIZE;
float2 ViewportRatio = { 0.25, 0.25 };
float downsampleScale = 0.25;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Sampler für Texturen in diesem Effekt

sampler currentScene = sampler_state
{
texture = (postTex1);
MinFilter = linear;
MagFilter = linear;
MipFilter = linear;
AddressU = Clamp;
AddressV = Clamp;
};


sampler originalScene = sampler_state
{
texture = (postTex2);
MinFilter = linear;
MagFilter = linear;
MipFilter = linear;
AddressU = Clamp;
AddressV = Clamp;
};


sampler DownsampleSampler = sampler_state
{
texture = (postTex1);
MinFilter = none;
MagFilter = linear;
MipFilter = linear;
AddressU = Clamp;
AddressV = Clamp;
};

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Zusätzliche Variablen

static const int g_c_PixelOffsetSize = 13;

float2 PixelOffsets[g_c_PixelOffsetSize] =
{
{ 0, -0.006 },
{ 0, -0.005 },
{ 0, -0.004 },
{ 0, -0.003 },
{ 0, -0.002 },
{ 0, -0.001 },
{ 0, 0.000 },
{ 0, 0.001 },
{ 0, 0.002 },
{ 0, 0.003 },
{ 0, 0.004 },
{ 0, 0.005 },
{ 0, 0.006 },
};

static const float BlurWeights[g_c_PixelOffsetSize] =
{
0.002216,
0.008764,
0.026995,
0.064759,
0.120985,
0.176033,
0.199471,
0.176033,
0.120985,
0.064759,
0.026995,
0.008764,
0.002216,
};

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Vertexberechnung

struct VS_OUTPUT_DOWNSAMPLE
{
float4 Position : POSITION;
float2 TexCoord[4]: TEXCOORD0;
};

VS_OUTPUT_DOWNSAMPLE VS_Downsample(float4 Position : POSITION, float2 TexCoord : TEXCOORD0)
{
VS_OUTPUT_DOWNSAMPLE OUT;
float2 texelSize = downsampleScale / WindowSize;
float2 s = TexCoord;
OUT.Position = Position;
OUT.TexCoord[0] = s;
OUT.TexCoord[1] = s + float2(2, 0)*texelSize;
OUT.TexCoord[2] = s + float2(2, 2)*texelSize;
OUT.TexCoord[3] = s + float2(0, 2)*texelSize;
return OUT;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Pixelberechnung

//float4 PS_Downsample(VS_OUTPUT_DOWNSAMPLE IN) : COLOR

float4 PS_Downsample(float2 TexCoord[4] : TEXCOORD0) : COLOR
{
float4 pixel = 0;

#if 0
// sub sampling
pixel = tex2D(DownsampleSampler, TexCoord[0]);
#else
// box filter
pixel = tex2D(DownsampleSampler, TexCoord[0]) * 0.25;
pixel += tex2D(DownsampleSampler, TexCoord[1]) * 0.25;
pixel += tex2D(DownsampleSampler, TexCoord[2]) * 0.25;
pixel += tex2D(DownsampleSampler, TexCoord[3]) * 0.25;
#endif
// store hilights in alpha
//pixel.a = highlights(pixel.rgb);

return pixel;
}

float4 BrightPass_PS(float2 texcoord0 : TEXCOORD0) : COLOR
{
// Aktuellen Pixel samplen:
float3 pixel = tex2D(currentScene,texcoord0);

pixel *= fMiddleGray / (Luminance + 0.001f);
pixel *= (1.0f + (pixel / (fWhiteCutoff * fWhiteCutoff)));
pixel -= 5.0f;

pixel = max(pixel,0.0f);
pixel /= (5.0f + pixel);
return float4(pixel,1.0f);
}

float4 HorBloom_PS(float2 texcoord0 : TEXCOORD0) : COLOR
{
// Aktuellen Pixel samplen:
float4 pixel = 0;

// Blur berechnen
for(int i = 0; i < g_c_PixelOffsetSize; i++)
{
pixel += tex2D(currentScene,texcoord0 + PixelOffsets[i] * 7.5f) * BlurWeights[i];
}

return pixel * 1;
}

float4 VerBloom_PS(float2 texcoord0 : TEXCOORD0) : COLOR
{
// Aktuellen Pixel samplen:
float4 pixel = 0;

// Blur berechnen
for(int i = 0; i < g_c_PixelOffsetSize; i++)
{
pixel += tex2D(currentScene,texcoord0 + PixelOffsets[i] * 7.5f) * BlurWeights[i];
}

return pixel * 1;
}

float4 Monochrom_PS(float2 texcoord0 : TEXCOORD0) : COLOR
{
float4 pixel = tex2D(originalScene,texcoord0);
return tex2D(currentScene,texcoord0) + pixel;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Technik 0 für Brightpass Effekt

technique tech_00
{
pass pass_00
{
cullmode = none;
ZEnable = false;
ZWriteEnable = false;

VertexShader = compile vs_2_0 VS_Downsample();
PixelShader = compile ps_2_0 PS_Downsample();
}
}

technique tech_01
{
pass pass_00
{
// Effekt compillieren
Pixelshader = compile ps_2_0 BrightPass_PS();
}
}


technique tech_02
{
pass pass_00
{
// Effekt compillieren
Pixelshader = compile ps_2_0 HorBloom_PS();
}
}


technique tech_03
{
pass pass_00
{
// Effekt compillieren
Pixelshader = compile ps_2_0 VerBloom_PS();
}
}

technique tech_04
{
pass pass_00
{
// Effekt compillieren
Pixelshader = compile ps_2_0 Monochrom_PS();
}
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Fallback Funktion --> No Effect
technique tech_05
{
pass pass_00
{
Texture[0] = <postTex1>;
}
}



was ist noch falsch am code... und was müsste ich noch ändern? ... bitte helft mir


=> www.alrik-online.de
A7 Commercial