Jump to content
  • Advertisement
Sign in to follow this  
Burz666

Problems with DX Post Bloom

This topic is 3756 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello to all! here my test project :http://webfile.ru/2079894 There is a problem - glow works fine? but blure don't.... please help me.

Share this post


Link to post
Share on other sites
Advertisement
*sigh* how is this attempt significantly different to your previous thread??

Read: Forum Guidelines, Best Practices and How To Solve A Problem Yourself - all stuck to the top of this forum.

Then get familiar with all the advice in how to ask a good question.

Then, the final tip - don't upload your code, it just doesn't work. No one in their right mind will download a bunch of arbitrary code from the internet, load it up and hit "F5". How do I know you're the real deal and this isn't some spyware/malware/virus? Hey, your code is broken - how do I know its not going to unintentionally break my computer?

As suggested in the aforementioned reading, post the analysis you've done - post the fragments of code that won't work along with every relevant detail. We'll help you fix your own code, we're not here to do all your work for you whilst you sit back and wait.

So, please try again with your question - 3rd time lucky I hope [smile]

Jack

Share this post


Link to post
Share on other sites
ok. here shader code:

#include <quad.fxh>
///////////////////////////////////////////////////////////
/////////////////////////////////////// Tweakables ////////
///////////////////////////////////////////////////////////
float SceneIntensity = 1.5f;
float GlowIntensity = 2.0f;
float HighlightThreshold = 0.0f;
float HighlightIntensity = 0.0f;
///////////////////////////////////////////////////////////
///////////////////////////// Render-to-Texture Data //////
///////////////////////////////////////////////////////////
float2 WindowSize = {1024.0f,768.0f};
float downsampleScale = 0.25;
float BlurWidth = 5.0f;

texture SceneMap;
sampler2D SceneSampler = sampler_state
{
Texture = <SceneMap>;
MinFilter = LINEAR;
MipFilter = LINEAR;
MagFilter = LINEAR;
AddressU = Wrap;
AddressV = Wrap;
};
texture DownsampleMap;
sampler2D DownsampleSampler = sampler_state
{
Texture = <DownsampleMap>;
MinFilter = LINEAR;
MipFilter = LINEAR;
MagFilter = LINEAR;
AddressU = Wrap;
AddressV = Wrap;
};
texture HBlurMap;
sampler2D HBlurSampler = sampler_state
{
Texture = <HBlurMap>;
MinFilter = LINEAR;
MipFilter = LINEAR;
MagFilter = LINEAR;
AddressU = Wrap;
AddressV = Wrap;
};
texture FinalBlurMap;
sampler2D FinalBlurSampler = sampler_state
{
Texture = <FinalBlurMap>;
MinFilter = LINEAR;
MipFilter = LINEAR;
MagFilter = LINEAR;
AddressU = Wrap;
AddressV = Wrap;
};
///////////////////////////////////////////////////////////
/////////////////////////////////// data structures ///////
///////////////////////////////////////////////////////////
struct VS_BLUR
{
float4 pos : POSITION;
float2 tex[8]: TEXCOORD0;
};

struct VS_OUTPUT
{
float4 pos : POSITION;
float2 tex0 : TEXCOORD0;
float2 tex1 : TEXCOORD1;
};

struct VS_DOWNSAMPLE
{
float4 pos : POSITION;
float2 tex[4]: TEXCOORD0;
};
////////////////////////////////////////////////////////////
////////////////////////////////// vertex shaders //////////
////////////////////////////////////////////////////////////
VS_DOWNSAMPLE VS_Downsample(float4 Position : POSITION,float2 TexCoord : TEXCOORD0)
{
VS_DOWNSAMPLE OUT;
float2 texelSize = BlurWidth / WindowSize;
float2 s = TexCoord;
OUT.pos = Position;
OUT.tex[0] = s;
OUT.tex[1] = s + float2(2, 0)*texelSize;
OUT.tex[2] = s + float2(2, 2)*texelSize;
OUT.tex[3] = s + float2(0, 2)*texelSize;
return OUT;
}

VS_BLUR VS_Blur(float4 Position : POSITION, float2 TexCoord : TEXCOORD0,uniform int nsamples,uniform float2 direction)
{
VS_BLUR OUT = (VS_BLUR)0;
OUT.pos = Position;

float2 texelSize = BlurWidth / WindowSize;
float2 s = TexCoord - texelSize*(nsamples-1)*5.5*direction;
for(int i=0; i<nsamples; i++)
{
OUT.tex = s + texelSize*i*direction;
}
return OUT;
}

