X

HLSL HDRI Glow Effect

  • October 5, 2014
  • By admin
  • Comments Off on HLSL HDRI Glow Effect
  • in

Direct X High Level Shading Language

HDRI GLOW EFFECT

 

1) Enva Pass

Vertax Shader

 

struct VS_INPUT

{

float4 mPosition : POSITION;

float3 EnvaUV : TEXCOORD0;

};

 

struct VS_OUTPUT

{

float4 mPosition : POSITION;

float3 EnvaUV : TEXCOORD0;

};

 

float4x4 gWorldViewProjectionMatrix;

float4 gWorldCameraPosition;

 

VS_OUTPUT vs_main (VS_INPUT Input)

{

VS_OUTPUT Output;

float3 pos = Input.mPosition;

pos += gWorldCameraPosition;

Output.mPosition = mul(float4(pos, 1.0), gWorldViewProjectionMatrix);

Output.EnvaUV = Input.mPosition.xyz;

return Output;

}

 

Pixel Shader

 

struct PS_INPUT

{

float3 EnvaUV : TEXCOORD0;

};

 

samplerCUBE EnvaSampler;

float ExposureLevel;

 

float4 ps_main (PS_INPUT Input) : COLOR

{

float4 color = texCUBE(EnvaSampler, Input.EnvaUV);

color = color*((1.0+(color.a*64.0f))*ExposureLevel);

return color;

}

 

 

 

2)LensFlarePass

Vertax Shader

 

struct VS_INPUT

{

float4 mPosition : POSITION;

float2 mUV : TEXCOORD0;

};

 

struct VS_OUTPUT

{

float4 mPosition : POSITION;

float2 mUV : TEXCOORD0;

float2 texCoord1 : TEXCOORD1;

float2 texCoord2 : TEXCOORD2;

float2 texCoord3 : TEXCOORD3;

float2 texCoord4 : TEXCOORD4;

};

 

float Viewport_inv_width;

float Viewport_inv_height;

 

VS_OUTPUT vs_main (VS_INPUT Input)

{

VS_OUTPUT Output;

Output.mPosition = float4(Input.mPosition.xy, 0, 1);

// UV

Output.mUV.x = 0.5 * (1 + Input.mPosition.x + Viewport_inv_width);

Output.mUV.y = 0.5 * (1 - Input.mPosition.y + Viewport_inv_height);

//texcoord scale

Output.texCoord1 = (Input.mUV-0.5)*(-2.0) + 0.5;

Output.texCoord2 = (Input.mUV-0.5)*(2.0) + 0.5;

Output.texCoord3 = (Input.mUV-0.5)*(-0.6) + 0.5;

Output.texCoord4 = (Input.mUV-0.5)*(0.6) + 0.5;

return Output;

}

 

Pixel Shader

 

struct PS_INPUT

{

float4 mPosition : POSITION;

float2 mUV : TEXCOORD0;

float2 texCoord1 : TEXCOORD1;

float2 texCoord2 : TEXCOORD2;

float2 texCoord3 : TEXCOORD3;

float2 texCoord4 : TEXCOORD4;

};

 

sampler2D SceneSampler;

sampler2D MaskSampler;

float FlareFactor;

 

 

float4 ps_main(PS_INPUT Input) : COLOR

{

//sample all flare image

float4 flare1 = tex2D(SceneSampler, Input.texCoord1) * tex2D(MaskSampler, Input.texCoord1).a;

float4 flare2 = tex2D(SceneSampler, Input.texCoord2) * tex2D(MaskSampler, Input.texCoord2).a;

float4 flare3 = tex2D(SceneSampler, Input.texCoord3) * tex2D(MaskSampler, Input.texCoord3).a;

float4 flare4 = tex2D(SceneSampler, Input.texCoord4) * tex2D(MaskSampler, Input.texCoord4).a;

float4 color = (flare1 + flare2 + flare3 + flare4)*FlareFactor;

return color;

}

 

 

 

3)Gaussian Blur Pass H

Vertax Shader

 

struct VS_INPUT

{

float4 mPosition : POSITION;

float2 mUV : TEXCOORD0;

};

 

struct VS_OUTPUT

{

float4 mPosition : POSITION;

float2 mUV : TEXCOORD0;

};

 

float Viewport_inv_width;

float Viewport_inv_height;

 

VS_OUTPUT vs_main (VS_INPUT Input)

{

VS_OUTPUT Output;

Output.mPosition = float4(Input.mPosition.xy, 0, 1);

Output.mUV.x = 0.5 * (1 + Input.mPosition.x + Viewport_inv_width);

Output.mUV.y = 0.5 * (1 - Input.mPosition.y + Viewport_inv_height);

//Output.mUV = Input.mUV;

return Output;

}

 

Pixel Shader

 

struct PS_INPUT

{

float2 mUV : TEXCOORD0;

float4 mPosition : POSITION;

};

 

float Viewport_inv_width;

float Viewport_inv_height;

sampler2D SceneSampler;

 

