Skip to content

Instantly share code, notes, and snippets.

@Reputeless
Last active October 28, 2023 12:17
Show Gist options
  • Save Reputeless/dfaf66475840482f26e9d3406590b9ee to your computer and use it in GitHub Desktop.
Save Reputeless/dfaf66475840482f26e9d3406590b9ee to your computer and use it in GitHub Desktop.
# include <Siv3D.hpp>
void Main()
{
Window::Resize(1280, 720);
const ColorF backgroundColor = ColorF{ 0.4, 0.6, 0.8 }.removeSRGBCurve();
const Texture uvChecker{ U"example/texture/uv.png", TextureDesc::MippedSRGB };
const MSRenderTexture renderTexture{ Scene::Size(), TextureFormat::R8G8B8A8_Unorm_SRGB, HasDepth::Yes };
DebugCamera3D camera{ renderTexture.size(), 30_deg, Vec3{ 10, 16, -32 } };
while (System::Update())
{
camera.update(2.0);
Graphics3D::SetCameraTransform(camera);
Graphics3D::SetGlobalAmbientColor(ColorF{ 0.2 });
{
const ScopedRenderTarget3D target{ renderTexture.clear(backgroundColor) };
Plane{ 64 }.draw(uvChecker);
Box{ -8,2,0,4 }.draw(ColorF{ 0.8, 0.6, 0.4 }.removeSRGBCurve());
const double sphereY = (2 + Periodic::Jump0_1(2s) * 2);
Sphere{ 0, sphereY, 0,2 }.draw(ColorF{ 0.4, 0.8, 0.6 }.removeSRGBCurve());
Cylinder{ 8, 2, 0, 2, 4 }.draw(ColorF{ 0.6, 0.4, 0.8 }.removeSRGBCurve());
// 平面投影の影を描画
{
// 3D モデルを平面化する変換行列
const Mat4x4 shadowMatrix{ DirectX::XMMatrixShadow(SIMD_Float4{ 0, 1, 0, 0 }, SIMD_Float4{ Graphics3D::GetSunDirection(), 0 }) };
const Transformer3D t{ shadowMatrix };
// 深度バイアス
RasterizerState rasterizerState = RasterizerState::Default3D;
rasterizerState.depthBias = 300; // 床より少し浮かせる
const ScopedRenderStates3D rs{ rasterizerState, BlendState::Default2D, DepthStencilState::DepthTest };
const ColorF shadowColor = ColorF{ 0.0, 0.7 }.removeSRGBCurve();
Box{ -8,2,0,4 }.draw(shadowColor);
Sphere{ 0,sphereY,0,2 }.draw(shadowColor);
Cylinder{ 8, 2, 0, 2, 4 }.draw(shadowColor);
}
}
{
Graphics3D::Flush();
renderTexture.resolve();
Shader::LinearToScreen(renderTexture);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment