(Three.js)为什么网格物体收到错误的阴影?

时间:2019-07-14 07:30:27

标签: javascript three.js

假设阴影的底部没有被#pragma once #include <algorithm> #include <bitset> #include <cassert> #include <climits> #include <cstdint> #include <iterator> #include <iostream> #include <iomanip> #include <limits> #include <map> #include <string> #include <type_traits> namespace vpc { using u8 = std::uint8_t; using u16 = std::uint16_t; using u32 = std::uint32_t; using u64 = std::uint64_t; template<typename T> struct Register; using Reg8 = Register<u8>; using Reg16 = Register<u16>; using Reg32 = Register<u32>; using Reg64 = Register<u64>; template<typename T> struct Register { T value; T previous_value; std::bitset<sizeof(T)* CHAR_BIT> bits; Register() : value{ 0 }, previous_value{ 0 }, bits{ 0 } {} template<typename U, std::enable_if_t<(sizeof(U) > sizeof(T))>* = nullptr> explicit Register(const U val, const u8 idx = 0) : value{ static_cast<T>((val >> std::size(bits) * idx) & std::numeric_limits<std::make_unsigned_t<T>>::max()) }, previous_value{ 0 }, bits{ value } { constexpr u16 sizeT = sizeof(T); constexpr u16 sizeU = sizeof(U); assert((idx >= 0) && (idx <= ((sizeU / sizeT) - 1)) ); } template<typename U, std::enable_if_t<(sizeof(U) < sizeof(T))>* = nullptr> explicit Register(const U val, const u8 idx = 0) : value{ static_cast<T>((static_cast<T>(val) << sizeof(U)*CHAR_BIT*idx) & std::numeric_limits<std::make_unsigned_t<T>>::max()) }, previous_value{ 0 }, bits{ value } { constexpr u16 sizeT = sizeof(T); constexpr u16 sizeU = sizeof(U); assert((idx >= 0) && (idx <= ((sizeT / sizeU) - 1)) ); } template<typename U, std::enable_if_t<(sizeof(U) == sizeof(T))>* = nullptr> explicit Register(const U val, const u8 idx = 0) : value{ static_cast<T>( val ) }, previous_value{ 0 }, bits{ value } {} template<typename... Args> Register(Args... args) {} template<typename U> Register(const Register<U>& reg, const u8 idx = 0) : Register(reg.value, idx) {} void changeEndian() { T tmp = value; char* const p = reinterpret_cast<char*>(&tmp); for (size_t i = 0; i < sizeof(T) / 2; ++i) std::swap(p[i], p[sizeof(T) - i - 1]); bits = tmp; } Register& operator=(const Register& obj) { this->value = obj.value; this->previous_value = obj.previous_value; this->bits = obj.bits; return *this; } template<typename Lhs, typename Rhs> friend auto operator+(const Register<Lhs>& l, const Register<Rhs>& r); }; } // namespace vpc 照射的阴影

下面是我的一些代码:

已启用light2

shadowMap

renderer.shadowMap.enabled = true; renderer.shadowMap.type = THREE.PCFSoftShadowMap; 被放置在球体的顶部

light1

light1 = new THREE.PointLight( 0xffffff, 1.5, 100 ); light1.position.set( -30, 30, 0 ); light1.castShadow = true; 被放置在球体的底部

light2

然后添加红色球体

light2 = new THREE.PointLight( 0xffffff, 1.5, 100 );
light2.position.set( 30, -30, 0 );

此图像现在将向您显示我得到了什么以及如何修复阴影?
wrong shadow image

three.js r.106
谢谢

0 个答案:

没有答案