VS_OUTPUT VS_Quad(float4 Position : POSITION, float2 TexCoord : TEXCOORD0)
{
VS_OUTPUT OUT;
float2 texelSize = BlurWidth / WindowSize;
OUT.pos = Position;
OUT.tex0 = TexCoord + texelSize*0.5;
OUT.tex1 = TexCoord + texelSize*0.5/downsampleScale;
return OUT;
}

//////////////////////////////////////////////////////
////////////////////////////////// pixel shaders /////
//////////////////////////////////////////////////////
float luminance(float3 c)
{
return dot( c, float3(0.3, 0.59, 0.11) );
}

float highlights(float3 c)
{
return smoothstep(HighlightThreshold, 1.0, luminance(c.rgb));
}

float4 PS_Downsample(VS_DOWNSAMPLE IN,
uniform sampler2D tex) : COLOR
{
float4 c;
#if 0
c = tex2D(tex, IN.tex[0]);
#else
c = tex2D(tex, IN.tex[0]) * 0.25;
c += tex2D(tex, IN.tex[1]) * 0.25;
c += tex2D(tex, IN.tex[2]) * 0.25;
c += tex2D(tex, IN.tex[3]) * 0.25;
#endif
c.a = highlights(c.rgb);

return c;
}

const float weights7[7] = {
0.05,
0.1,
0.2,
0.3,
0.2,
0.1,
0.05,
};

const float weights7_Central[7] = {
0.0,
0.0,
0.2,
0.6,
0.2,
0.0,
0.0,
};

float4 PS_Blur7(VS_BLUR IN,
uniform sampler2D tex,
uniform float weight[7]
) : COLOR
{
float4 c = 0;
for(int i=0; i<7; i++)
{
float scale = 1.0f + -0.5f * i;
c += tex2D(tex, IN.tex.xy * scale) * weight;
}
return c;
}

float4 PS_Display(VS_OUTPUT IN,
uniform sampler2D tex) : COLOR
{
return tex2D(tex, IN.tex1);
}

float4 PS_Comp(VS_OUTPUT IN,
uniform sampler2D sceneSampler,
uniform sampler2D blurredSceneSampler) : COLOR
{
float4 orig = tex2D(sceneSampler, IN.tex0);
float4 blur = tex2D(blurredSceneSampler, IN.tex1);
return SceneIntensity*orig + GlowIntensity*blur + HighlightIntensity*blur.a;
}
////////////////////////////////////////////////////////////
/////////////////////////////////////// techniques /////////
////////////////////////////////////////////////////////////
technique Bloom
{
pass DownSample
{
cullmode = none;
ZEnable = false;
ZWriteEnable = false;
VertexShader = compile vs_2_0 VS_Downsample();
PixelShader = compile ps_2_0 PS_Downsample(SceneSampler);
}
pass GlowH
{
cullmode = none;
ZEnable = false;
ZWriteEnable = false;
VertexShader = compile vs_2_0 VS_Blur(7, float2(1, 0));
PixelShader = compile ps_2_0 PS_Blur7(DownsampleSampler, weights7);
}
pass GlowV
{
cullmode = none;
ZEnable = false;
ZWriteEnable = false;
VertexShader = compile vs_2_0 VS_Blur(7, float2(0, 1));
PixelShader = compile ps_2_0 PS_Blur7(HBlurSampler, weights7);
}

pass GlowH_Central
{
cullmode = none;
ZEnable = false;
ZWriteEnable = false;
VertexShader = compile vs_2_0 VS_Blur(7, float2(1, 0));
PixelShader = compile ps_2_0 PS_Blur7(DownsampleSampler, weights7_Central);
}
pass GlowV_Central
{
cullmode = none;
ZEnable = false;
ZWriteEnable = false;
VertexShader = compile vs_2_0 VS_Blur(7, float2(0, 1));
PixelShader = compile ps_2_0 PS_Blur7(HBlurSampler, weights7_Central);
}
pass FinalComp
{
cullmode = none;
ZEnable = false;
ZWriteEnable = false;
VertexShader = compile vs_2_0 VS_Quad();
PixelShader = compile ps_2_0 PS_Comp(SceneSampler, FinalBlurSampler);
}
}

and here render:

