mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-11 15:21:51 +00:00
Add dynamic light to sprites
This commit is contained in:
parent
c6235fb674
commit
ef41e8e54e
3 changed files with 445 additions and 15 deletions
File diff suppressed because it is too large
Load diff
|
@ -130,6 +130,10 @@ namespace swrenderer
|
|||
__m128i shade_light = _mm_set_epi16(shade_constants.light_alpha, shade_constants.light_red, shade_constants.light_green, shade_constants.light_blue, shade_constants.light_alpha, shade_constants.light_red, shade_constants.light_green, shade_constants.light_blue);
|
||||
int desaturate = shade_constants.desaturate;
|
||||
<? } ?>
|
||||
|
||||
__m128i dynlight = _mm_cvtsi32_si128(args.DynamicLight());
|
||||
dynlight = _mm_unpacklo_epi8(dynlight, _mm_setzero_si128());
|
||||
dynlight = _mm_shuffle_epi32(dynlight, _MM_SHUFFLE(1,0,1,0));
|
||||
|
||||
int count = args.Count();
|
||||
int pitch = RenderViewport::Instance()->RenderTarget->GetPitch();
|
||||
|
@ -274,7 +278,9 @@ namespace swrenderer
|
|||
function Shade($blendVariant, $isSimpleShade)
|
||||
{
|
||||
if ($blendVariant == "copy" || $blendVariant == "shaded") return;
|
||||
|
||||
?>
|
||||
__m128i material = fgcolor;
|
||||
<?
|
||||
if ($isSimpleShade == true)
|
||||
{ ?>
|
||||
fgcolor = _mm_srli_epi16(_mm_mullo_epi16(fgcolor, mlight), 8);
|
||||
|
@ -297,8 +303,11 @@ namespace swrenderer
|
|||
fgcolor = _mm_mullo_epi16(fgcolor, mlight);
|
||||
fgcolor = _mm_srli_epi16(_mm_add_epi16(shade_fade, fgcolor), 8);
|
||||
fgcolor = _mm_srli_epi16(_mm_mullo_epi16(fgcolor, shade_light), 8);
|
||||
<? }
|
||||
}
|
||||
<? } ?>
|
||||
|
||||
fgcolor = _mm_add_epi16(fgcolor, _mm_srli_epi16(_mm_mullo_epi16(material, dynlight), 8));
|
||||
fgcolor = _mm_min_epi16(fgcolor, _mm_set1_epi16(255));
|
||||
<? }
|
||||
|
||||
function Blend($blendVariant)
|
||||
{
|
||||
|
|
|
@ -246,28 +246,41 @@ namespace swrenderer
|
|||
float ly = (float)(lightX * ViewTanCos + lightY * ViewTanSin - pos.Y);
|
||||
float lz = (float)(lightZ - pos.Z);
|
||||
|
||||
bool is_point_light = (node->lightsource->flags4 & MF4_ATTENUATE) != 0;
|
||||
// Attenuated lights disabled for sprites for now to keep consistency with the GL renderer
|
||||
//bool is_point_light = (node->lightsource->flags4 & MF4_ATTENUATE) != 0;
|
||||
float LdotL = lx * lx + ly * ly + lz * lz;
|
||||
float NdotL = is_point_light ? -ly : 0.0f;
|
||||
float NdotL = 1.0f;//is_point_light ? -ly : 1.0f;
|
||||
|
||||
float radius = node->lightsource->GetRadius();
|
||||
if (radius * radius >= LdotL && NdotL > 0.0f)
|
||||
{
|
||||
uint32_t red = light->GetRed();
|
||||
uint32_t green = light->GetGreen();
|
||||
uint32_t blue = light->GetBlue();
|
||||
float distance = sqrt(LdotL);
|
||||
float attenuation = distance / radius * NdotL;
|
||||
lit_red += red * attenuation;
|
||||
lit_red += green * attenuation;
|
||||
lit_red += blue * attenuation;
|
||||
float attenuation = (1.0f - distance / radius) * NdotL;
|
||||
if (attenuation > 0.0f)
|
||||
{
|
||||
float red = light->GetRed() * (1.0f / 255.0f);
|
||||
float green = light->GetGreen() * (1.0f / 255.0f);
|
||||
float blue = light->GetBlue() * (1.0f / 255.0f);
|
||||
/*if (light->IsSubtractive())
|
||||
{
|
||||
float bright = FVector3(lr, lg, lb).Length();
|
||||
FVector3 lightColor(lr, lg, lb);
|
||||
red = (bright - lr) * -1;
|
||||
green = (bright - lg) * -1;
|
||||
blue = (bright - lb) * -1;
|
||||
}*/
|
||||
|
||||
lit_red += red * attenuation;
|
||||
lit_green += green * attenuation;
|
||||
lit_blue += blue * attenuation;
|
||||
}
|
||||
}
|
||||
}
|
||||
node = node->nextLight;
|
||||
}
|
||||
lit_red = MIN(lit_red, 255.0f);
|
||||
lit_green = MIN(lit_green, 255.0f);
|
||||
lit_blue = MIN(lit_blue, 255.0f);
|
||||
lit_red = clamp(lit_red * 255.0f, 0.0f, 255.0f);
|
||||
lit_green = clamp(lit_green * 255.0f, 0.0f, 255.0f);
|
||||
lit_blue = clamp(lit_blue * 255.0f, 0.0f, 255.0f);
|
||||
vis->dynlightcolor = (((uint32_t)lit_red) << 16) | (((uint32_t)lit_green) << 8) | ((uint32_t)lit_blue);
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue