summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Subv2017-06-09 14:44:02 -0500
committerGravatar wwylele2017-07-11 19:39:15 +0300
commit46b8c8e1da6bc29df2662d63b0e028136fef3636 (patch)
tree99ed1cb8182ff798225b250077ed5c445e19f00c /src
parentSwRasterizer: Calculate specular_0 for fragment lighting. (diff)
downloadyuzu-46b8c8e1da6bc29df2662d63b0e028136fef3636.tar.gz
yuzu-46b8c8e1da6bc29df2662d63b0e028136fef3636.tar.xz
yuzu-46b8c8e1da6bc29df2662d63b0e028136fef3636.zip
SwRasterizer: Calculate specular_1 for fragment lighting.
Diffstat (limited to 'src')
-rw-r--r--src/video_core/swrasterizer/rasterizer.cpp62
1 files changed, 59 insertions, 3 deletions
diff --git a/src/video_core/swrasterizer/rasterizer.cpp b/src/video_core/swrasterizer/rasterizer.cpp
index 34b84b0af..e0c326a4a 100644
--- a/src/video_core/swrasterizer/rasterizer.cpp
+++ b/src/video_core/swrasterizer/rasterizer.cpp
@@ -148,8 +148,8 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(const Math::Qu
148 148
149 Math::Vec3<float> light_vector = {}; 149 Math::Vec3<float> light_vector = {};
150 Math::Vec4<float> diffuse_sum = {0.f, 0.f, 0.f, 1.f}; 150 Math::Vec4<float> diffuse_sum = {0.f, 0.f, 0.f, 1.f};
151 // TODO(Subv): Calculate specular
152 Math::Vec4<float> specular_sum = {0.f, 0.f, 0.f, 1.f}; 151 Math::Vec4<float> specular_sum = {0.f, 0.f, 0.f, 1.f};
152 Math::Vec3<float> refl_value = {};
153 153
154 for (unsigned light_index = 0; light_index <= lighting.max_light_index; ++light_index) { 154 for (unsigned light_index = 0; light_index <= lighting.max_light_index; ++light_index) {
155 unsigned num = lighting.light_enable.GetNum(light_index); 155 unsigned num = lighting.light_enable.GetNum(light_index);
@@ -253,8 +253,64 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(const Math::Qu
253 253
254 Math::Vec3<float> specular_0 = d0_lut_value * light_config.specular_0.ToVec3f(); 254 Math::Vec3<float> specular_0 = d0_lut_value * light_config.specular_0.ToVec3f();
255 255
256 // TODO(Subv): Specular 1 256 // If enabled, lookup ReflectRed value, otherwise, 1.0 is used
257 Math::Vec3<float> specular_1 = {}; 257 if (lighting.config1.disable_lut_rr == 0 &&
258 LightingRegs::IsLightingSamplerSupported(lighting.config0.config,
259 LightingRegs::LightingSampler::ReflectRed)) {
260
261 float index = GetLutIndex(num, lighting.lut_input.rr, lighting.abs_lut_input.disable_rr == 0);
262
263 float scale = lighting.lut_scale.GetScale(lighting.lut_scale.rr);
264
265 refl_value.x = scale * LookupLightingLut(static_cast<size_t>(LightingRegs::LightingSampler::ReflectRed), index);
266 } else {
267 refl_value.x = 1.0f;
268 }
269
270 // If enabled, lookup ReflectGreen value, otherwise, ReflectRed value is used
271 if (lighting.config1.disable_lut_rg == 0 &&
272 LightingRegs::IsLightingSamplerSupported(lighting.config0.config,
273 LightingRegs::LightingSampler::ReflectGreen)) {
274
275 float index = GetLutIndex(num, lighting.lut_input.rg, lighting.abs_lut_input.disable_rg == 0);
276
277 float scale = lighting.lut_scale.GetScale(lighting.lut_scale.rg);
278
279 refl_value.y = scale * LookupLightingLut(static_cast<size_t>(LightingRegs::LightingSampler::ReflectGreen), index);
280 } else {
281 refl_value.y = refl_value.x;
282 }
283
284 // If enabled, lookup ReflectBlue value, otherwise, ReflectRed value is used
285 if (lighting.config1.disable_lut_rb == 0 &&
286 LightingRegs::IsLightingSamplerSupported(lighting.config0.config,
287 LightingRegs::LightingSampler::ReflectBlue)) {
288
289 float index = GetLutIndex(num, lighting.lut_input.rb, lighting.abs_lut_input.disable_rb == 0);
290
291 float scale = lighting.lut_scale.GetScale(lighting.lut_scale.rb);
292
293 refl_value.z = scale * LookupLightingLut(static_cast<size_t>(LightingRegs::LightingSampler::ReflectBlue), index);
294 } else {
295 refl_value.z = refl_value.x;
296 }
297
298 float d1_lut_value = 1.0f;
299 if (lighting.config1.disable_lut_d1 == 0 &&
300 LightingRegs::IsLightingSamplerSupported(
301 lighting.config0.config, LightingRegs::LightingSampler::Distribution1)) {
302
303 // Lookup specular "distribution 1" LUT value
304 float index = GetLutIndex(num, lighting.lut_input.d1.Value(), lighting.abs_lut_input.disable_d1 == 0);
305
306 float scale = lighting.lut_scale.GetScale(lighting.lut_scale.d1);
307
308 d1_lut_value = scale * LookupLightingLut(static_cast<size_t>(LightingRegs::LightingSampler::Distribution1), index);
309 }
310
311 Math::Vec3<float> specular_1 = d1_lut_value * refl_value * light_config.specular_1.ToVec3f();
312
313 // TODO(Subv): Fresnel
258 314
259 auto diffuse = light_config.diffuse.ToVec3f() * dot_product + light_config.ambient.ToVec3f(); 315 auto diffuse = light_config.diffuse.ToVec3f() * dot_product + light_config.ambient.ToVec3f();
260 diffuse_sum += Math::MakeVec(diffuse * dist_atten, 0.0f); 316 diffuse_sum += Math::MakeVec(diffuse * dist_atten, 0.0f);