forked from suyu/suyu
SwRasterizer: Run clang-format
This commit is contained in:
parent
73566ff7a9
commit
2d69a9b8bf
1 changed files with 83 additions and 45 deletions
|
@ -125,11 +125,12 @@ float LookupLightingLut(size_t lut_index, u8 index, float delta) {
|
||||||
return lut_value + lut_diff * delta;
|
return lut_value + lut_diff * delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(const Math::Quaternion<float>& normquat, const Math::Vec3<float>& view) {
|
std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
|
||||||
|
const Math::Quaternion<float>& normquat, const Math::Vec3<float>& view) {
|
||||||
const auto& lighting = g_state.regs.lighting;
|
const auto& lighting = g_state.regs.lighting;
|
||||||
|
|
||||||
if (lighting.disable)
|
if (lighting.disable)
|
||||||
return {{}, {}};
|
return {Math::MakeVec<u8>(0, 0, 0, 0), Math::MakeVec<u8>(0, 0, 0, 0)};
|
||||||
|
|
||||||
// TODO(Subv): Bump mapping
|
// TODO(Subv): Bump mapping
|
||||||
Math::Vec3<float> surface_normal = {0.0f, 0.0f, 1.0f};
|
Math::Vec3<float> surface_normal = {0.0f, 0.0f, 1.0f};
|
||||||
|
@ -151,7 +152,9 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(const Math::Qu
|
||||||
unsigned num = lighting.light_enable.GetNum(light_index);
|
unsigned num = lighting.light_enable.GetNum(light_index);
|
||||||
const auto& light_config = g_state.regs.lighting.light[num];
|
const auto& light_config = g_state.regs.lighting.light[num];
|
||||||
|
|
||||||
Math::Vec3<float> position = {float16::FromRaw(light_config.x).ToFloat32(), float16::FromRaw(light_config.y).ToFloat32(), float16::FromRaw(light_config.z).ToFloat32()};
|
Math::Vec3<float> position = {float16::FromRaw(light_config.x).ToFloat32(),
|
||||||
|
float16::FromRaw(light_config.y).ToFloat32(),
|
||||||
|
float16::FromRaw(light_config.z).ToFloat32()};
|
||||||
|
|
||||||
if (light_config.config.directional)
|
if (light_config.config.directional)
|
||||||
light_vector = position;
|
light_vector = position;
|
||||||
|
@ -173,11 +176,13 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(const Math::Qu
|
||||||
auto distance = (-view - position).Length();
|
auto distance = (-view - position).Length();
|
||||||
float scale = Pica::float20::FromRaw(light_config.dist_atten_scale).ToFloat32();
|
float scale = Pica::float20::FromRaw(light_config.dist_atten_scale).ToFloat32();
|
||||||
float bias = Pica::float20::FromRaw(light_config.dist_atten_scale).ToFloat32();
|
float bias = Pica::float20::FromRaw(light_config.dist_atten_scale).ToFloat32();
|
||||||
size_t lut = static_cast<size_t>(LightingRegs::LightingSampler::DistanceAttenuation) + num;
|
size_t lut =
|
||||||
|
static_cast<size_t>(LightingRegs::LightingSampler::DistanceAttenuation) + num;
|
||||||
|
|
||||||
float sample_loc = scale * distance + bias;
|
float sample_loc = scale * distance + bias;
|
||||||
|
|
||||||
u8 lutindex = MathUtil::Clamp(std::floor(sample_loc * 256.f), 0.0f, 255.0f);
|
u8 lutindex =
|
||||||
|
static_cast<u8>(MathUtil::Clamp(std::floor(sample_loc * 256.f), 0.0f, 255.0f));
|
||||||
float delta = sample_loc * 256 - lutindex;
|
float delta = sample_loc * 256 - lutindex;
|
||||||
dist_atten = LookupLightingLut(lut, lutindex, delta);
|
dist_atten = LookupLightingLut(lut, lutindex, delta);
|
||||||
}
|
}
|
||||||
|
@ -216,7 +221,7 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(const Math::Qu
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
LOG_CRITICAL(HW_GPU, "Unknown lighting LUT input %d\n", (int)input);
|
LOG_CRITICAL(HW_GPU, "Unknown lighting LUT input %u\n", static_cast<u32>(input));
|
||||||
UNIMPLEMENTED();
|
UNIMPLEMENTED();
|
||||||
result = 0.f;
|
result = 0.f;
|
||||||
}
|
}
|
||||||
|
@ -227,14 +232,15 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(const Math::Qu
|
||||||
else
|
else
|
||||||
result = std::max(result, 0.0f);
|
result = std::max(result, 0.0f);
|
||||||
|
|
||||||
u8 lutindex = MathUtil::Clamp(std::floor(result * 256.f), 0.0f, 255.0f);
|
float flr = std::floor(result * 256.f);
|
||||||
|
u8 lutindex = static_cast<u8>(MathUtil::Clamp(flr, 0.0f, 255.0f));
|
||||||
float delta = result * 256 - lutindex;
|
float delta = result * 256 - lutindex;
|
||||||
return {lutindex, delta};
|
return {lutindex, delta};
|
||||||
} else {
|
} else {
|
||||||
float flr = std::floor(result * 128.f);
|
float flr = std::floor(result * 128.f);
|
||||||
s8 tmpi = MathUtil::Clamp(flr, -128.0f, 127.0f);
|
s8 lutindex = static_cast<u8>(MathUtil::Clamp(flr, -128.0f, 127.0f));
|
||||||
float delta = result * 128.f - tmpi;
|
float delta = result * 128.f - lutindex;
|
||||||
return { tmpi & 0xFF, delta };
|
return {static_cast<u8>(lutindex), delta};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -247,11 +253,15 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(const Math::Qu
|
||||||
// Lookup specular "distribution 0" LUT value
|
// Lookup specular "distribution 0" LUT value
|
||||||
u8 index;
|
u8 index;
|
||||||
float delta;
|
float delta;
|
||||||
std::tie(index, delta) = GetLutIndex(num, lighting.lut_input.d0.Value(), lighting.abs_lut_input.disable_d0 == 0);
|
std::tie(index, delta) = GetLutIndex(num, lighting.lut_input.d0.Value(),
|
||||||
|
lighting.abs_lut_input.disable_d0 == 0);
|
||||||
|
|
||||||
float scale = lighting.lut_scale.GetScale(lighting.lut_scale.d0);
|
float scale = lighting.lut_scale.GetScale(lighting.lut_scale.d0);
|
||||||
|
|
||||||
d0_lut_value = scale * LookupLightingLut(static_cast<size_t>(LightingRegs::LightingSampler::Distribution0), index, delta);
|
d0_lut_value =
|
||||||
|
scale *
|
||||||
|
LookupLightingLut(static_cast<size_t>(LightingRegs::LightingSampler::Distribution0),
|
||||||
|
index, delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
Math::Vec3<float> specular_0 = d0_lut_value * light_config.specular_0.ToVec3f();
|
Math::Vec3<float> specular_0 = d0_lut_value * light_config.specular_0.ToVec3f();
|
||||||
|
@ -263,11 +273,15 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(const Math::Qu
|
||||||
|
|
||||||
u8 index;
|
u8 index;
|
||||||
float delta;
|
float delta;
|
||||||
std::tie(index, delta) = GetLutIndex(num, lighting.lut_input.rr, lighting.abs_lut_input.disable_rr == 0);
|
std::tie(index, delta) =
|
||||||
|
GetLutIndex(num, lighting.lut_input.rr, lighting.abs_lut_input.disable_rr == 0);
|
||||||
|
|
||||||
float scale = lighting.lut_scale.GetScale(lighting.lut_scale.rr);
|
float scale = lighting.lut_scale.GetScale(lighting.lut_scale.rr);
|
||||||
|
|
||||||
refl_value.x = scale * LookupLightingLut(static_cast<size_t>(LightingRegs::LightingSampler::ReflectRed), index, delta);
|
refl_value.x =
|
||||||
|
scale *
|
||||||
|
LookupLightingLut(static_cast<size_t>(LightingRegs::LightingSampler::ReflectRed),
|
||||||
|
index, delta);
|
||||||
} else {
|
} else {
|
||||||
refl_value.x = 1.0f;
|
refl_value.x = 1.0f;
|
||||||
}
|
}
|
||||||
|
@ -279,11 +293,15 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(const Math::Qu
|
||||||
|
|
||||||
u8 index;
|
u8 index;
|
||||||
float delta;
|
float delta;
|
||||||
std::tie(index, delta) = GetLutIndex(num, lighting.lut_input.rg, lighting.abs_lut_input.disable_rg == 0);
|
std::tie(index, delta) =
|
||||||
|
GetLutIndex(num, lighting.lut_input.rg, lighting.abs_lut_input.disable_rg == 0);
|
||||||
|
|
||||||
float scale = lighting.lut_scale.GetScale(lighting.lut_scale.rg);
|
float scale = lighting.lut_scale.GetScale(lighting.lut_scale.rg);
|
||||||
|
|
||||||
refl_value.y = scale * LookupLightingLut(static_cast<size_t>(LightingRegs::LightingSampler::ReflectGreen), index, delta);
|
refl_value.y =
|
||||||
|
scale *
|
||||||
|
LookupLightingLut(static_cast<size_t>(LightingRegs::LightingSampler::ReflectGreen),
|
||||||
|
index, delta);
|
||||||
} else {
|
} else {
|
||||||
refl_value.y = refl_value.x;
|
refl_value.y = refl_value.x;
|
||||||
}
|
}
|
||||||
|
@ -295,11 +313,15 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(const Math::Qu
|
||||||
|
|
||||||
u8 index;
|
u8 index;
|
||||||
float delta;
|
float delta;
|
||||||
std::tie(index, delta) = GetLutIndex(num, lighting.lut_input.rb, lighting.abs_lut_input.disable_rb == 0);
|
std::tie(index, delta) =
|
||||||
|
GetLutIndex(num, lighting.lut_input.rb, lighting.abs_lut_input.disable_rb == 0);
|
||||||
|
|
||||||
float scale = lighting.lut_scale.GetScale(lighting.lut_scale.rb);
|
float scale = lighting.lut_scale.GetScale(lighting.lut_scale.rb);
|
||||||
|
|
||||||
refl_value.z = scale * LookupLightingLut(static_cast<size_t>(LightingRegs::LightingSampler::ReflectBlue), index, delta);
|
refl_value.z =
|
||||||
|
scale *
|
||||||
|
LookupLightingLut(static_cast<size_t>(LightingRegs::LightingSampler::ReflectBlue),
|
||||||
|
index, delta);
|
||||||
} else {
|
} else {
|
||||||
refl_value.z = refl_value.x;
|
refl_value.z = refl_value.x;
|
||||||
}
|
}
|
||||||
|
@ -312,30 +334,40 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(const Math::Qu
|
||||||
// Lookup specular "distribution 1" LUT value
|
// Lookup specular "distribution 1" LUT value
|
||||||
u8 index;
|
u8 index;
|
||||||
float delta;
|
float delta;
|
||||||
std::tie(index, delta) = GetLutIndex(num, lighting.lut_input.d1.Value(), lighting.abs_lut_input.disable_d1 == 0);
|
std::tie(index, delta) = GetLutIndex(num, lighting.lut_input.d1.Value(),
|
||||||
|
lighting.abs_lut_input.disable_d1 == 0);
|
||||||
|
|
||||||
float scale = lighting.lut_scale.GetScale(lighting.lut_scale.d1);
|
float scale = lighting.lut_scale.GetScale(lighting.lut_scale.d1);
|
||||||
|
|
||||||
d1_lut_value = scale * LookupLightingLut(static_cast<size_t>(LightingRegs::LightingSampler::Distribution1), index, delta);
|
d1_lut_value =
|
||||||
|
scale *
|
||||||
|
LookupLightingLut(static_cast<size_t>(LightingRegs::LightingSampler::Distribution1),
|
||||||
|
index, delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
Math::Vec3<float> specular_1 = d1_lut_value * refl_value * light_config.specular_1.ToVec3f();
|
Math::Vec3<float> specular_1 =
|
||||||
|
d1_lut_value * refl_value * light_config.specular_1.ToVec3f();
|
||||||
|
|
||||||
if (lighting.config1.disable_lut_fr == 0 &&
|
if (lighting.config1.disable_lut_fr == 0 &&
|
||||||
LightingRegs::IsLightingSamplerSupported(
|
LightingRegs::IsLightingSamplerSupported(lighting.config0.config,
|
||||||
lighting.config0.config, LightingRegs::LightingSampler::Fresnel)) {
|
LightingRegs::LightingSampler::Fresnel)) {
|
||||||
|
|
||||||
// Lookup fresnel LUT value
|
// Lookup fresnel LUT value
|
||||||
u8 index;
|
u8 index;
|
||||||
float delta;
|
float delta;
|
||||||
std::tie(index, delta) = GetLutIndex(num, lighting.lut_input.fr.Value(), lighting.abs_lut_input.disable_fr == 0);
|
std::tie(index, delta) = GetLutIndex(num, lighting.lut_input.fr.Value(),
|
||||||
|
lighting.abs_lut_input.disable_fr == 0);
|
||||||
|
|
||||||
float scale = lighting.lut_scale.GetScale(lighting.lut_scale.fr);
|
float scale = lighting.lut_scale.GetScale(lighting.lut_scale.fr);
|
||||||
|
|
||||||
float lut_value = scale * LookupLightingLut(static_cast<size_t>(LightingRegs::LightingSampler::Fresnel), index, delta);
|
float lut_value =
|
||||||
|
scale *
|
||||||
|
LookupLightingLut(static_cast<size_t>(LightingRegs::LightingSampler::Fresnel),
|
||||||
|
index, delta);
|
||||||
|
|
||||||
// Enabled for difffuse lighting alpha component
|
// Enabled for diffuse lighting alpha component
|
||||||
if (lighting.config0.fresnel_selector == LightingRegs::LightingFresnelSelector::PrimaryAlpha ||
|
if (lighting.config0.fresnel_selector ==
|
||||||
|
LightingRegs::LightingFresnelSelector::PrimaryAlpha ||
|
||||||
lighting.config0.fresnel_selector == LightingRegs::LightingFresnelSelector::Both) {
|
lighting.config0.fresnel_selector == LightingRegs::LightingFresnelSelector::Both) {
|
||||||
diffuse_sum.a() *= lut_value;
|
diffuse_sum.a() *= lut_value;
|
||||||
}
|
}
|
||||||
|
@ -348,18 +380,26 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(const Math::Qu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto diffuse =
|
||||||
auto diffuse = light_config.diffuse.ToVec3f() * dot_product + light_config.ambient.ToVec3f();
|
light_config.diffuse.ToVec3f() * dot_product + light_config.ambient.ToVec3f();
|
||||||
diffuse_sum += Math::MakeVec(diffuse * dist_atten, 0.0f);
|
diffuse_sum += Math::MakeVec(diffuse * dist_atten, 0.0f);
|
||||||
|
|
||||||
specular_sum += Math::MakeVec((specular_0 + specular_1) * clamp_highlights * dist_atten, 0.f);
|
specular_sum +=
|
||||||
|
Math::MakeVec((specular_0 + specular_1) * clamp_highlights * dist_atten, 0.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
diffuse_sum += Math::MakeVec(lighting.global_ambient.ToVec3f(), 0.0f);
|
diffuse_sum += Math::MakeVec(lighting.global_ambient.ToVec3f(), 0.0f);
|
||||||
return {
|
|
||||||
Math::MakeVec<float>(MathUtil::Clamp(diffuse_sum.x, 0.0f, 1.0f) * 255, MathUtil::Clamp(diffuse_sum.y, 0.0f, 1.0f) * 255, MathUtil::Clamp(diffuse_sum.z, 0.0f, 1.0f) * 255, MathUtil::Clamp(diffuse_sum.w, 0.0f, 1.0f) * 255).Cast<u8>(),
|
return {Math::MakeVec<float>(MathUtil::Clamp(diffuse_sum.x, 0.0f, 1.0f) * 255,
|
||||||
Math::MakeVec<float>(MathUtil::Clamp(specular_sum.x, 0.0f, 1.0f) * 255, MathUtil::Clamp(specular_sum.y, 0.0f, 1.0f) * 255, MathUtil::Clamp(specular_sum.z, 0.0f, 1.0f) * 255, MathUtil::Clamp(specular_sum.w, 0.0f, 1.0f) * 255).Cast<u8>()
|
MathUtil::Clamp(diffuse_sum.y, 0.0f, 1.0f) * 255,
|
||||||
};
|
MathUtil::Clamp(diffuse_sum.z, 0.0f, 1.0f) * 255,
|
||||||
|
MathUtil::Clamp(diffuse_sum.w, 0.0f, 1.0f) * 255)
|
||||||
|
.Cast<u8>(),
|
||||||
|
Math::MakeVec<float>(MathUtil::Clamp(specular_sum.x, 0.0f, 1.0f) * 255,
|
||||||
|
MathUtil::Clamp(specular_sum.y, 0.0f, 1.0f) * 255,
|
||||||
|
MathUtil::Clamp(specular_sum.z, 0.0f, 1.0f) * 255,
|
||||||
|
MathUtil::Clamp(specular_sum.w, 0.0f, 1.0f) * 255)
|
||||||
|
.Cast<u8>()};
|
||||||
}
|
}
|
||||||
|
|
||||||
MICROPROFILE_DEFINE(GPU_Rasterization, "GPU", "Rasterization", MP_RGB(50, 50, 240));
|
MICROPROFILE_DEFINE(GPU_Rasterization, "GPU", "Rasterization", MP_RGB(50, 50, 240));
|
||||||
|
@ -554,19 +594,16 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve
|
||||||
};
|
};
|
||||||
|
|
||||||
Math::Quaternion<float> normquat{
|
Math::Quaternion<float> normquat{
|
||||||
{
|
{GetInterpolatedAttribute(v0.quat.x, v1.quat.x, v2.quat.x).ToFloat32(),
|
||||||
GetInterpolatedAttribute(v0.quat.x, v1.quat.x, v2.quat.x).ToFloat32(),
|
|
||||||
GetInterpolatedAttribute(v0.quat.y, v1.quat.y, v2.quat.y).ToFloat32(),
|
GetInterpolatedAttribute(v0.quat.y, v1.quat.y, v2.quat.y).ToFloat32(),
|
||||||
GetInterpolatedAttribute(v0.quat.z, v1.quat.z, v2.quat.z).ToFloat32()
|
GetInterpolatedAttribute(v0.quat.z, v1.quat.z, v2.quat.z).ToFloat32()},
|
||||||
},
|
|
||||||
GetInterpolatedAttribute(v0.quat.w, v1.quat.w, v2.quat.w).ToFloat32(),
|
GetInterpolatedAttribute(v0.quat.w, v1.quat.w, v2.quat.w).ToFloat32(),
|
||||||
};
|
};
|
||||||
|
|
||||||
Math::Vec3<float> fragment_position{
|
Math::Vec3<float> fragment_position{
|
||||||
GetInterpolatedAttribute(v0.view.x, v1.view.x, v2.view.x).ToFloat32(),
|
GetInterpolatedAttribute(v0.view.x, v1.view.x, v2.view.x).ToFloat32(),
|
||||||
GetInterpolatedAttribute(v0.view.y, v1.view.y, v2.view.y).ToFloat32(),
|
GetInterpolatedAttribute(v0.view.y, v1.view.y, v2.view.y).ToFloat32(),
|
||||||
GetInterpolatedAttribute(v0.view.z, v1.view.z, v2.view.z).ToFloat32()
|
GetInterpolatedAttribute(v0.view.z, v1.view.z, v2.view.z).ToFloat32()};
|
||||||
};
|
|
||||||
|
|
||||||
Math::Vec2<float24> uv[3];
|
Math::Vec2<float24> uv[3];
|
||||||
uv[0].u() = GetInterpolatedAttribute(v0.tc0.u(), v1.tc0.u(), v2.tc0.u());
|
uv[0].u() = GetInterpolatedAttribute(v0.tc0.u(), v1.tc0.u(), v2.tc0.u());
|
||||||
|
@ -685,7 +722,8 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve
|
||||||
Math::Vec4<u8> primary_fragment_color;
|
Math::Vec4<u8> primary_fragment_color;
|
||||||
Math::Vec4<u8> secondary_fragment_color;
|
Math::Vec4<u8> secondary_fragment_color;
|
||||||
|
|
||||||
std::tie(primary_fragment_color, secondary_fragment_color) = ComputeFragmentsColors(normquat, fragment_position);
|
std::tie(primary_fragment_color, secondary_fragment_color) =
|
||||||
|
ComputeFragmentsColors(normquat, fragment_position);
|
||||||
|
|
||||||
for (unsigned tev_stage_index = 0; tev_stage_index < tev_stages.size();
|
for (unsigned tev_stage_index = 0; tev_stage_index < tev_stages.size();
|
||||||
++tev_stage_index) {
|
++tev_stage_index) {
|
||||||
|
|
Loading…
Reference in a new issue