UE2 - UT2kX Lens Flares in Skybox

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

forrestmark9

New Member
Aug 6, 2009
56
0
0
I've been trying to get lens-flares to work correctly in skyboxes but so far nothing works, it works fine if the light is directly in the map itself but not if the light is in the skybox

Here's a pic of them working
https://dl.dropboxusercontent.com/u/52828637/WorkingFlares.png

Here's a pic of them not working
https://dl.dropboxusercontent.com/u/52828637/NonWorkingFlares.png

These lens flares are done via Canvas which is probably why they do not work, I sadly can't add the corona light directly to the map as you'd get the lens flares overlapping the planet and ring
 
Last edited by a moderator:

forrestmark9

New Member
Aug 6, 2009
56
0
0
I don't know what kind of code you are using there, but keep in mind that the skybox isn't viewed from the player, but from the SkyZoneInfo.

Hmm I see.

Here is the code I'm using, a friend found it for me from the BeyondUnreal wiki
Code:
//-----------------------------------------------------------
// FlareInteraction.
// Adds 1337 lens flares for lights w/ coronas.
// (c) 2002 jasonyu
//-----------------------------------------------------------
class FlareInteraction extends Interaction;
 
#exec OBJ LOAD FILE=..\Textures\HaloTC_LensFlares.utx
 
var Actor PlayerOwner;
const HLSMAX = 240;
const RGBMAX = 255;
 
event Initialized()
{
	PlayerOwner = ViewportOwner.Actor;
	log("Lensflare interaction initialized.");
}
 
// adapted from:
// http://plaza27.mbn.or.jp/~satomii/design/win32/hls2rgb.html
final simulated function float HueToRGB(float n1, float n2, float hue)
{
	if ( hue < 0 ) hue += HLSMAX;
	if ( hue > HLSMAX ) hue -= HLSMAX;
 
	/* return r,g, or b value from this tridrant */
	if ( hue < (HLSMAX/6) )
		return ( n1 + (((n2-n1)*hue + (HLSMAX/12))/(HLSMAX/6)) );
	if ( hue < (HLSMAX/2) )
		return n2;
	if ( hue < ((HLSMAX*2)/3) )
		return ( n1 + (((n2-n1)*(((HLSMAX*2)/3)-hue) + (HLSMAX/12))/(HLSMAX/6)) );
	else
		return n1;
}
 
final simulated function Color hls2rgb(byte hue, byte lum, byte sat)
{
	local Color C;
	local float Magic1, Magic2;
	local int R,G,B;
 
	if ( sat==0)
	{     /* achromatic case */
		C.R = (lum*RGBMAX) / HLSMAX;
		C.G = C.R;
		C.B = C.R;
	}
	else
	{       /* chromatic case */
		/* set up magic numbers */
		if (lum <= (HLSMAX/2))
			Magic2 = (lum*(HLSMAX+sat)+(HLSMAX/2)) / HLSMAX;
		else
			Magic2 = lum+sat - ((lum*sat)+(HLSMAX/2)) / HLSMAX;
 
		Magic1 = 2*lum - Magic2;
 
		/* get RGB, change units from HLSMAX to RGBMAX */
		R = (HueToRGB(Magic1, Magic2, hue+(HLSMAX/3))
				* RGBMAX + (HLSMAX/2)) / HLSMAX;
		G = (HueToRGB(Magic1, Magic2, hue)
				* RGBMAX + (HLSMAX/2)) / HLSMAX;
 
		B = (HueToRGB(Magic1, Magic2, hue-(HLSMAX/3))
				* RGBMAX + (HLSMAX/2)) / HLSMAX;
	}
 
	C.R = R;
	C.G = G;
	C.B = B;
	C.A = 255;
	return C;
}
 
// adapted from:
// http://www.gamedev.net/reference/articles/article813.asp
simulated function PostRender( canvas Canvas )
{
	local Light Other;
	local float Dist;
	local Vector X,Y,Z, Dir;
 
	local Vector V, C, L;
	local float Length;
	local float ScaleX, ScaleY;
 
 
	if ( ViewportOwner.Actor.Pawn != None ) PlayerOwner = ViewportOwner.Actor.Pawn;
	else PlayerOwner = ViewportOwner.Actor;
 
	if ( PlayerOwner != None )
	{
		ScaleX = Canvas.SizeX / 640.0;
		ScaleY = Canvas.SizeY / 480.0;
 
		C.X = Canvas.ClipX/2;
		C.Y = Canvas.ClipY/2;
		GetAxes(PlayerOwner.Rotation, X,Y,Z);
		ForEach PlayerOwner.RadiusActors(class'Light', Other, 2000)
		{
			Dir = Other.Location - PlayerOwner.Location;
			Dist = VSize(Dir);
			Dir = Dir/Dist;
 
			// find an appropriate light source (bright, in FOV)
			if ( (Dir Dot X) > 0.7 && Other.bCorona &&
				(
				(PlayerOwner.IsA('Pawn') &&  Pawn(PlayerOwner).LineOfSightTo(Other) ) ||
				(PlayerOwner.IsA('Controller') && Controller(PlayerOwner).LineOfSightTo(Other) )
				) &&
				Other.LightRadius >= 64 && Other.DrawScale > 0.2 )
			{
				//Convert 3d location to 2d for display on the Canvas
				L = WorldToScreen(Other.location);
 
				V.X = L.X - C.X;
				V.Y = L.Y - C.Y;
				Length = VSize(V);
				V = Normal(V);
 
				Canvas.Style = PlayerOwner.ERenderStyle.STY_Additive;
 
				// tint the corona textures to match the hue of the light
				Canvas.DrawColor = hls2rgb(Other.LightHue, 15, 75);
 
				// place flares along directional vector
				Canvas.SetPos( (V.X*Length*1.2)-32*ScaleX+C.X, (V.Y*Length*1.2)-32*ScaleY+C.Y );
				Canvas.DrawTile(Texture'flares_generic_bitmap_2', 64*ScaleX,64*ScaleY,0.0, 0.0, 32, 32);
 
				Canvas.SetPos( (V.X*Length)-32*ScaleX+C.X, (V.Y*Length)-32*ScaleY+C.Y );
				Canvas.DrawTile(Texture'flares_generic_bitmap_3', 64*ScaleX,64*ScaleY,0.0, 0.0, 16, 16);
 
				Canvas.SetPos( (V.X*Length*0.66)-64*ScaleX+C.X, (V.Y*Length*0.66)-64*ScaleY+C.Y );
				Canvas.DrawTile(Texture'flares_generic_bitmap_4', 128*ScaleX,128*ScaleY,0.0, 0.0, 32, 32);
 
				Canvas.SetPos( (V.X*Length*0.33)-64*ScaleX+C.X, (V.Y*Length*0.33)-64*ScaleY+C.Y );
				Canvas.DrawTile(Texture'flares_generic_bitmap_5', 128*ScaleX,128*ScaleY,0.0, 0.0, 32, 32);
 
				Canvas.SetPos( (V.X*Length*0.125)-64*ScaleX+C.X, (V.Y*Length*0.125)-64*ScaleY+C.Y );
				Canvas.DrawTile(Texture'flares_generic_bitmap_6', 128*ScaleX,128*ScaleY,0.0, 0.0, 16, 16);
 
				Canvas.SetPos( (V.X*Length*-0.21)-64*ScaleX+C.X, (V.Y*Length*-0.21)-64*ScaleY+C.Y );
				Canvas.DrawTile(Texture'flares_generic_bitmap_7', 128*ScaleX,128*ScaleY,0.0, 0.0, 64, 64);
 
				Canvas.SetPos( (V.X*Length*-0.30)-32*ScaleX+C.X, (V.Y*Length*-0.30)-32*ScaleY+C.Y );
				Canvas.DrawTile(Texture'flares_generic_bitmap_3', 64*ScaleX,64*ScaleY,0.0, 0.0, 16, 16);
 
				Canvas.SetPos( (V.X*Length*-0.5)-90*ScaleX+C.X, (V.Y*Length*-0.5)-90*ScaleY+C.Y );
				Canvas.DrawTile(Texture'flares_generic_bitmap_3', 180*ScaleX,180*ScaleY,0.0, 0.0, 16, 16);
			}
		}
	}
}
 
defaultproperties
{
   bVisible=true
   bActive=true
}
 
Last edited by a moderator:

Wormbo

Administrator
Staff member
Jun 4, 2001
5,913
36
48
Germany
www.koehler-homepage.de
That code definitely doesn't support skybox lights at all. As you know, the map's sky box is somewhere outside the playable area. The code only checks for lights with a corona and certain other parameters (reasonable size and radius) that is in the player's view and not blocked by geometry.

You'd have to extend the code to also consider skybox lights, and that's where the trouble starts. The problem is: You can't reliably test whether you can see a certain part of the skybox. Tracing only works in the skybox itself, but a trace from the player towards the perceived light location will end inside the playable area. If you hit a BSP surface, you can't figure out if that's a fake backdrop surface or not.
 

forrestmark9

New Member
Aug 6, 2009
56
0
0
That code definitely doesn't support skybox lights at all. As you know, the map's sky box is somewhere outside the playable area. The code only checks for lights with a corona and certain other parameters (reasonable size and radius) that is in the player's view and not blocked by geometry.

You'd have to extend the code to also consider skybox lights, and that's where the trouble starts. The problem is: You can't reliably test whether you can see a certain part of the skybox. Tracing only works in the skybox itself, but a trace from the player towards the perceived light location will end inside the playable area. If you hit a BSP surface, you can't figure out if that's a fake backdrop surface or not.

Interesting, so it's not entirely possible to do Lens Flares from the skybox in UE2? I suspected as much, I wish I could add the corona directly into the map.
 

Leo(T.C.K.)

I did something m0tarded and now I have read only access! :(
May 14, 2006
4,794
36
48
It might be possible, one guy (Daewon) made a code to make meshes not disapear at angle(in the original unreal engine this was issue with scaled up meshes/decorations etc) and a check for specific box-like radius and also supports viewports as well not just player. Something similar could be done with a corona and a similar bounding box but it will probably have to be quite complex.
 

forrestmark9

New Member
Aug 6, 2009
56
0
0
It might be possible, one guy (Daewon) made a code to make meshes not disapear at angle(in the original unreal engine this was issue with scaled up meshes/decorations etc) and a check for specific box-like radius and also supports viewports as well not just player. Something similar could be done with a corona and a similar bounding box but it will probably have to be quite complex.

I see, I'm not entirely sure what you're saying nor do I know how to do it