#include <acknex.h>
#include <default.c>
VIEW *pp_view = { layer = 2; flags = PROCESS_TARGET | CHILD; }
MATERIAL *mtl_2d_lights =
{
effect = "
//https://www.shadertoy.com/view/ttj3zd
float4x4 matProj;
const float4 vecTime;
const float4 vecViewPort;
float smoothObjectPadding = 0.33;
float flickerSpeedFactor = 2;
float iLights;
float4 vecLightPos[8];
float4 vecLightViewPos[8];
float4 vecLightDir[8];
float4 vecLightColor[8];
texture TargetMap;
sampler postTex = sampler_state
{
texture = <TargetMap>;
MinFilter = Point;
};
float4 FP(
in float2 inTex : TEXCOORD0,
in float2 inPos : VPOS) : COLOR
{
float3 color = tex2D(postTex, inTex).rgb;
float3 blurColor = float3(0.0, 0.0, 0.0);
float i = 0;
for(i = 0; i < iLights; i += 1.0)
{
// pointlights only
// checking only .w doesn't help to skip the sun
if(vecLightDir[i].x <= 0 && vecLightDir[i].y <= 0 && vecLightDir[i].z <= 0)
{
float4 clipSpacePos = mul(float4(vecLightViewPos[i].xyz, 1.0f), matProj);
float2 ndcSpacePos = clipSpacePos.xy / clipSpacePos.w;
float2 windowSpacePos = float2(1.0f + ndcSpacePos.x, 1.0f - ndcSpacePos.y) * vecViewPort.xy * 0.5f;
float4 clipSpaceOutterPoint = mul(float4(vecLightViewPos[i].x - vecLightPos[i].w, vecLightViewPos[i].yz, 1.0f), matProj);
float ndcSpaceOutterPoint = clipSpaceOutterPoint.x / clipSpaceOutterPoint.w;
float windowSpaceRadius = (ndcSpacePos.x - ndcSpaceOutterPoint) * vecViewPort.x * 0.5f;
float2 objectCenter = windowSpacePos.xy / vecViewPort.xy;
float2 uv = length(inPos - windowSpacePos);
float2 pos = uv - objectCenter;
float flickerTime = sin(vecTime.w * flickerSpeedFactor);
float min_size = windowSpaceRadius;
float max_size = windowSpaceRadius + 8;
float size = lerp(min_size, max_size, flickerTime);
float smoothSize = size * smoothObjectPadding;
float circleMix = smoothstep(size, size - smoothSize, length(pos));
blurColor.rgb = lerp(blurColor.rgb, color.rgb * vecLightColor[i].rgb, circleMix);
}
}
float4 fragColor = float4(blurColor, 1.0);
return fragColor;
}
technique
{
pass one
{
ZWriteEnable = False;
AlphaBlendEnable = False;
PixelShader = compile ps_3_0 FP();
}
}
";
}
action act_light()
{
set(my, PASSABLE);
vec_set(&my->blue, vector(128 + random(128), 128 + random(128), 128 + random(128)));
my->lightrange = 128;
}
void main()
{
video_mode = 10;
warn_level = 6;
sun_light = 0;
level_load("");
random_seed(0);
camera->arc = 90;
vec_set(&camera->x, vector(0, 300, 300));
vec_set(&camera->pan, vector(270, -45, 0));
pp_view->material = mtl_2d_lights;
camera->stage = pp_view;
ENTITY *ent = ent_create(CUBE_MDL, nullvector, NULL);
vec_set(&ent->scale_x, vector(64, 64, 0.01));
c_setminmax(ent);
int i = 0;
for(i = 0; i < 3; i++)
{
ent_create(CUBE_MDL, vector(-128 + (128 * i), 0, 16), act_light);
}
}