float4 gaussFilter[7] =

{

-3.0, 0.0, 0.0,  1.0/64.0,

-2.0, 0.0, 0.0,  6.0/64.0,

-1.0, 0.0, 0.0, 15.0/64.0,

0.0, 0.0, 0.0, 20.0/64.0,

1.0, 0.0, 0.0, 15.0/64.0,

2.0, 0.0, 0.0,  6.0/64.0,

3.0, 0.0, 0.0,  1.0/64.0

};

 

float texScaler = 1.0/128.0;

float texOffset = 0.0;

 

 

float4 ps_main (PS_INPUT Input) : COLOR

{

float4 color = float4(0, 0, 0, 0);

for(int i = 0; i<7; i++)

{

color += tex2D(SceneSampler,float2(Input.mUV.x + gaussFilter[i].x * texScaler + texOffset,

Input.mUV.y + gaussFilter[i].y * texScaler + texOffset)) *

gaussFilter[i].w;

}

return color;

}

 

 

4)moreBlur01Pass

Vertax Shader

 

struct VS_INPUT

{

float4 mPosition : POSITION;

float2 mUV : TEXCOORD0;

};

 

struct VS_OUTPUT

{

float4 mPosition : POSITION;

float2 mUV : TEXCOORD0;

};

 

float Viewport_inv_width;

float Viewport_inv_height;

 

VS_OUTPUT vs_main (VS_INPUT Input)

{

VS_OUTPUT Output;

Output.mPosition = float4(Input.mPosition.xy, 0, 1);

Output.mUV.x = 0.5 * (1 + Input.mPosition.x + Viewport_inv_width);

Output.mUV.y = 0.5 * (1 - Input.mPosition.y + Viewport_inv_height);

//Output.mUV = Input.mUV;

return Output;

}

 

Pixel Shader

struct PS_INPUT

{

float2 mUV : TEXCOORD0;

float4 mPosition : POSITION;

};

 

float Viewport_inv_width;

float Viewport_inv_height;

sampler2D BlurTextureSampler;

const float blurFactor;

const float offsetFactor = 1;

 

const float4 blurSamples[4] =

{

0.0, 0.0, 0.0, 0,

1.0,-1.0, 0.0, 1,

2.0,-2.0, 0.0, 2,

3.0,-3.0, 0.0, 3,

};

 

float4 ps_main (PS_INPUT Input) : COLOR

{

float4 color = float4(0, 0, 0, 0);

for(int i=0; i<4; i++)

{

float4 col = tex2D(BlurTextureSampler, Input.mUV + offsetFactor * float2(blurSamples[i].x * Viewport_inv_width,

blurSamples[i].y * Viewport_inv_height));

col *= pow(blurFactor, offsetFactor*blurSamples[i].w);

color += col;

}

return color;

}

 

 

5) ScenePass

Vertax Shader

 

struct VS_INPUT

{

float4 mPosition : POSITION;

float2 mUV : TEXCOORD0;

};

 

struct VS_OUTPUT

{

float4 mPosition : POSITION;

float2 mUV : TEXCOORD0;

};

 

float Viewport_inv_width;

float Viewport_inv_height;

 

VS_OUTPUT vs_main (VS_INPUT Input)

{

VS_OUTPUT Output;

Output.mPosition = float4(Input.mPosition.xy, 0, 1);

Output.mUV.x = 0.5 * (1 + Input.mPosition.x + Viewport_inv_width);

Output.mUV.y = 0.5 * (1 - Input.mPosition.y + Viewport_inv_height);

//Output.mUV = Input.mUV;

return Output;

}

 

Pixel Shader

 

struct PS_INPUT

{

float2 mUV : TEXCOORD0;

float4 mPosition : POSITION;

};

 

sampler2D SceneSampler;

sampler2D FlareSampler;

sampler2D GlowSampler;

sampler2D StarGlowSampler1;

sampler2D StarGlowSampler2;

sampler2D StarGlowSampler3;

sampler2D StarGlowSampler4;

float FlareFactor;

float GlowFactor;

float StarGlowFactor;

 

 

float4 ps_main(PS_INPUT Input) : COLOR

{

float4 originColor = tex2D(SceneSampler, Input.mUV);

float4 flareColor = tex2D(FlareSampler, Input.mUV);

float4 glowColor = tex2D(GlowSampler, Input.mUV);

float4 StarGlowColor = tex2D(StarGlowSampler1, Input.mUV)+

tex2D(StarGlowSampler2, Input.mUV) + tex2D(StarGlowSampler3, Input.mUV) +

tex2D(StarGlowSampler4, Input.mUV);

float4 color = originColor + float4((glowColor*GlowFactor).rgb, 0.0);

color += float4((StarGlowColor*StarGlowFactor).rgb, 0.0);

color += float4((flareColor*FlareFactor).rgb, 0.0);

return color;

}

 

 

Contact Me

Using the contact form to send me email at below

Keep in touch with me

You can use the following information to contact me if anything need to communicate.

Name: Luke Lee (yongmin)