VOID Render()
{
HRESULT hErr;
//-------------------------------------------------------------------------------------------------------------------------//
SetupMatrices();
SetupFullScreenQuad();
//-------------------------------------------------------------------------------------------------------------------------//
g_pd3dDevice->BeginScene();

g_pd3dDevice->SetRenderState(D3DRS_CLIPPING,TRUE);
g_pd3dDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_CCW);
g_pd3dDevice->SetRenderState(D3DRS_ZENABLE,D3DZB_TRUE);
//-------------------------------------------------------------------------------------------------------------------------//
D3DLIGHT9 light;
D3DXVECTOR3 vecLightDirUnnormalized(100.0f, -200.0f, -1.0f);
ZeroMemory( &light, sizeof(D3DLIGHT9) );

light.Type = D3DLIGHT_DIRECTIONAL;
light.Diffuse.r = 1.0f;
light.Diffuse.g = 1.0f;
light.Diffuse.b = 1.0f;
D3DXVec3Normalize( (D3DXVECTOR3*)&light.Direction, &vecLightDirUnnormalized );
light.Position.x = 0.0f;
light.Position.y = -10.0f;
light.Position.z = 1.0f;
light.Range = 1.0f;

g_pd3dDevice->SetLight(0,&light);
g_pd3dDevice->LightEnable(0,TRUE);
//-------------------------------------------------------------------------------------------------------------------------//
g_pd3dDevice->GetRenderTarget(0,&oldrt);
g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_STENCIL|D3DCLEAR_ZBUFFER,
D3DCOLOR_ARGB(1,0,0,0), 100.0f, 1.0f );

SetRenderTarget(0,SceneMap);
g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_STENCIL|D3DCLEAR_ZBUFFER,
D3DCOLOR_ARGB(1,0,0,0), 100.0f, 1.0f );

g_pd3dDevice->GetDepthStencilSurface(&ds);

D3DXMATRIX ObjMat;
D3DXMatrixIdentity(&ObjMat);

D3DXMATRIX pos;
D3DXMatrixIdentity(&pos);

D3DXMATRIX sc;
D3DXMatrixIdentity(&sc);
D3DXMatrixScaling(&sc, 1.0f / 3.0f, 1.0f / 3.0f, 1.0f / 3.0f);

D3DXMATRIX rot;
D3DXMatrixIdentity(&rot);
D3DXMatrixRotationY( &rot, timeGetTime()/1000.0f );

ObjMat = sc * rot * pos;

g_pd3dDevice->SetTransform(D3DTS_WORLD,&ObjMat);

for(int i = 0; i < g_dwNumMaterials; i ++)
{
g_pd3dDevice->SetMaterial(&g_pMeshMaterials);
g_pd3dDevice->SetTexture(0,g_pMeshTextures);
g_pMesh->DrawSubset(i);
}

//D3DXSaveTextureToFile(L"scene___.jpg", D3DXIFF_JPG ,ScnMap,NULL);
//-------------------------------------------------------------------------------------------------------------------------//
Effect->SetTechnique("Bloom");
SetRenderTarget(0,SceneMap);
//-------------------------------------------------------------------------------------------------------------------------//
UINT cPasses = 0;
Effect->Begin( &cPasses, 0 );

//pass DownSample
SetRenderTarget(0,DownsampleMap);
g_pd3dDevice->SetDepthStencilSurface(ds);

g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_STENCIL|D3DCLEAR_ZBUFFER,
D3DCOLOR_ARGB(1,0,0,0), 100.0f, 1.0f );
Effect->BeginPass(0);
g_pd3dDevice->SetFVF(FVF_SCREEN);
Effect->SetTexture("SceneMap",SceneMap);
Effect->CommitChanges();
g_pd3dDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, v, sizeof(ScreenVertex));
Effect->EndPass();
//D3DXSaveTextureToFile(L"pass0.tga", D3DXIFF_TGA ,DownsampleMap,NULL);

//-------------------------------------------------------------------------------------------------------------------------//
//pass GlowH
SetRenderTarget(0,HBlurMap);
g_pd3dDevice->SetDepthStencilSurface(ds);

g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_STENCIL|D3DCLEAR_ZBUFFER,
D3DCOLOR_ARGB(1,0,0,0), 100.0f, 1.0f );
Effect->BeginPass(1);
g_pd3dDevice->SetFVF(FVF_SCREEN);
Effect->SetTexture("DownsampleMap",DownsampleMap);
Effect->CommitChanges();
g_pd3dDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, v, sizeof(ScreenVertex));
Effect->EndPass();
//D3DXSaveTextureToFile(L"pass1.tga", D3DXIFF_TGA ,HBlurMap,NULL);
//-------------------------------------------------------------------------------------------------------------------------//

//pass GlowV
SetRenderTarget(0,FinalBlurMap);
g_pd3dDevice->SetDepthStencilSurface(ds);

g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_STENCIL|D3DCLEAR_ZBUFFER,
D3DCOLOR_ARGB(1,0,0,0), 100.0f, 1.0f );

Effect->BeginPass(2);
g_pd3dDevice->SetFVF(FVF_SCREEN);
Effect->SetTexture("HBlurMap",HBlurMap);
Effect->CommitChanges();
g_pd3dDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, v, sizeof(ScreenVertex));
Effect->EndPass();
//D3DXSaveTextureToFile(L"pass2.tga", D3DXIFF_TGA ,FinalBlurMap,NULL);
//-------------------------------------------------------------------------------------------------------------------------//

//pass GlowH_Central
SetRenderTarget(0,HBlurMap);
g_pd3dDevice->SetDepthStencilSurface(ds);

g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_STENCIL|D3DCLEAR_ZBUFFER,
D3DCOLOR_ARGB(1,0,0,0), 100.0f, 1.0f );
Effect->BeginPass(3);
g_pd3dDevice->SetFVF(FVF_SCREEN);
Effect->SetTexture("DownsampleMap",DownsampleMap);
Effect->CommitChanges();
g_pd3dDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, v, sizeof(ScreenVertex));
Effect->EndPass();
//D3DXSaveTextureToFile(L"pass3.jpg", D3DXIFF_JPG ,HBlurMap,NULL);

//-------------------------------------------------------------------------------------------------------------------------//
//pass GlowV_Central
SetRenderTarget(0,FinalBlurMap);
g_pd3dDevice->SetDepthStencilSurface(ds);


g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_STENCIL|D3DCLEAR_ZBUFFER,
D3DCOLOR_ARGB(1,0,0,0), 100.0f, 1.0f );
Effect->BeginPass(4);
g_pd3dDevice->SetFVF(FVF_SCREEN);
Effect->SetTexture("HBlurMap",HBlurMap);
Effect->CommitChanges();
g_pd3dDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, v, sizeof(ScreenVertex));
Effect->EndPass();
//D3DXSaveTextureToFile(L"pass4.jpg", D3DXIFF_JPG ,FinalBlurMap,NULL);

//-------------------------------------------------------------------------------------------------------------------------//
//pass FinalComp
g_pd3dDevice->SetRenderTarget(0,oldrt);
g_pd3dDevice->SetDepthStencilSurface(ds);

g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_STENCIL|D3DCLEAR_ZBUFFER,
D3DCOLOR_ARGB(1,0,0,0), 100.0f, 1.0f );

Effect->BeginPass(5);
g_pd3dDevice->SetFVF(FVF_SCREEN);
Effect->SetTexture("SceneMap",SceneMap);
Effect->SetTexture("FinalBlurMap",FinalBlurMap);
Effect->CommitChanges();
g_pd3dDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, v, sizeof(ScreenVertex));
Effect->EndPass();

Effect->End();

hErr = g_pd3dDevice->EndScene();
hErr = g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
//-------------------------------------------------------------------------------------------------------------------------//


there is a no viruses doesn.t it?

Share this post


Link to post
Share on other sites
Ok, small step in the right direction - next up you can post your analysis and debugging results.

Full description of what happens, what doesn't happen - reproduction steps, any hypothesis or elimination for why it does(n't) work.

I assume you've fired this through PIX to see what your shaders are doing? I'll bet you also used FXComposer (or RenderMonkey) to author the shader? Results of that as well please. Maybe you just copied this from a sample online - how is your application different from theirs, I assume you tried running their code?

Debug output from Direct3D? Any HRESULT's triggering FAILED() macros? Details of that please.

Cheers,
Jack

P.S. Please remember to post with [source]...[/source] tags in future.

Share this post


Link to post
Share on other sites
D3DDEBUG - no messages.
ALL HRESULT = OK.

what happens - draws model with glow effect.
what doesn't happen - glow effect draws without blur.

why it does(n't) work - i don.t know, bocouse i am here.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!