Jump to content
  • Advertisement
Sign in to follow this  
Migi0027

Flares not working as they should

This topic is 2109 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

Hi guys!

 

I've recently looked into flares and how to generate them but one issue came up.

 

f0tgdf.png

 

It should look somewhat similar to this:

 

fig12.jpg

 

Yeah, it's not working yet. My code is based on this awesome person: http://john-chapman-graphics.blogspot.co.uk/2013/02/pseudo-lens-flare.html

 

Generating the lens flares:

cbuffer FRAMEBUFF : register(b0) // Ignore these buffers
{
	float4 vTint;

	float fTexScale;
	float fBlurScale;
	float nSamples;
	float pad;
};

cbuffer BloomBuffer : register(b1)
{
	float BloomThreshold;
	float BloomSaturation;
	float BloomIntensity;
};

Texture2D t_dff : register(t0);
Texture1D t_lensColors : register(t1);
SamplerState ss;

struct VS_Output
{  
	float4 Pos : SV_POSITION;              
	float2 Tex : TEXCOORD0;
};

VS_Output VShader(uint id : SV_VertexID)
{
	VS_Output Output;
	Output.Tex = float2((id << 1) & 2, id & 2);
	Output.Pos = float4(Output.Tex * float2(2,-2) + float2(-1,1), 0, 1);

	return Output;
}

/*----------------------------------------------------------------------------*/
float4 textureDistorted(
	float2 texcoord, 
	float2 direction,
	float3 distortion 
) {
	return float4(
		t_dff.Sample(ss, texcoord + direction * distortion.r).r,
		t_dff.Sample(ss, texcoord + direction * distortion.g).g,
		t_dff.Sample(ss, texcoord + direction * distortion.b).b,
		1.0
	);
}

static int MAX_SAMPLES = 64;
static int uSamples = 8;

static float uDispersal = 0.25;
static float uHaloWidth = 1.0;
static float uDistortion = 1.0;

static float flareSamples_ = 8.0f;
static float flareDispersal_ = 0.3f;
static float flareHaloWidth_ = 0.6f;
static float flareDistortion_ = 1.5f;
static float flareScale_ = 0.05f;
static float flareBias_ = -3.5f;
static float flareBlurRadius_ = 24.0f;

float4 PShader(VS_Output input) : SV_TARGET
{
	float2 texcoord = -input.Tex + float2(1.0, 1.0); // flip texcoordoords
	float2 texelSize = 1.0 / float2(600, 800);
	
	float2 ghostVec = (float2(0.5, 0.5) - texcoord) * uDispersal;
	float2 haloVec = normalize(ghostVec) * uHaloWidth;
	
	float3 distortion = float3(-texelSize.x * uDistortion, 0.0, texelSize.x * uDistortion);

    // sample ghosts:
	float4 result = float4(0, 0, 0, 0);

	for (int i = 0; i < uSamples; ++i) {
		float2 offset = frac(texcoord + ghostVec * float(i));
		
		float weight = length(float2(0.5, 0.5) - offset) / length(float2(0.5, 0.5));
		weight = pow(1.0 - weight, 10.0);
	
		result += textureDistorted(
			offset,
			normalize(ghostVec),
			distortion
		) * weight;
	}
	
	result *= t_lensColors.Sample(ss, length(float2(0.5, 0.5) - texcoord) / length(float2(0.5, 0.5)));

//	sample halo:
	float weight = length(float2(0.5, 0.5) - frac(texcoord + haloVec)) / length(float2(0.5, 0.5));
	weight = pow(1.0 - weight, 10.0);
	result += textureDistorted(
		frac(texcoord + haloVec),
		normalize(ghostVec),
		distortion
	) * weight;
	
	return result;
}

So somehow the flares itself are being generated wrongly, but I'm not quite sure why, and I was hoping that you guys had an idea why this could be.

 

Thanks, as usual!

-MIGI0027

Share this post


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

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!