Combine shaders

Posted By: Truth

Combine shaders - 10/07/13 19:52

Hi,
is it possible to combine shaders? can someone do this for me?

I have a Bloom shader and a blur shader but i cant seem to get them to work together. If anyone has a better blur shader please post.

Blur shader (pp_gaussian.fx)
Quote:

Texture TargetMap;
sampler2D g_samSrcColor = sampler_state { texture = <TargetMap>; MipFilter = Linear; };

float4 vecViewPort;

float4 postprocessing_gaussian(float2 Tex : TEXCOORD0) : COLOR0
{
float4 sampleM = tex2D(g_samSrcColor, Tex.xy);
float4 sampleB0 = tex2D( g_samSrcColor, Tex.xy - vecViewPort.zw );
float4 sampleF0 = tex2D( g_samSrcColor, Tex.xy + vecViewPort.zw );
float4 sampleB1 = tex2D( g_samSrcColor, Tex.xy - vecViewPort.zw*2. );
float4 sampleF1 = tex2D( g_samSrcColor, Tex.xy + vecViewPort.zw*2. );
//float4 sampleB2 = tex2D( g_samSrcColor, Tex.xy - vecViewPort.zw*3. );
//float4 sampleF2 = tex2D( g_samSrcColor, Tex.xy + vecViewPort.zw*3. );

return 0.1752 * sampleM + 0.1658 * (sampleB0 + sampleF0) + 0.1403 * (sampleB1 + sampleF1);// + 0.1063 * (sampleB2 + sampleF2);
}

technique PostProcess
{
pass p1
{
AlphaBlendEnable = false;
VertexShader = null;
PixelShader = compile ps_2_0 postprocessing_gaussian();
}
}



Bloom shader (bloom.fx)

Quote:

float4 vecSkill1;

texture entSkin1;

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




float Luminance = 0.08f;
static const float fMiddleGray = 0.18f;
static const float fWhiteCutoff = 0.8f;

#define NUM 13 //13

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

static const float BlurWeights[NUM] =
{
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,
};





float4 Bloom_PS_3_0(float2 texcoord0 : TEXCOORD0) : COLOR
{
float3 pixel;
float3 Color = 0;

for(int i = 0; i < NUM; i++)
{
pixel = tex2D(postTex,texcoord0 + PixelOffsets[i] * 5.0f)+vecSkill1[1];

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

pixel = max(pixel,0.0f);
pixel /= (10.0f + pixel);

Color += pixel * BlurWeights[i];
}

Color *= vecSkill1[0];

return float4(Color,1.0) + tex2D(postTex,texcoord0);
}

float4 Bloom_PS_2_0(float2 texcoord0 : TEXCOORD0) : COLOR
{
float3 pixel;
float3 Color = 0;

for(int i = 4; i < 9; i++)
{
pixel = tex2D(postTex,texcoord0 + PixelOffsets[i] * 5.0f)+vecSkill1[1];

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

pixel = max(pixel,0.0f);
pixel /= (10.0f + pixel);

Color += pixel * BlurWeights[i];
}

Color *= vecSkill1[0];

return float4(Color,1.0) + tex2D(postTex,texcoord0);
}


/*
technique tech_00
{
pass pass_00
{
VertexShader = null;
PixelShader = compile ps_3_0 Bloom_PS_3_0();
}
}
*/


technique tech_01
{
pass pass_00
{

VertexShader = null;
PixelShader = compile ps_2_0 Bloom_PS_2_0();

}
}
/*
technique tech_02
{
pass pass_00
{
Texture[0] = <entSkin1>;
}
}
*/




Thank you!
Posted By: Kartoffel

Re: Combine shaders - 10/08/13 07:36

how do you use them?
Posted By: Truth

Re: Combine shaders - 10/08/13 12:01

Hi,
I use the pp_helper I got from wiki
Quote:

view PP_Cam{layer = -2;}

entity PP_Quad
{
type = <PPE_Quad.bmp>;
layer = 0;
view = PP_Cam;

x = 1060; //878
y = 0;
z = 0;

scale_x = 1.0;
scale_y = 1.0;
}


//
function PP_Init_Effect()
{
PP_Quad.material = Shader_mat; //Change this to the material you wish<---------------------------


Bloom_set_Value(2,0.3); //Call here the function to set the materials values<------------- 4,0.9


/*
while(1)
{
if(screen_size.x == 1920)
}

*/
}

//
function PP_Toggle_OnOff()
{
if(PP_Quad.visible == on)
{
camera.bmap = NULL;
PP_Quad.visible = off;

}else
{
PP_Quad.visible = on;

camera.bmap = bmap_for_entity(PP_Quad,0);

}
}



on_b = PP_Toggle_OnOff();



Thanks
Posted By: Kartoffel

Re: Combine shaders - 10/08/13 13:03

so, combining them shouldn't be a problem (right now I haven't got alot of time, maybe later) but you have to know how set the material-skins of the shader properly.
Posted By: Truth

Re: Combine shaders - 10/08/13 18:58

Okay cool, thanks laugh
Posted By: Benni003

Re: Combine shaders - 10/25/13 14:10

yes, hope you can help me a little. The main thing is that I want to make a building dirty looking with a shader.
© 2024 lite-C Forums