mitiru::render

Higher-level renderer built on top of `mitiru::gfx`. Sprite, mesh, particle, post-process, and 3D-scene rendering.

Higher-level renderer built on top of `mitiru::gfx`. Sprite, mesh, particle, post-process, and 3D-scene rendering.

NameKindItems
Screenclass92
GpuParticlestruct16
ParticleSimConstantsstruct8
ParticleRenderConstantsstruct5
IGpuParticleSystemclass12
ToneMapOperatorenum4
BokehShapeenum29
PSInputstruct2
PSInputstruct2
PSInputstruct2
PSInputstruct2
PSInputstruct2
SSAOConfigstruct5
SSAOPassclass8
HDRConfigstruct4
HDRToneMappingPassclass6
TAAConfigstruct3
TAAPassclass8
DoFConfigstruct7
DepthOfFieldPassclass7
BlendFuncenum5
AlphaBlendstruct7
Loopenum3
Directionenum4
LoopModestruct5
Transitionstruct8
KeyframeEntrystruct2
Keyframesstruct9
Pipeline2DResultstruct2
BillboardInstancestruct4
Billboard3Dclass7
BitmapFontclass3
Camera2Dclass13
Camera3Dclass29
ClusterLightstruct2
ClusterConfigstruct6
Clusterstruct2
ClusteredLightingclass9
CubeFaceenum7
Cubemapclass18
DecalConfigstruct3
Decalstruct4
VSInputstruct1
VSOutputstruct2
PSInputstruct2
PSOutputstruct2
DecalSystemclass30
VSInputstruct3
VSOutputstruct3
PSInputstruct3
VSInputstruct4
VSOutputstruct4
PSInputstruct4
VSInputstruct4
VSOutputstruct4
PSInputstruct8
DeferredPipelineclass16
PSInputstruct2
PSInputstruct2
DepthOfFieldConfigstruct7
DepthOfFieldEffectclass6
GlyphInfostruct6
FontDatastruct3
DxTextRendererclass4
Easingstruct17
PSInputstruct2
PSInputstruct2
FSRConfigstruct5
FSREffectclass5
FXAAQualityenum8
PSInputstruct2
FXAAConfigstruct4
FXAAPassclass10
FontAtlasclass5
AABBstruct2
Planestruct6
Frustumclass4
GBufferPixelstruct1
GBufferclass9
GameViewRTclass17
VoxelGIConfigstruct8
LightmapConfigstruct7
IrradianceSamplestruct1
GISystemclass22
GltfMaterialConverterclass3
GltfMeshPrimitivestruct3
GltfMeshDatastruct2
GltfMaterialDatastruct5
GltfSceneDatastruct5
SkinnedVertexstruct2
GpuSkinnerclass8
SpriteBlendModeenum4
SamplerModeenum7
VSInputstruct3
VSOutputstruct3
PSInputstruct3
GpuTexture2Dclass9
GpuSpriteBatchVertexstruct8
GpuSpriteBatchclass11
ShaderMode3Denum10
OutlineModeenum7
IRenderer3Dclass33
ImageLoaderclass6
InstancedRendererclass14
LODLevelstruct5
LODGroupstruct2
LODSelectionstruct2
LODConfigstruct4
LODObjectstruct2
LODManagerclass12
LightTypeenum3
Lightstruct9
Materialstruct8
Meshclass11
MeshCacheclass4
MeshBoundsstruct3
MeshNormalizerclass3
MipmapFilterModeenum2
MipmapConfigstruct3
MipmapGeneratorclass15
MultiLightSystemclass23
VertexWithTangentstruct3
NormalMapTexturestruct5
VSInputstruct5
VSOutputstruct7
PSInputstruct7
NormalMapHelperclass17
ObjVertexKeystruct4
ObjVertexKeyHashstruct2
CullAABBstruct2
CullResultstruct3
OcclusionCullerclass4
OffscreenRenderer3Dclass14
PBRMaterialstruct12
PBREnvironmentstruct5
PBRRendererclass79
VSInputstruct4
VSOutputstruct6
PSInputstruct6
PSInputstruct2
PSInputstruct2
VSOutputstruct2
PBRShaderSetstruct12
ParticleCollisionConfigstruct7
ParticleCollisionEventstruct2
ParticleCollisionStatsstruct4
CollisionParticlestruct4
CollisionEvent_GPUstruct6
ParticleCollisionResolverclass17
Particle3Dstruct5
ParticleEmitter3Dstruct9
ParticleSystem3Dclass8
RenderModeenum2
DrawCommand3Dstruct3
Pipeline3Dclass15
PostEffectsclass4
PostProcessManagerclass52
PSInputstruct2
PSInputstruct2
PSInputstruct2
PSInputstruct2
PSInputstruct2
PSInputstruct2
PSInputstruct2
PSInputstruct2
PSInputstruct8
ShaderBytecodestruct3
RenderPassstruct3
RenderGraphclass7
ValidationReportstruct7
RenderPipelineValidatorclass6
CullModeenum3
RenderState3Dstruct11
RenderTextureclass9
Renderer2Dclass16
Renderer2DBridgeConfigstruct3
Renderer2DBridgeclass24
Renderer3D_DX12class78
PSInputstruct2
PSInputstruct2
PSInputstruct2
SSAOConfigstruct5
SSAOPassclass9
Scene3Dclass8
ScenePlacerclass5
ScreenshotDatastruct9
ButtonStateenum4
NotificationTypeenum4
ArrowDirectionenum4
PanelStylestruct6
ButtonStylestruct5
CardStylestruct5
ProgressBarStylestruct3
PostProcessSettingsstruct8
ScreenEnhancedclass27
SdfTextRendererclass16
SdfShaderLogicstruct10
PSInputstruct3
SdfShaderParamsstruct3
SdfFontGpuclass11
ShaderLoaderclass6
DirectionalShadowConfigstruct6
DirectionalShadowclass6
ShadowMapConfigstruct4
ShadowMapclass12
ShadowMapConfig3Dstruct5
ShadowPass3Dclass19
ShadowFilterModeenum3
ShadowConfigstruct7
CascadeInfostruct9
CascadedShadowMapclass14
ShapeRendererclass12
Bonestruct4
AnimationKeyframestruct1
BoneTrackstruct2
AnimationClipstruct4
MorphTargetstruct3
Skeletonclass7
AnimationPlayer3Dclass6
Skyboxclass15
Triangle3Dstruct5
SoftwareRenderer3Dclass17
OctreeNodeclass5
GridPartition2Dclass6
SpritePivotenum12
Vertex3DSpritestruct2
QuadMeshstruct3
PopupAnimationstruct8
Sprite3DInstancestruct8
Sprite3DRendererclass5
AnimatorStateenum4
AnimatorDirectionenum2
SpriteFramestruct3
SpriteAnimationstruct5
SpriteAnimationSetclass6
SpriteSheetclass9
SpriteAnimatorclass20
SpriteAnimationBuilderclass7
SpriteAnimationCacheclass7
SpriteBatchclass14
SpriteRendererclass15
PackedSpritestruct3
PackResultstruct5
SpriteSheetPackerclass8
AsepriteParseResultstruct2
SpriteSheetParserclass2
Edgeenum4
PathCommandenum7
Colorstruct7
ColorStopstruct1
Gradientstruct10
Shadowstruct3
Cornersstruct5
Strokestruct1
StyleTransformstruct1
Stylestruct3
ZigzagStylestruct2
ShapeRectstruct1
ShapeCirclestruct2
ShapeEllipsestruct3
ShapeTrianglestruct3
ShapeLinestruct3
ShapeArcstruct4
ShapePiestruct4
ShapeRingstruct3
ShapePolygonstruct1
PathPointstruct1
ShapePathstruct6
StyledVertex2Dstruct2
StyledRectBatchclass7
StyledCircleBatchclass8
StyledShapeRendererclass14
SSSProfileenum8
PSInputstruct2
SSSConfigstruct4
SubsurfaceScatterEffectclass23
PSInputstruct2
PSInputstruct2
TAAConfigstruct2
TAAEffectclass8
Textureclass9
AtlasRegionstruct11
TextureAtlasclass10
TiledObjectstruct9
TiledObjectLayerstruct3
TiledMapResultstruct5
TiledMapLoaderclass1
TileFlipenum4
AutoTileNeighborenum14
TilesetConfigstruct9
AnimatedTilestruct3
AutoTileRulesstruct4
TilemapLayerstruct15
Tilemapstruct5
TilemapCollisionclass8
TilemapRendererclass21
ToonLightingConfigstruct7
ToonOutlineConfigstruct6
ToonConfigstruct2
ToonPipelineclass27
Transform2Dstruct24
SortedDrawCommandstruct2
TransparencySortclass2
TrueTypeRendererclass6
TrueTypeScreenRendererclass3
Vertex2Dstruct3
Vertex3Dstruct3
VisualPresetsstruct18
VolumetricConfigstruct6
FogConfigstruct4
PSInputstruct2
PSInputstruct2
VolumetricLightPassclass8
VolumetricFogPassclass8
WorldUITypeenum3
WorldUIElementstruct9
WorldUIclass35
Overlay2DVertexstruct3
OutlineDrawCommandstruct40
SSRConfigstruct4
PSInstruct2
SSRPassclass5
ParallaxConfigstruct3
SSSConfigstruct2
PSInstruct2
SSSPassclass5
TessellationConfigstruct3
VOutstruct3
HOutstruct3
HConststruct2
HOutstruct3
HConststruct2
DOutstruct3
TessellationShadersclass5
OITConfigstruct1
PSOutstruct2
PSInstruct2
OITPassclass7
GPUParticleConfigstruct4
GPUParticlestruct7
ComputeShaderParticlesclass6
VignetteConfigstruct3
VignettePassclass4
ChromaticAberrationConfigstruct1
ChromaticAberrationPassclass4
FilmGrainConfigstruct2
FilmGrainPassclass5
BloomConfigstruct3
BloomPassclass4
ColorGradingConfigstruct7
ColorGradingPassclass4
GaussianBlurConfigstruct2
GaussianBlurPassclass6
PostProcessConfigstruct8
PostProcessChainclass9
PostProcessPassclass12
PostProcessRTstruct5
FadeConfigstruct5
FadePassclass4
FrostGlassConfigstruct5
FrostGlassPassclass4
SdfOutlineEffectstruct2
SdfShadowEffectstruct4
SdfGlowEffectstruct2
SdfTextEffectstruct7
SdfGlyphInfostruct11
SdfFontMetricsstruct5
SdfFontAtlasclass27
SdfTextSizestruct2
SdfWrappedLinestruct9
Utf8Decoderclass4

Free functions and typedefs

inline void mitiru::validate::DrawCallValidator::attach(Screen& screen)
inline void mitiru::validate::DrawCallValidator::drawDebugOverlay(Screen& screen) const
class Screen 92
`using TtDrawFunc = void(*)(void* font, Screen& scr, float x, float y, std::string_view text, float fontSize, const sgc::Colorf& color);`
using TtMeasureFunc = sgc::Vec2f(*)(void* font, std::string_view text, float fontSize);
using SdfDrawFunc = TtDrawFunc;
using SdfMeasureFunc = TtMeasureFunc;
using Transform2D = render::Transform2D;
enum `TextAlignH` { Left, Center, Right }
enum `TextAlignV` { Top, Middle, Bottom }
enum `PatternType` { Checkerboard, HStripes, VStripes, DiagStripes, Dots }
explicit Screen(int width, int height) noexcept
void setPipeline(render::RenderPipeline2D* pipeline) noexcept
[[nodiscard]] render::RenderPipeline2D* pipeline() const noexcept
void setTrueTypeFont(void* font, TtDrawFunc drawFn, TtMeasureFunc measureFn) noexcept
[[nodiscard]] void* trueTypeFont() const noexcept
void setSdfFont(void* font, SdfDrawFunc drawFn, SdfMeasureFunc measureFn) noexcept
[[nodiscard]] void* sdfFont() const noexcept
void clearSdfFont() noexcept
void registerFont(const std::string& name, void* font, TtDrawFunc drawFn, TtMeasureFunc measureFn)
void setFont(const std::string& name)
void setValidator(validate::DrawCallValidator* validator) noexcept
[[nodiscard]] validate::DrawCallValidator* validator() const noexcept
void clear(const sgc::Colorf& color = sgc::Colorf{0.0f, 0.0f, 0.0f, 1.0f})
void drawStyledRect(const sgc::Rectf& rect, const render::Style& style)
void drawStyledCircle(const sgc::Vec2f& center, float radius, const render::Style& style)
void draw(const render::ShapeData& shape, const render::Style& style)
void drawZigzagEdge(const sgc::Rectf& rect, const render::ZigzagStyle& zs)
void drawScanlines(const sgc::Rectf& rect, float lineHeight, const sgc::Colorf& color)
void drawDashedLine(const sgc::Vec2f& from, const sgc::Vec2f& to, float thickness, float dashLen, float gapLen, const sgc::Colorf& color)
void drawRect(const sgc::Rectf& rect, const sgc::Colorf& color)
void drawRectFrame(const sgc::Rectf& rect, const sgc::Colorf& color, float thickness = 1.0f)
void drawRoundedRect(const sgc::Rectf& rect, const sgc::Colorf& color, float radius = 8.0f)
void drawRoundedRectFrame(const sgc::Rectf& rect, const sgc::Colorf& color, float radius = 8.0f, float thickness = 1.0f)
void drawPie(const sgc::Vec2f& center, float radius, float startAngle, float endAngle, const sgc::Colorf& color)
void drawArc(const sgc::Vec2f& center, float radius, float startAngle, float endAngle, const sgc::Colorf& color, float thickness = 2.0f)
void drawTriangle(const sgc::Vec2f& p0, const sgc::Vec2f& p1, const sgc::Vec2f& p2, const sgc::Colorf& color)
void drawCircle(const sgc::Vec2f& center, float radius, const sgc::Colorf& color)
void drawCircleFrame(const sgc::Vec2f& center, float radius, const sgc::Colorf& color, float thickness = 2.0f)
void drawLine(const sgc::Vec2f& from, const sgc::Vec2f& to, const sgc::Colorf& color, float thickness = 1.0f)
void drawText(const sgc::Vec2f& position, std::string_view text, const sgc::Colorf& color, float fontSize = 16.0f)
[[nodiscard]] sgc::Vec2f measureText(std::string_view text, float fontSize = 16.0f) const
[[nodiscard]] bool textFitsInRect(const sgc::Rectf& rect, const sgc::Vec2f& position, std::string_view text, float fontSize = 16.0f) const
void drawTextClipped(const sgc::Rectf& rect, std::string_view text, const sgc::Colorf& color, float fontSize = 16.0f, float padX = 0.0f, float padY = 0.0f)
void drawTextInRect(const sgc::Rectf& rect, std::string_view text, const sgc::Colorf& color, float fontSize = 16.0f, TextAlignH alignH = TextAlignH::Left, TextAlignV alignV = TextAlignV::Top, float padX = 4.0f, float padY = 2.0f)
void drawTextWrapped(const sgc::Rectf& rect, std::string_view text, const sgc::Colorf& color, float fontSize = 16.0f, float padX = 4.0f, float padY = 2.0f, float lineSpacing = 1.4f)
void drawTextHQ(const sgc::Vec2f& position, std::string_view text, const sgc::Colorf& color, float fontSize)
void drawPolygon(const std::vector<sgc::Vec2f>& points, const sgc::Colorf& color)
void drawEllipse(const sgc::Vec2f& center, float radiusX, float radiusY, const sgc::Colorf& color)
void drawRing(const sgc::Vec2f& center, float outerRadius, float innerRadius, const sgc::Colorf& color)
void drawGradientRectH(const sgc::Rectf& rect, const sgc::Colorf& leftColor, const sgc::Colorf& rightColor)
void drawGradientRect4(const sgc::Rectf& rect, const sgc::Colorf& topLeft, const sgc::Colorf& topRight, const sgc::Colorf& bottomRight, const sgc::Colorf& bottomLeft)
void drawRoundedRect4(const sgc::Rectf& rect, const sgc::Colorf& color, float tl, float tr, float br, float bl)
void drawRectRotated(const sgc::Rectf& rect, const sgc::Colorf& color, float angleDeg)
void drawTextWithShadow(const sgc::Rectf& rect, std::string_view text, const sgc::Colorf& color, float fontSize, const sgc::Colorf& shadowColor, float shadowOffsetX = 2.0f, float shadowOffsetY = 2.0f, TextAlignH alignH = TextAlignH::Center, TextAlignV alignV = TextAlignV::Middle)
void drawTextOutlined(const sgc::Rectf& rect, std::string_view text, const sgc::Colorf& color, const sgc::Colorf& outlineColor, float outlineWidth = 1.0f, float fontSize = 16.0f, TextAlignH alignH = TextAlignH::Center, TextAlignV alignV = TextAlignV::Middle)
void drawTextStrikethrough(const sgc::Rectf& rect, std::string_view text, const sgc::Colorf& color, float fontSize = 16.0f, TextAlignH alignH = TextAlignH::Left, TextAlignV alignV = TextAlignV::Middle)
void drawTextBold(const sgc::Rectf& rect, std::string_view text, const sgc::Colorf& color, float fontSize = 16.0f, TextAlignH alignH = TextAlignH::Left, TextAlignV alignV = TextAlignV::Middle)
void drawTextSpaced(const sgc::Vec2f& position, std::string_view text, const sgc::Colorf& color, float fontSize = 16.0f, float letterSpacing = 2.0f)
void drawGradientRect(const sgc::Rectf& rect, const sgc::Colorf& topColor, const sgc::Colorf& bottomColor)
void drawRectPattern(const sgc::Rectf& rect, PatternType pattern, float cellSize, const sgc::Colorf& color1, const sgc::Colorf& color2)
void drawInnerShadow(const sgc::Rectf& rect, const sgc::Colorf& shadowColor, float blurSize = 8.0f, float offsetX = 0.0f, float offsetY = 0.0f)
void drawFrostedRect(const sgc::Rectf& rect, const sgc::Colorf& tintColor, int layers = 3)
void drawRectPerspective(const sgc::Rectf& rect, const sgc::Colorf& color, bool vanishTop = true, float strength = 0.2f)
void drawRectPerspectiveGradient(const sgc::Rectf& rect, const sgc::Colorf& topColor, const sgc::Colorf& bottomColor, bool vanishTop = true, float strength = 0.2f)
void drawSprite(const render::Texture& texture, const sgc::Rectf& dstRect)
void drawPixelGrid(const sgc::Rectf& dest, const std::uint32_t* pixels, int pixelWidth, int pixelHeight)
void drawPixelGrid(const sgc::Rectf& dest, const std::uint32_t* pixels, int pixelWidth, int pixelHeight, render::PixelArtFilter filter)
void drawSprite(const render::Texture& texture, const sgc::Rectf& dstRect, const sgc::Colorf& tintColor)
void renderUI(const ui::UINode& root, const ui::UITheme& theme)
void pushClipRect(const sgc::Rectf& rect)
void popClipRect()
void setBlendMode(gfx::BlendMode mode)
void pushTransform(float tx = 0.0f, float ty = 0.0f, float sx = 1.0f, float sy = 1.0f)
void pushTransform(const Transform2D& t)
void pushRotation(float rad, float pivotX = 0.0f, float pivotY = 0.0f)
void popTransform()
[[nodiscard]] sgc::Rectf applyTransform(const sgc::Rectf& rect) const
[[nodiscard]] sgc::Vec2f applyTransform(const sgc::Vec2f& pos) const
template <typename Fn> void drawGroup(const sgc::Vec2f& position, float rotationDeg, Fn&& drawFn)
void present()
[[nodiscard]] int width() const noexcept
[[nodiscard]] int height() const noexcept
[[nodiscard]] int drawCallCount() const noexcept
void resetDrawCallCount() noexcept
[[nodiscard]] const sgc::Colorf& clearColor() const noexcept
void resize(int width, int height) noexcept
[[nodiscard]] render::SpriteBatch& spriteBatch() noexcept
[[nodiscard]] const render::SpriteBatch& spriteBatch() const noexcept
[[nodiscard]] render::ShapeRenderer& shapeRenderer() noexcept
[[nodiscard]] const render::ShapeRenderer& shapeRenderer() const noexcept
void enableSoftwareFramebuffer() noexcept
[[nodiscard]] bool hasSoftwareFramebuffer() const noexcept
[[nodiscard]] const std::vector<std::uint8_t>& pixels() const noexcept
[[nodiscard]] sgc::Colorf pixelAt(int x, int y) const noexcept
struct GpuParticle 16
float posX = 0
float posY = 0
float posZ = 0
float velX = 0
float velY = 0
float velZ = 0
float accelX = 0
float accelY = 0
float accelZ = 0
float colorR = 1
float colorG = 1
float colorB = 1
float colorA = 1
float size = 0.1f
float lifetime = 2
float age = 0
struct ParticleSimConstants 8
float deltaTime = 0
float gravityX = 0
float gravityY = -9.81f
float gravityZ = 0
float drag = 0.1f
std::uint32_t maxParticles = 0
std::uint32_t activeParticles = 0
float padding = 0
struct ParticleRenderConstants 5
sgc::Mat4f viewProjection
sgc::Vec3f cameraRight
float padding0 = 0
sgc::Vec3f cameraUp
float padding1 = 0
class IGpuParticleSystem 12
/// @brief デストラクタ virtual ~IGpuParticleSystem() = default
/// @brief エミッター設定を適用する /// @param emitter エミッター設定 virtual void setEmitter(const ParticleEmitter& emitter) = 0
/// @brief エミッター設定を取得する /// @return 現在のエミッター設定への参照 [[nodiscard]] virtual const ParticleEmitter& emitter() const noexcept = 0
/// @brief 個別パーティクルを放出する /// @param position 放出位置 /// @param velocity 初期速度 /// @param lifetime 寿命(秒) /// @param color 初期色 /// @param size 初期サイズ virtual void emit(const sgc::Vec3f& position, const sgc::Vec3f& velocity, float lifetime, const sgc::Colorf& color, float size) = 0
/// @brief エミッター設定に基づいてパーティクルを自動放出する /// @param dt デルタタイム(秒) virtual void emitFromEmitter(float dt) = 0
/// @brief バースト放出を行う /// @param count 放出数 virtual void burst(std::uint32_t count) = 0
/// @brief GPUシミュレーションを実行する(重力・抵抗・寿命減衰) /// @param dt デルタタイム(秒) virtual void update(float dt) = 0
/// @brief パーティクルをインスタンス描画する /// @param camera 描画に使用するカメラ virtual void render(const mitiru::render::Camera3D& camera) = 0
/// @brief アクティブパーティクル数を取得する /// @return 現在生存中のパーティクル数 [[nodiscard]] virtual std::uint32_t activeCount() const noexcept = 0
/// @brief 最大パーティクル数を取得する /// @return サポートする最大パーティクル数 [[nodiscard]] virtual std::uint32_t maxCount() const noexcept = 0
/// @brief 全パーティクルをクリアする virtual void clear() = 0
/// @brief システムが有効かどうかを判定する [[nodiscard]] virtual bool isValid() const noexcept = 0
enum ToneMapOperator 4
Reinhard = 0
ACES = 1
Uncharted2 = 2
Exposure = 3
enum BokehShape 29
Circle
Hexagon
`constexpr std::string_view PP_SSAO_PS = R"hlsl(
`constexpr std::string_view PP_SSAO_BLUR_PS = R"hlsl(
`constexpr std::string_view PP_HDR_TONEMAP_PS = R"hlsl(
`constexpr std::string_view PP_TAA_PS = R"hlsl(
`constexpr std::string_view PP_DOF_PS = R"hlsl(
Texture2D normalTexture : register(t1)
SamplerState pointSampler : register(s0)
cbuffer SSAOParams : register(b0)
float3 reconstructViewPos(float2 uv)
float rand2d(float2 co)
SamplerState pointSampler : register(s0)
cbuffer BlurParams : register(b0)
SamplerState linearSampler : register(s0)
cbuffer HDRParams : register(b0)
float3 reinhardTonemap(float3 c, float wp)
float3 acesFilmic(float3 x)
float3 uc2(float3 x)
float3 uncharted2Tonemap(float3 c, float wp)
float3 exposureTonemap(float3 c)
Texture2D historyTexture : register(t1)
Texture2D motionTexture : register(t2)
SamplerState linearSampler : register(s0)
cbuffer TAAParams : register(b0)
Texture2D depthTexture : register(t1)
SamplerState linearSampler : register(s0)
cbuffer DoFParams : register(b0)
float linearDepth(float d)
struct PSInput 2
float4 position : SV_POSITION
float2 texCoord : TEXCOORD0
struct PSInput 2
float4 position : SV_POSITION
float2 texCoord : TEXCOORD0
struct PSInput 2
float4 position : SV_POSITION
float2 texCoord : TEXCOORD0
struct PSInput 2
float4 position : SV_POSITION
float2 texCoord : TEXCOORD0
struct PSInput 2
float4 position : SV_POSITION
float2 texCoord : TEXCOORD0
struct SSAOConfig 5
float radius = 0.5f
float bias = 0.025f
float intensity = 1.0f
int kernelSize = 16
int blurPasses = 1
class SSAOPass : public PostProcessPass 8
template <typename T> using ComPtr = Microsoft::WRL::ComPtr<T>
SSAOPass( ID3D11Device* device, const ComPtr<ID3D11VertexShader>& fullscreenVS, const ComPtr<ID3D11SamplerState>& sampler, std::uint32_t screenW, std::uint32_t screenH)
void setConfig(const SSAOConfig& cfg) noexcept
void setProjection(const float* proj4x4, const float* invProj4x4) noexcept
void setNormalSRV(ID3D11ShaderResourceView* normalSRV) noexcept
void apply( ID3D11DeviceContext* context, ID3D11ShaderResourceView* inputSRV, ID3D11RenderTargetView* outputRTV, std::uint32_t screenW, std::uint32_t screenH) override
[[nodiscard]] std::string_view name() const noexcept override
[[nodiscard]] const SSAOConfig& config() const noexcept
struct HDRConfig 4
float exposure = 1.0f
ToneMapOperator op = ToneMapOperator::ACES
float whitePoint = 4.0f
float gamma = 2.2f
class HDRToneMappingPass : public PostProcessPass 6
template <typename T> using ComPtr = Microsoft::WRL::ComPtr<T>
HDRToneMappingPass( ID3D11Device* device, const ComPtr<ID3D11VertexShader>& fullscreenVS, const ComPtr<ID3D11SamplerState>& sampler)
void setConfig(const HDRConfig& cfg) noexcept
void apply( ID3D11DeviceContext* context, ID3D11ShaderResourceView* inputSRV, ID3D11RenderTargetView* outputRTV, std::uint32_t screenW, std::uint32_t screenH) override
[[nodiscard]] std::string_view name() const noexcept override
[[nodiscard]] const HDRConfig& config() const noexcept
struct TAAConfig 3
float blendFactor = 0.1f
float jitterScale = 1.0f
bool enabled = true
class TAAPass : public PostProcessPass 8
template <typename T> using ComPtr = Microsoft::WRL::ComPtr<T>
TAAPass( ID3D11Device* device, const ComPtr<ID3D11VertexShader>& fullscreenVS, const ComPtr<ID3D11SamplerState>& sampler, std::uint32_t screenW, std::uint32_t screenH)
void setConfig(const TAAConfig& cfg) noexcept
void setMotionVectorSRV( ID3D11ShaderResourceView* motionSRV) noexcept
[[nodiscard]] std::array<float, 2> getJitter( std::uint32_t frameIndex, std::uint32_t screenW, std::uint32_t screenH) const noexcept
void apply( ID3D11DeviceContext* context, ID3D11ShaderResourceView* inputSRV, ID3D11RenderTargetView* outputRTV, std::uint32_t screenW, std::uint32_t screenH) override
[[nodiscard]] std::string_view name() const noexcept override
[[nodiscard]] const TAAConfig& config() const noexcept
struct DoFConfig 7
float focusDistance = 10.0f
float aperture = 0.1f
float focalLength = 50.0f
float maxBlur = 8.0f
float nearPlane = 0.1f
float farPlane = 1000.0f
BokehShape bokehShape = BokehShape::Circle
class DepthOfFieldPass : public PostProcessPass 7
template <typename T> using ComPtr = Microsoft::WRL::ComPtr<T>
DepthOfFieldPass( ID3D11Device* device, const ComPtr<ID3D11VertexShader>& fullscreenVS, const ComPtr<ID3D11SamplerState>& sampler)
void setConfig(const DoFConfig& cfg) noexcept
void setDepthSRV( ID3D11ShaderResourceView* depthSRV) noexcept
void apply( ID3D11DeviceContext* context, ID3D11ShaderResourceView* inputSRV, ID3D11RenderTargetView* outputRTV, std::uint32_t screenW, std::uint32_t screenH) override
[[nodiscard]] std::string_view name() const noexcept override
[[nodiscard]] const DoFConfig& config() const noexcept
enum BlendFunc 5
Normal
Additive
Multiply
Screen
Overlay
struct AlphaBlend 7
[[nodiscard]] static constexpr float saturate(float v) noexcept
[[nodiscard]] static constexpr sgc::Colorf over( const sgc::Colorf& src, const sgc::Colorf& dst) noexcept
[[nodiscard]] static constexpr sgc::Colorf overWithAlpha( const sgc::Colorf& srcRgb, float alpha, const sgc::Colorf& dst) noexcept
[[nodiscard]] static constexpr sgc::Colorf premultiply( const sgc::Colorf& color) noexcept
[[nodiscard]] static constexpr sgc::Colorf unpremultiply( const sgc::Colorf& color) noexcept
[[nodiscard]] static constexpr sgc::Colorf blend( const sgc::Colorf& src, const sgc::Colorf& dst, BlendFunc func) noexcept
[[nodiscard]] static constexpr sgc::Colorf lerp( const sgc::Colorf& a, const sgc::Colorf& b, float t) noexcept
enum Loop 3
Once
Infinite
Count
enum Direction 4
Normal
Reverse
Alternate
AlternateReverse
struct LoopMode 5
Loop type = Loop::Once
int count = 1
static LoopMode once()
static LoopMode infinite()
static LoopMode times(int n)
struct Transition 8
float duration = 0.3f
float delay = 0.0f
Easing easing = Easing::ease()
void target(const Style& newTarget)
void update(float dt)
[[nodiscard]] const Style& current() const
[[nodiscard]] bool isAnimating() const
void reset(const Style& initial)
struct KeyframeEntry 2
float offset
Style style
struct Keyframes 9
std::vector<KeyframeEntry> frames
float duration = 1.0f
Direction direction = Direction::Normal
Easing easing = Easing::linear()
LoopMode loop = LoopMode::once()
[[nodiscard]] Style evaluate(float time) const
[[nodiscard]] bool isComplete(float time) const
[[nodiscard]] inline Pipeline2DResult createPipeline2DFor( gfx::IDevice* device, int screenWidth, int screenHeight)
[[nodiscard]] inline std::unique_ptr<IRenderer3D> createRenderer3DFor( gfx::IDevice* device, int screenWidth, int screenHeight, int windowWidth, int windowHeight)
struct Pipeline2DResult 2
std::optional<RenderPipeline2D> pipeline
std::shared_ptr<PostProcessManager> postProcess
struct BillboardInstance 4
sgc::Vec3f position
float width = 1.0f
float height = 1.0f
float rotation = 0.0f
class Billboard3D 7
Billboard3D()
void add(const BillboardInstance& instance)
void clear()
[[nodiscard]] sgc::Mat4f computeWorldMatrix(const BillboardInstance& bb, const Camera3D& camera) const noexcept
[[nodiscard]] const Mesh& quadMesh() const noexcept
[[nodiscard]] const std::vector<BillboardInstance>& instances() const noexcept
[[nodiscard]] std::size_t instanceCount() const noexcept
class BitmapFont 3
[[nodiscard]] static constexpr std::array<std::uint8_t, 8> glyph(char ch) noexcept
[[nodiscard]] static constexpr int textWidth(std::string_view text, int scale = 1) noexcept
[[nodiscard]] static constexpr int textHeight(int scale = 1) noexcept
class Camera2D 13
explicit Camera2D(float screenWidth = 1280.0f, float screenHeight = 720.0f) noexcept
void setPosition(const sgc::Vec2f& position) noexcept
[[nodiscard]] const sgc::Vec2f& position() const noexcept
void setZoom(float zoom) noexcept
[[nodiscard]] float zoom() const noexcept
void setRotation(float radians) noexcept
[[nodiscard]] float rotation() const noexcept
[[nodiscard]] sgc::Mat4f viewMatrix() const noexcept
[[nodiscard]] sgc::Vec2f screenToWorld(const sgc::Vec2f& screenPos) const noexcept
[[nodiscard]] sgc::Vec2f worldToScreen(const sgc::Vec2f& worldPos) const noexcept
void shake(float intensity, float duration) noexcept
void updateShake(float deltaTime) noexcept
void setScreenSize(float width, float height) noexcept
class Camera3D 29
Camera3D() noexcept = default
Camera3D(const sgc::Vec3f& position, const sgc::Vec3f& target, const sgc::Vec3f& up, float fov, float aspectRatio, float nearClip, float farClip) noexcept
void setPosition(const sgc::Vec3f& position) noexcept
[[nodiscard]] const sgc::Vec3f& position() const noexcept
void setTarget(const sgc::Vec3f& target) noexcept
[[nodiscard]] const sgc::Vec3f& target() const noexcept
void setUp(const sgc::Vec3f& up) noexcept
[[nodiscard]] const sgc::Vec3f& up() const noexcept
void setFov(float fov) noexcept
[[nodiscard]] float fov() const noexcept
void setAspectRatio(float ratio) noexcept
[[nodiscard]] float aspectRatio() const noexcept
void setNearClip(float nearClip) noexcept
[[nodiscard]] float nearClip() const noexcept
void setFarClip(float farClip) noexcept
[[nodiscard]] float farClip() const noexcept
void setOrthographic(bool ortho) noexcept
[[nodiscard]] bool isOrthographic() const noexcept
void setOrthoParams(float left, float right, float bottom, float top) noexcept
[[nodiscard]] sgc::Mat4f viewMatrix() const noexcept
[[nodiscard]] sgc::Mat4f projectionMatrix() const noexcept
[[nodiscard]] sgc::Mat4f viewProjectionMatrix() const noexcept
[[nodiscard]] sgc::Vec3f worldToScreen(const sgc::Vec3f& worldPos, float screenWidth, float screenHeight) const noexcept
[[nodiscard]] bool isInFront(const sgc::Vec3f& worldPos) const noexcept
[[nodiscard]] sgc::Vec3f forwardDirection() const noexcept
[[nodiscard]] sgc::Vec3f rightDirection() const noexcept
[[nodiscard]] sgc::Vec3f upDirection() const noexcept
void orbitAround(const sgc::Vec3f& orbitTarget, float yawRadians, float pitchRadians, float distance) noexcept
void lookDirection(float yawRadians, float pitchRadians) noexcept
struct ClusterLight 2
float radius = 10.0f
float intensity = 1.0f
struct ClusterConfig 6
int gridX = 16
int gridY = 9
int gridZ = 24
float nearPlane = 0.1f
float farPlane = 100.0f
int maxLightsPerCluster = 32
struct Cluster 2
int lightCount = 0
std::vector<int> lightIndices
class ClusteredLighting 9
void configure(const ClusterConfig& config)
void setLights(const std::vector<ClusterLight>& lights)
void addLight(const ClusterLight& light)
void buildClusters(const float viewMatrix[16], [[maybe_unused]] const float projMatrix[16], int screenWidth, int screenHeight)
[[nodiscard]] const Cluster& getCluster(int x, int y, int z) const
[[nodiscard]] int totalClusters() const noexcept
[[nodiscard]] int lightCount() const noexcept
[[nodiscard]] const ClusterConfig& config() const noexcept
void clearLights()
enum CubeFace : std::uint8_t 7
PosX = 0
NegX = 1
PosY = 2
NegY = 3
PosZ = 4
NegZ = 5
constexpr int kCubemapFaceCount = 6
class Cubemap 18
Cubemap() = default
explicit Cubemap(const std::array<Texture, kCubemapFaceCount>& faces) noexcept
[[nodiscard]] static Cubemap solid(int size, const sgc::Colorf& color) noexcept
[[nodiscard]] static Cubemap verticalGradient( int size, const sgc::Colorf& zenith, const sgc::Colorf& nadir) noexcept
[[nodiscard]] const Texture& face(CubeFace f) const noexcept
[[nodiscard]] const Texture& face(int index) const noexcept
[[nodiscard]] int faceSize() const noexcept
[[nodiscard]] bool valid() const noexcept
using DecalId = std::uint32_t;
`constexpr std::string_view DECAL_VS = R"hlsl(
`constexpr std::string_view DECAL_PS = R"hlsl(
VSOutput VSMain(VSInput input)
Texture2D normalTexture : register(t1)
Texture2D decalTexture : register(t2)
Texture2D decalNormalMap : register(t3)
SamplerState linearSampler : register(s0)
cbuffer CbDecalTransform : register(b0)
PSOutput PSMain(PSInput input)
struct DecalConfig 3
int maxDecals = 256
float fadeDuration = 3.0f
float defaultSize = 1.0f
struct Decal 4
std::string textureKey
std::string normalMapKey
float opacity = 1.0f
float fadeTime = 0.0f
struct VSInput 1
float3 Position : POSITION
struct VSOutput 2
float4 Position : SV_POSITION
float4 ScreenPos : TEXCOORD0
struct PSInput 2
float4 Position : SV_POSITION
float4 ScreenPos : TEXCOORD0
struct PSOutput 2
float4 Albedo : SV_TARGET0
float4 Normal : SV_TARGET1
class DecalSystem 30
template <typename T> using ComPtr = Microsoft::WRL::ComPtr<T>
DecalSystem() noexcept = default
void init(ID3D11Device* device, const DecalConfig& config = {})
[[nodiscard]] bool isInitialized() const noexcept
[[nodiscard]] DecalId addDecal(const Decal& decal)
void removeDecal(DecalId id)
void update(float dt)
[[nodiscard]] int decalCount() const noexcept
void render(ID3D11DeviceContext* context, ID3D11ShaderResourceView* depthSRV, ID3D11ShaderResourceView* normalSRV, const float viewProj[16], const float invViewProj[16])
`constexpr std::string_view DEFAULT_VS_2D = R"hlsl(
`constexpr std::string_view DEFAULT_PS_2D = R"hlsl(
`constexpr std::string_view SDF_RECT_VS = R"hlsl(
`constexpr std::string_view SDF_RECT_PS = R"hlsl(
`constexpr std::string_view SDF_CIRCLE_VS = R"hlsl(
`constexpr std::string_view SDF_CIRCLE_PS = R"hlsl(
VSOutput VSMain(VSInput input)
SamplerState sampler0 : register(s0)
cbuffer PSConstants : register(b0)
VSOutput VSMain(VSInput input)
// up to 8 stop colors (RGBA each) float4 gradientOffsetsPacked[2]
// type(0=solid,1=linear,2=radial), cos(angle), sin(angle), stopCount float4 strokeColor
/// @brief グラデーションオフセット配列から値を取得する float getGradientOffset(int idx)
/// @brief マルチストップグラデーションを評価する float4 sampleGradient(float t, int stopCount)
/// @brief 角丸矩形のSDF(符号付き距離関数) float roundedBoxSDF(float2 p, float2 halfSize, float4 radii)
VSOutput VSMain(VSInput input)
// up to 8 stop colors (RGBA each) float4 gradientOffsetsPacked[2]
// type(0=solid,1=linear,2=radial), cos(angle), sin(angle), stopCount float4 strokeColor
/// @brief グラデーションオフセット配列から値を取得する float getGradientOffset(int idx)
/// @brief マルチストップグラデーションを評価する float4 sampleGradient(float t, int stopCount)
/// @brief 楕円の近似SDF float ellipseSDF(float2 p, float2 halfSize)
struct VSInput 3
float2 position : POSITION
float2 texCoord : TEXCOORD0
float4 color : COLOR0
struct VSOutput 3
float4 position : SV_POSITION
float2 texCoord : TEXCOORD0
float4 color : COLOR0
struct PSInput 3
float4 position : SV_POSITION
float2 texCoord : TEXCOORD0
float4 color : COLOR0
struct VSInput 4
float2 position : POSITION
float2 localUV : TEXCOORD0
float4 color : COLOR0
float4 shapeRect : TEXCOORD1
struct VSOutput 4
float4 position : SV_POSITION
float2 localUV : TEXCOORD0
float4 color : COLOR0
float4 shapeRect : TEXCOORD1
struct PSInput 4
float4 position : SV_POSITION
float2 localUV : TEXCOORD0
float4 color : COLOR0
float4 shapeRect : TEXCOORD1
struct VSInput 4
float2 position : POSITION
float2 localUV : TEXCOORD0
float4 color : COLOR0
float4 shapeRect : TEXCOORD1
struct VSOutput 4
float4 position : SV_POSITION
float2 localUV : TEXCOORD0
float4 color : COLOR0
float4 shapeRect : TEXCOORD1
struct PSInput 8
float4 position : SV_POSITION
float2 localUV : TEXCOORD0
float4 color : COLOR0
float4 shapeRect : TEXCOORD1
constexpr const char* DEFAULT_VS_3D = R"hlsl( cbuffer CbTransform : register(b0) { float4x4 World; float4x4 View; float4x4 Projection; }; struct VSInput { float3 Position : POSITION; float3 Normal : NORMAL; float2 TexCoord : TEXCOORD0; float4 Color : COLOR0; }; struct VSOutput { float4 Position : SV_POSITION; float3 WorldPos : TEXCOORD0; float3 WorldNorm : TEXCOORD1; float2 TexCoord : TEXCOORD2; float4 Color : COLOR0; }; VSOutput VSMain(VSInput input) { VSOutput output; float4 worldPos = mul(float4(input.Position, 1.0), World); output.WorldPos = worldPos.xyz; output.WorldNorm = normalize(mul(input.Normal, (float3x3)World)); float4 viewPos = mul(worldPos, View); output.Position = mul(viewPos, Projection); output.TexCoord = input.TexCoord; output.Color = input.Color; return output; } )hlsl"
constexpr const char* DEFAULT_PS_3D = R"hlsl( cbuffer CbLighting : register(b1) { float3 LightDir; float _pad0; float3 LightColor; float _pad1; float3 AmbientColor; float _pad2; float3 CameraPos; float _pad3; float4 MaterialDiffuse; float4 MaterialSpecular; float MaterialShininess; float3 _pad4; }; struct PSInput { float4 Position : SV_POSITION; float3 WorldPos : TEXCOORD0; float3 WorldNorm : TEXCOORD1; float2 TexCoord : TEXCOORD2; float4 Color : COLOR0; }; float4 PSMain(PSInput input) : SV_TARGET { float3 N = normalize(input.WorldNorm); float3 L = normalize(-LightDir); float3 V = normalize(CameraPos - input.WorldPos); float3 R = reflect(-L, N); float3 ambient = AmbientColor * MaterialDiffuse.rgb; float NdotL = max(dot(N, L), 0.0); float3 diffuse = LightColor * MaterialDiffuse.rgb * NdotL; float3 H = normalize(L + V); float NdotH = max(dot(N, H), 0.0); float specFactor = pow(NdotH, MaterialShininess); float3 specular = LightColor * MaterialSpecular.rgb * specFactor; float3 finalColor = ambient + diffuse + specular; float alpha = MaterialDiffuse.a * input.Color.a; return float4(finalColor * input.Color.rgb, alpha); } )hlsl"
constexpr const char* UNLIT_VS_3D = R"hlsl( cbuffer CbTransform : register(b0) { float4x4 World; float4x4 View; float4x4 Projection; }; struct VSInput { float3 Position : POSITION; float3 Normal : NORMAL; float2 TexCoord : TEXCOORD0; float4 Color : COLOR0; }; struct VSOutput { float4 Position : SV_POSITION; float2 TexCoord : TEXCOORD0; float4 Color : COLOR0; }; VSOutput VSMain(VSInput input) { VSOutput output; float4 worldPos = mul(float4(input.Position, 1.0), World); float4 viewPos = mul(worldPos, View); output.Position = mul(viewPos, Projection); output.TexCoord = input.TexCoord; output.Color = input.Color; return output; } )hlsl"
constexpr const char* UNLIT_PS_3D = R"hlsl( struct PSInput { float4 Position : SV_POSITION; float2 TexCoord : TEXCOORD0; float4 Color : COLOR0; }; float4 PSMain(PSInput input) : SV_TARGET { return input.Color; } )hlsl"
class DeferredPipeline 16
DeferredPipeline() noexcept = default
void initialize(int width, int height, const ShadowMapConfig& shadowConfig = {})
[[nodiscard]] bool isInitialized() const noexcept
[[nodiscard]] const ShadowMap& shadowMap() const noexcept
[[nodiscard]] const GBuffer& gBuffer() const noexcept
void render(const Scene3D& scene, const Camera3D& camera, RenderTexture& output)
void setClearColor(const sgc::Colorf& color) noexcept
`constexpr std::string_view DOF_COC_PS = R"hlsl(
`constexpr std::string_view DOF_BLUR_PS = R"hlsl(
SamplerState pointClampSampler : register(s0)
cbuffer DofCoCParams : register(b0)
float linearizeDepth(float d)
Texture2D cocTexture : register(t1)
SamplerState linearClampSampler : register(s0)
SamplerState pointClampSampler : register(s1)
cbuffer DofBlurParams : register(b0)
struct PSInput 2
float4 position : SV_POSITION
float2 texCoord : TEXCOORD0
struct PSInput 2
float4 position : SV_POSITION
float2 texCoord : TEXCOORD0
struct DepthOfFieldConfig 7
float focusDistance = 5.0f
float aperture = 2.8f
float focalLength = 0.05f
float nearPlane = 0.1f
float farPlane = 100.0f
float maxCoCRadius = 10.0f
float blurScale = 1.0f
class DepthOfFieldEffect 6
template <typename T> using ComPtr = Microsoft::WRL::ComPtr<T>
void init(ID3D11Device* device, std::uint32_t screenW, std::uint32_t screenH)
void setDepthSRV( ID3D11ShaderResourceView* depthSRV) noexcept
void setConfig( const DepthOfFieldConfig& cfg) noexcept
[[nodiscard]] const DepthOfFieldConfig& config() const noexcept
void apply( ID3D11DeviceContext* context, ID3D11ShaderResourceView* inputSRV, ID3D11RenderTargetView* outputRTV, std::uint32_t screenW, std::uint32_t screenH)
struct GlyphInfo 6
char32_t codepoint = 0
float advance = 0.0f
float bearingX = 0.0f
float bearingY = 0.0f
float width = 0.0f
float height = 0.0f
struct FontData 3
std::string name
float size = 0.0f
std::map<char32_t, GlyphInfo> glyphs
class DxTextRenderer 4
void registerFont(const std::string& name, float size, const FontData& data)
[[nodiscard]] bool hasFont(const std::string& name) const
[[nodiscard]] sgc::Vec2f measureText(const std::string& text, float fontSize) const
void drawText(sgc::graphics::IRenderer2D& renderer, sgc::Vec2f pos, const std::string& text, float fontSize, sgc::graphics::Color color)
struct Easing 17
static Easing linear()
static Easing ease()
static Easing easeIn()
static Easing easeOut()
static Easing easeInOut()
static Easing cubicBezier(float x1, float y1, float x2, float y2)
[[nodiscard]] float evaluate(float t) const
`constexpr std::string_view FSR_EASU_PS = R"hlsl(
`constexpr std::string_view FSR_RCAS_PS = R"hlsl(
SamplerState linearClampSampler : register(s0)
SamplerState pointClampSampler : register(s1)
cbuffer EASUParams : register(b0)
// ── Lanczos2重み関数 ─────────────────────────── float lanczos2(float x)
// ── 輝度を計算する ───────────────────────────── float luminance(float3 c)
SamplerState pointClampSampler : register(s0)
cbuffer RCASParams : register(b0)
float luminance(float3 c)
struct PSInput 2
float4 position : SV_POSITION
float2 texCoord : TEXCOORD0
struct PSInput 2
float4 position : SV_POSITION
float2 texCoord : TEXCOORD0
struct FSRConfig 5
std::uint32_t inputWidth = 960
std::uint32_t inputHeight = 540
std::uint32_t outputWidth = 1920
std::uint32_t outputHeight = 1080
float sharpness = 0.5f
class FSREffect 5
template <typename T> using ComPtr = Microsoft::WRL::ComPtr<T>
void init(ID3D11Device* device, const FSRConfig& cfg)
void setConfig(const FSRConfig& cfg)
[[nodiscard]] const FSRConfig& config() const noexcept
void apply( ID3D11DeviceContext* context, ID3D11ShaderResourceView* inputSRV, ID3D11RenderTargetView* outputRTV)
enum FXAAQuality 8
Low
Medium
High
`constexpr std::string_view PP_FXAA_PS = R"hlsl(
SamplerState linearSampler : register(s0)
cbuffer FXAAParams : register(b0)
// ── 知覚輝度計算(緑チャネル重み付き) ────────────────── float FxaaLuma(float3 rgb)
// ── オフセットテクスチャサンプル ────────────────────── float3 FxaaTexOff(float2 uv, float2 offset)
struct PSInput 2
float4 position : SV_POSITION
float2 texCoord : TEXCOORD0
struct FXAAConfig 4
float subpixQuality = 0.75f
float edgeThreshold = 0.166f
float edgeThresholdMin = 0.0833f
[[nodiscard]] static FXAAConfig fromQuality( FXAAQuality quality) noexcept
class FXAAPass : public PostProcessPass 10
template <typename T> using ComPtr = Microsoft::WRL::ComPtr<T>
FXAAPass( ID3D11Device* device, const ComPtr<ID3D11VertexShader>& fullscreenVS, const ComPtr<ID3D11SamplerState>& sampler)
[[nodiscard]] static FXAAPass low( ID3D11Device* device, const ComPtr<ID3D11VertexShader>& fullscreenVS, const ComPtr<ID3D11SamplerState>& sampler)
[[nodiscard]] static FXAAPass medium( ID3D11Device* device, const ComPtr<ID3D11VertexShader>& fullscreenVS, const ComPtr<ID3D11SamplerState>& sampler)
[[nodiscard]] static FXAAPass high( ID3D11Device* device, const ComPtr<ID3D11VertexShader>& fullscreenVS, const ComPtr<ID3D11SamplerState>& sampler)
void setConfig(const FXAAConfig& cfg) noexcept
void setQuality( float subpixel, float edgeThreshold, float edgeThresholdMin) noexcept
void apply( ID3D11DeviceContext* context, ID3D11ShaderResourceView* inputSRV, ID3D11RenderTargetView* outputRTV, std::uint32_t screenW, std::uint32_t screenH) override
[[nodiscard]] std::string_view name() const noexcept override
[[nodiscard]] const FXAAConfig& config() const noexcept
class FontAtlas 5
[[nodiscard]] static Texture generate(int scale = 2)
[[nodiscard]] static constexpr int cellWidth(int scale = 2) noexcept
[[nodiscard]] static constexpr int cellHeight(int scale = 2) noexcept
static void glyphUV(char ch, int scale, float& outU0, float& outV0, float& outU1, float& outV1)
template <typename T> [[nodiscard]] std::vector<T> cullObjects( const std::vector<CullEntry<T>>& entries, const Frustum& frustum)
struct AABB 2
float minX = 0.0f, minY = 0.0f, minZ = 0.0f
float maxX = 0.0f, maxY = 0.0f, maxZ = 0.0f
struct Plane 6
float a = 0.0f
float b = 0.0f
float c = 0.0f
float d = 0.0f
void normalize() noexcept
[[nodiscard]] float distanceTo(float x, float y, float z) const noexcept
class Frustum 4
void extractFromViewProj(const float m[16]) noexcept
[[nodiscard]] bool isBoxVisible(const AABB& box) const noexcept
[[nodiscard]] bool isSphereVisible(float cx, float cy, float cz, float radius) const noexcept
[[nodiscard]] const std::array<Plane, 6>& planes() const noexcept
struct GBufferPixel 1
float depth = 1.0f
class GBuffer 9
GBuffer() noexcept = default
void initialize(int width, int height)
[[nodiscard]] bool isInitialized() const noexcept
void clear()
void writePixel(int x, int y, const GBufferPixel& pixel)
[[nodiscard]] const GBufferPixel& readPixel(int x, int y) const noexcept
[[nodiscard]] int width() const noexcept
[[nodiscard]] int height() const noexcept
[[nodiscard]] const std::vector<GBufferPixel>& pixels() const noexcept
class GameViewRT 17
bool create(ID3D11Device* device, std::uint32_t width, std::uint32_t height)
void release()
void beginCapture(ID3D11DeviceContext* ctx)
void endCapture(ID3D11DeviceContext* ctx)
[[nodiscard]] ID3D11ShaderResourceView* srv() const
[[nodiscard]] std::uint32_t width() const noexcept
[[nodiscard]] std::uint32_t height() const noexcept
inline glm::vec3 toGlm(const sgc::Vec3f& v)
inline glm::vec2 toGlm(const sgc::Vec2f& v)
inline glm::mat4 toGlm(const sgc::Mat4f& m)
inline void toHLSL(float dst[4][4], const glm::mat4& m)
inline void toColumnMajor(float dst[4][4], const glm::mat4& m)
inline glm::mat4 lookAt(const sgc::Vec3f& eye, const sgc::Vec3f& target, const sgc::Vec3f& up)
inline glm::mat4 perspective(float fovRadians, float aspect, float nearZ, float farZ)
inline glm::mat4 modelMatrix(const sgc::Vec3f& pos, const sgc::Vec3f& rot, const sgc::Vec3f& scale)
inline glm::mat4 orthographic(float left, float right, float bottom, float top, float nearZ, float farZ)
using BakeProgressCallback = std::function<void(float progress, const std::string& phase)>;
struct VoxelGIConfig 8
int resolution = 128
float worldSize = 50.0f
int maxBounces = 2
float coneSpread = 0.1f
float aoDistance = 5.0f
float indirectIntensity = 1.0f
bool enableSpecular = true
bool enableDiffuse = true
struct LightmapConfig 7
int textureSize = 1024
int samplesPerTexel = 64
int maxBounces = 3
float biasOffset = 0.001f
bool enableAO = true
bool enableDirectional = false
float aoRadius = 1.0f
struct IrradianceSample 1
float confidence = 0.0f
class GISystem 22
virtual ~GISystem() = default
GISystem(const GISystem&) = delete
GISystem& operator=(const GISystem&) = delete
virtual bool initVoxelGI(const VoxelGIConfig& config) = 0
virtual void updateVoxelGI(float deltaTime) = 0
virtual void revoxelize() = 0
virtual bool bake(const LightmapConfig& config, BakeProgressCallback callback = nullptr) = 0
virtual bool saveLightmap(const std::string& outputPath) const = 0
virtual bool loadLightmap(const std::string& inputPath) = 0
[[nodiscard]] virtual IrradianceSample getIrradiance( float worldX, float worldY, float worldZ) const = 0
[[nodiscard]] virtual bool isEnabled() const noexcept = 0
virtual void setEnabled(bool enabled) = 0
[[nodiscard]] inline float readFloat(const cgltf_accessor* accessor, cgltf_size index, cgltf_size component)
[[nodiscard]] inline sgc::Vec3f readVec3(const cgltf_accessor* accessor, cgltf_size index)
[[nodiscard]] inline sgc::Vec2f readVec2(const cgltf_accessor* accessor, cgltf_size index)
[[nodiscard]] inline uint32_t readIndex(const cgltf_accessor* accessor, cgltf_size index)
[[nodiscard]] inline sgc::Vec3f computeFlatNormal( const sgc::Vec3f& v0, const sgc::Vec3f& v1, const sgc::Vec3f& v2)
[[nodiscard]] inline GltfMeshPrimitive convertPrimitive(const cgltf_primitive& prim)
[[nodiscard]] inline std::optional<GltfSceneData> loadGltfFromMemory( const void* data, std::size_t size)
[[nodiscard]] inline std::optional<GltfSceneData> loadGltfSceneFromFile(const std::string& filePath)
[[nodiscard]] inline std::optional<Mesh> loadGltfMeshFromFile(const std::string& filePath)
[[nodiscard]] inline Material convertGltfMaterial(const GltfMaterialData& gltfMat)
class GltfMaterialConverter 3
[[nodiscard]] static Material convertPBR(const GltfMaterialData& gltf)
[[nodiscard]] static Material convertPBRForToon(const GltfMaterialData& gltf)
[[nodiscard]] static std::vector<Material> convertAll( const std::vector<GltfMaterialData>& gltfMaterials, bool toonMode = false)
struct GltfMeshPrimitive 3
std::vector<Vertex3D> vertices
std::vector<uint32_t> indices
int materialIndex = -1
struct GltfMeshData 2
std::string name
std::vector<GltfMeshPrimitive> primitives
struct GltfMaterialData 5
std::string name
float metallic = 0.0f
float roughness = 1.0f
std::string baseColorTexturePath
std::string normalTexturePath
struct GltfSceneData 5
std::vector<GltfMeshData> meshes
std::vector<GltfMaterialData> materials
inline constexpr int kMaxBones = 128
struct alignas(16) CbSkinning
constexpr const char* SKINNING_VS = R"hlsl( cbuffer CbTransform : register(b0) { float4x4 World; float4x4 View; float4x4 Projection; }; cbuffer CbSkinning : register(b3) { float4x4 BoneMatrices[128]; }; struct VSInput { float3 Position : POSITION; float3 Normal : NORMAL; float2 TexCoord : TEXCOORD0; float4 Color : COLOR0; uint4 BoneIndices : BLENDINDICES; float4 BoneWeights : BLENDWEIGHT; }; struct VSOutput { float4 Position : SV_POSITION; float3 WorldPos : TEXCOORD0; float3 WorldNorm : TEXCOORD1; float2 TexCoord : TEXCOORD2; float4 Color : COLOR0; }; VSOutput VSMain(VSInput input) { VSOutput output; // Apply up to 4 bone influences per vertex float4 skinnedPos = float4(0, 0, 0, 0); float3 skinnedNormal = float3(0, 0, 0); for (int i = 0; i < 4; i++) { float w = input.BoneWeights[i]; if (w > 0) { float4x4 bone = BoneMatrices[input.BoneIndices[i]]; skinnedPos += mul(bone, float4(input.Position, 1)) * w; skinnedNormal += mul((float3x3)bone, input.Normal) * w; } } float4 worldPos = mul(skinnedPos, World); output.WorldPos = worldPos.xyz; output.WorldNorm = normalize(mul(skinnedNormal, (float3x3)World)); float4 viewPos = mul(worldPos, View); output.Position = mul(viewPos, Projection); output.TexCoord = input.TexCoord; output.Color = input.Color; return output; } )hlsl"
struct SkinnedVertex 2
constexpr SkinnedVertex() noexcept = default
constexpr SkinnedVertex(const sgc::Vec3f& pos, const sgc::Vec3f& nrm, const sgc::Vec2f& uv, const sgc::Colorf& col, const std::array<uint32_t, 4>& indices, const std::array<float, 4>& weights) noexcept
class GpuSkinner 8
template <typename T> using ComPtr = Microsoft::WRL::ComPtr<T>
GpuSkinner() noexcept = default
[[nodiscard]] bool isInitialized() const noexcept
void init(ID3D11Device* device)
void updateBones(ID3D11DeviceContext* context, const sgc::Mat4f* matrices, size_t count)
void bindSkinning(ID3D11DeviceContext* context)
void unbindSkinning(ID3D11DeviceContext* context)
[[nodiscard]] ID3D11InputLayout* inputLayout() const noexcept
enum SpriteBlendMode : std::uint8_t 4
AlphaBlend
Additive
Multiply
None
enum SamplerMode : std::uint8_t 7
Bilinear
Point
Anisotropic
`constexpr std::string_view GPU_SPRITE_VS = R"hlsl(
`constexpr std::string_view GPU_SPRITE_PS = R"hlsl(
VSOutput VSMain(VSInput input)
SamplerState samp : register(s0)
struct VSInput 3
float2 position : POSITION
float2 texCoord : TEXCOORD0
float4 color : COLOR0
struct VSOutput 3
float4 position : SV_POSITION
float2 texCoord : TEXCOORD0
float4 color : COLOR0
struct PSInput 3
float4 position : SV_POSITION
float2 texCoord : TEXCOORD0
float4 color : COLOR0
class GpuTexture2D 9
template <typename T> using ComPtr = Microsoft::WRL::ComPtr<T>
GpuTexture2D() noexcept = default
[[nodiscard]] static GpuTexture2D createFromPixels( ID3D11Device* device, int width, int height, std::span<const std::uint8_t> pixels)
template <typename TextureT> [[nodiscard]] static GpuTexture2D createFromTexture( ID3D11Device* device, const TextureT& texture)
[[nodiscard]] static GpuTexture2D createWhitePixel( ID3D11Device* device)
[[nodiscard]] int width() const noexcept
[[nodiscard]] int height() const noexcept
[[nodiscard]] ID3D11ShaderResourceView* getSRV() const noexcept
[[nodiscard]] bool isValid() const noexcept
struct GpuSpriteBatchVertex 8
float x = 0.0f
float y = 0.0f
float u = 0.0f
float v = 0.0f
float r = 1.0f
float g = 1.0f
float b = 1.0f
float a = 1.0f
class GpuSpriteBatch 11
template <typename T> using ComPtr = Microsoft::WRL::ComPtr<T>
GpuSpriteBatch() noexcept = default
void init(ID3D11Device* device, int maxSprites = 4096)
void begin(ID3D11DeviceContext* context, float screenW, float screenH, SpriteBlendMode blendMode = SpriteBlendMode::AlphaBlend, SamplerMode samplerMode = SamplerMode::Bilinear)
void draw(ID3D11ShaderResourceView* textureSrv, float srcX, float srcY, float srcW, float srcH, float dstX, float dstY, float dstW, float dstH, float r, float g, float b, float a, float rotation = 0.0f)
void drawUV(ID3D11ShaderResourceView* textureSrv, float u0, float v0, float u1, float v1, float dstX, float dstY, float dstW, float dstH, float r, float g, float b, float a, float rotation = 0.0f)
void drawRect(float dstX, float dstY, float dstW, float dstH, float r, float g, float b, float a)
void end()
[[nodiscard]] bool isInitialized() const noexcept
[[nodiscard]] int flushCount() const noexcept
[[nodiscard]] const GpuTexture2D& whiteTexture() const noexcept
enum ShaderMode3D : uint8_t 10
Phong = 0
Toon
Unlit
Flat
Posterize
Halftone
Hatching
GradientMap
Silhouette
Watercolor
enum OutlineMode : int 7
DepthSobel = 0
DepthLaplacian = 1
DepthSobelNdotV = 2
ColorEdge = 3
DepthColorCombo = 4
Fresnel = 5
constexpr int OUTLINE_MODE_COUNT = 6
class IRenderer3D 33
virtual ~IRenderer3D() = default
[[nodiscard]] virtual bool isInitialized() const noexcept = 0
virtual void beginFrame(const sgc::Colorf& clearColor = {0.2f, 0.2f, 0.3f, 1.0f}) = 0
virtual void endFrame() = 0
virtual void setCamera(const Camera3D& camera) = 0
virtual void setLight(const Light& light) = 0
virtual void setLights(std::span<const Light> lights)
virtual void setUseMultiLight(bool )
[[nodiscard]] virtual bool useMultiLight() const noexcept
virtual void setSkybox(const Cubemap& )
virtual void setSkyboxEnabled(bool )
[[nodiscard]] virtual bool isSkyboxEnabled() const noexcept
virtual void setAmbientColor(const sgc::Colorf& )
[[nodiscard]] virtual sgc::Colorf ambientColor() const noexcept
virtual void drawMesh(const Mesh& mesh, const sgc::Mat4f& worldTransform, const Material& material = {}) = 0
virtual void resetFrameActive() noexcept = 0
[[nodiscard]] virtual bool isFrameActive() const noexcept = 0
[[nodiscard]] virtual int drawCallCount() const noexcept = 0
virtual void setShaderMode([[maybe_unused]] ShaderMode3D mode)
virtual void setOutlineEnabled(bool )
[[nodiscard]] virtual bool isOutlineEnabled() const noexcept
virtual void setOutlineMode(OutlineMode )
[[nodiscard]] virtual OutlineMode outlineMode() const noexcept
virtual void setTonemapExposure(float )
[[nodiscard]] virtual float tonemapExposure() const noexcept
virtual void setTonemapGamma(float )
[[nodiscard]] virtual float tonemapGamma() const noexcept
virtual void setOverlayScreen(const Screen* )
[[nodiscard]] virtual bool hasOverlaySupport() const noexcept
[[nodiscard]] virtual void* nativeCommandList() const noexcept
[[nodiscard]] virtual void* nativeDevice() const noexcept
[[nodiscard]] virtual void* nativeSwapChain() const noexcept
virtual void finalizeFrame()
class ImageLoader 6
[[nodiscard]] static Texture fromMemory(const std::uint8_t* data, int dataSize)
[[nodiscard]] static Texture fromFile(const std::string& path)
[[nodiscard]] static std::string lastError()
struct alignas(16) InstanceData
inline constexpr const char* kInstancedVS = R"hlsl( cbuffer CbViewProj : register(b0) { float4x4 viewProj; }; struct VSInput { // Per-vertex (slot 0) float3 position : POSITION; float3 normal : NORMAL; float2 texcoord : TEXCOORD; // Per-instance (slot 1) float4 instWorld0 : INST_WORLD0; float4 instWorld1 : INST_WORLD1; float4 instWorld2 : INST_WORLD2; float4 instWorld3 : INST_WORLD3; float4 instColor : INST_COLOR; float4 instCustom : INST_CUSTOM; }; struct PSInput { float4 position : SV_POSITION; float3 normal : NORMAL; float2 texcoord : TEXCOORD; float4 color : COLOR; float4 custom : CUSTOM; }; PSInput main(VSInput input) { PSInput output; float4x4 world = float4x4( input.instWorld0, input.instWorld1, input.instWorld2, input.instWorld3 ); float4 worldPos = mul(float4(input.position, 1.0), world); output.position = mul(worldPos, viewProj); output.normal = mul(float4(input.normal, 0.0), world).xyz; output.texcoord = input.texcoord; output.color = input.instColor; output.custom = input.instCustom; return output; } )hlsl"
inline constexpr const char* kInstancedPS = R"hlsl( struct PSInput { float4 position : SV_POSITION; float3 normal : NORMAL; float2 texcoord : TEXCOORD; float4 color : COLOR; float4 custom : CUSTOM; }; float4 main(PSInput input) : SV_TARGET { float3 lightDir = normalize(float3(0.3, -1.0, 0.5)); float ndotl = saturate(dot(normalize(input.normal), -lightDir)); float3 lit = input.color.rgb * (ndotl * 0.7 + 0.3); return float4(lit, input.color.a); } )hlsl"
class InstancedRenderer 14
template <typename T> using ComPtr = Microsoft::WRL::ComPtr<T>
InstancedRenderer() noexcept = default
[[nodiscard]] bool isInitialized() const noexcept
[[nodiscard]] std::uint32_t instanceCount() const noexcept
[[nodiscard]] std::uint32_t maxInstances() const noexcept
[[nodiscard]] int drawCallCount() const noexcept
[[nodiscard]] int totalInstancesDrawn() const noexcept
void init(ID3D11Device* device, ID3D11DeviceContext* context, std::uint32_t maxInstances = 10000)
void beginBatch(ID3D11DeviceContext* context, ID3D11Buffer* meshVertexBuffer, ID3D11Buffer* meshIndexBuffer, std::uint32_t indexCount)
void addInstance(const float worldMatrix[4][4], const float color[4])
void addInstance(const InstanceData& data)
void setViewProjection(const float viewProj[4][4])
void flush(ID3D11DeviceContext* context)
void resetStats() noexcept
struct LODLevel 5
Microsoft::WRL::ComPtr<ID3D11Buffer> vertexBuffer
Microsoft::WRL::ComPtr<ID3D11Buffer> indexBuffer
std::uint32_t indexCount = 0
float maxDistance = 0.0f
float transitionRange = 5.0f
struct LODGroup 2
std::vector<LODLevel> levels
std::uint32_t currentLevel = 0
struct LODSelection 2
std::uint32_t level = 0
float blendFactor = 0.0f
struct LODConfig 4
float bias = 0.0f
std::uint32_t maxLevel = 0
float crossFadeDuration = 0.5f
float hysteresis = 2.0f
struct LODObject 2
std::string groupId
std::uint32_t currentLevel = 0
class LODManager 12
LODManager() noexcept = default
[[nodiscard]] const LODConfig& config() const noexcept
void setConfig(const LODConfig& cfg) noexcept
void registerGroup(const std::string& id, std::vector<LODLevel> levels)
[[nodiscard]] bool hasGroup(const std::string& id) const
[[nodiscard]] const LODGroup& getGroup(const std::string& id) const
[[nodiscard]] const LODLevel& selectLOD( const std::string& groupId, const float cameraPos[3], const float objectPos[3]) const
[[nodiscard]] LODSelection selectLODSmooth( const std::string& groupId, const float cameraPos[3], const float objectPos[3])
void update(const float cameraPos[3], std::vector<LODObject>& objects)
[[nodiscard]] int lodTransitionCount() const noexcept
[[nodiscard]] int drawCallsSaved() const noexcept
void resetStats() noexcept
enum LightType 3
Directional
Point
Spot
struct Light 9
LightType type = LightType::Directional
float intensity = 1.0f
float range = 100.0f
float spotAngle = 45.0f
[[nodiscard]] static Light directional( const sgc::Vec3f& dir, const sgc::Colorf& col = {1.0f, 1.0f, 1.0f, 1.0f})
[[nodiscard]] static Light point( const sgc::Vec3f& pos, float lightRange = 100.0f, const sgc::Colorf& col = {1.0f, 1.0f, 1.0f, 1.0f})
[[nodiscard]] static Light spot( const sgc::Vec3f& pos, const sgc::Vec3f& dir, float angle = 45.0f, float lightRange = 100.0f, const sgc::Colorf& col = {1.0f, 1.0f, 1.0f, 1.0f})
struct alignas(16) LightEntryGpu
struct alignas(16) LightArrayCB
struct Material 8
float shininess = 32.0f
std::string diffuseTexturePath
std::string normalTexturePath
float metallic = 0.0f
float roughness = 1.0f
const Texture* albedoTexture = nullptr
[[nodiscard]] static Material defaultMaterial() noexcept
[[nodiscard]] std::string toJson() const
class Mesh 11
Mesh() noexcept = default
void setVertices(std::vector<Vertex3D> vertices)
void setIndices(std::vector<uint32_t> indices)
[[nodiscard]] std::size_t vertexCount() const noexcept
[[nodiscard]] std::size_t indexCount() const noexcept
[[nodiscard]] AABB computeAABB() const noexcept
[[nodiscard]] const std::vector<Vertex3D>& vertices() const noexcept
[[nodiscard]] const std::vector<uint32_t>& indices() const noexcept
[[nodiscard]] static Mesh createCube(float size = 1.0f)
[[nodiscard]] static Mesh createSphere(float radius = 0.5f, int segments = 16)
[[nodiscard]] static Mesh createPlane(float width = 1.0f, float height = 1.0f)
class MeshCache 4
MeshCache() = default
[[nodiscard]] const Mesh* loadMesh(const std::string& objPath)
void clear() noexcept
[[nodiscard]] std::size_t size() const noexcept
struct MeshBounds 3
[[nodiscard]] sgc::Vec3f center() const noexcept
[[nodiscard]] sgc::Vec3f size() const noexcept
[[nodiscard]] float maxDimension() const noexcept
class MeshNormalizer 3
[[nodiscard]] static MeshBounds computeBounds(const Mesh& mesh)
static void normalize(Mesh& mesh, float targetSize = 1.0f, bool centerXZ = true, bool bottomY0 = true)
static void convertZUpToYUp(Mesh& mesh)
enum MipmapFilterMode : std::uint8_t 2
Box
Lanczos
struct MipmapConfig 3
MipmapFilterMode filterMode = MipmapFilterMode::Box
std::uint32_t maxLevel = 0
std::uint32_t anisotropicLevel = 1
class MipmapGenerator 15
template <typename T> using ComPtr = Microsoft::WRL::ComPtr<T>
MipmapGenerator() noexcept = default
void generateMipmaps(ID3D11Device* device, ID3D11DeviceContext* context, ID3D11Texture2D* texture)
[[nodiscard]] ComPtr<ID3D11Texture2D> createTextureWithMipmaps( ID3D11Device* device, std::uint32_t width, std::uint32_t height, const void* pixels)
[[nodiscard]] ComPtr<ID3D11ShaderResourceView> createSRVWithMipmaps( ID3D11Device* device, ID3D11Texture2D* texture)
[[nodiscard]] ComPtr<ID3D11SamplerState> createAnisotropicSampler( ID3D11Device* device, std::uint32_t level)
[[nodiscard]] const MipmapConfig& config() const noexcept
void setConfig(const MipmapConfig& cfg) noexcept
[[nodiscard]] static std::uint32_t calculateMipLevels( std::uint32_t width, std::uint32_t height) noexcept
inline constexpr const char* MULTI_LIGHT_VS_3D = R"HLSL( cbuffer CbTransform : register(b0) { float4x4 world; float4x4 view; float4x4 projection; }; struct VSIn { float3 pos : POSITION; float3 normal : NORMAL; float2 uv : TEXCOORD0; float4 color : COLOR0; }; struct VSOut { float4 svpos : SV_POSITION; float3 worldPos : TEXCOORD0; float3 worldNrm : NORMAL; float2 uv : TEXCOORD1; float4 color : COLOR0; }; VSOut VSMain(VSIn i) { VSOut o; float4 wp = mul(float4(i.pos, 1.0), world); o.worldPos = wp.xyz; o.svpos = mul(mul(wp, view), projection); // 法線変換は world の 3x3 部分(無一様 scale 非対応の簡易版)。 o.worldNrm = normalize(mul(float4(i.normal, 0.0), world).xyz); o.uv = i.uv; o.color = i.color; return o; } )HLSL"
inline constexpr const char* MULTI_LIGHT_PS_3D = R"HLSL( struct LightEntry { float4 typeAndIntensity; // x=type (0=Dir,1=Point,2=Spot), y=intensity, z=spotInnerCos, w=spotOuterCos float4 position; // xyz=position float4 direction; // xyz=direction float4 color; // rgb=color, a=range }; cbuffer CbLighting : register(b1) { float4 _lightDir; // 未使用(multi-light は b2 を使う) float4 _lightColor; // 未使用 float4 ambientColor_b1; // 未使用(b2 の ambient を使う) float4 cameraPos; float4 materialDiffuse; float4 materialSpecular; float materialShininess; float3 _pad_lighting; }; cbuffer CbLightArray : register(b2) { int lightCount; int3 _pad_la; float4 sceneAmbient; LightEntry lights[8]; }; Texture2D g_albedo : register(t0); SamplerState g_samp : register(s0); struct VSOut { float4 svpos : SV_POSITION; float3 worldPos : TEXCOORD0; float3 worldNrm : NORMAL; float2 uv : TEXCOORD1; float4 color : COLOR0; }; float3 evaluateLight(LightEntry L, float3 worldPos, float3 N, float3 V, float3 albedo) { int type = (int)L.typeAndIntensity.x; float intensity = L.typeAndIntensity.y; float3 Lcol = L.color.rgb * intensity; float range = L.color.a; float3 Ldir; float attenuation = 1.0; if (type == 0) { // Directional: L からの光は -direction 方向から来る。 Ldir = normalize(-L.direction.xyz); } else { // Point / Spot: 光源位置から worldPos へのベクトル。 float3 toLight = L.position.xyz - worldPos; float dist = length(toLight); Ldir = toLight / max(dist, 1e-4); // smooth distance attenuation: 1 at center, 0 at range. attenuation = saturate(1.0 - dist / max(range, 1e-4)); attenuation *= attenuation; if (type == 2) { // Spot: dot(Ldir, -direction) > outerCos で減衰開始。 float3 spotDir = normalize(L.direction.xyz); float cosTheta = dot(-Ldir, spotDir); float inner = L.typeAndIntensity.z; float outer = L.typeAndIntensity.w; float spotFactor = saturate( (cosTheta - outer) / max(inner - outer, 1e-4)); attenuation *= spotFactor; } } float NdotL = saturate(dot(N, Ldir)); // Phong specular float3 H = normalize(Ldir + V); float specPow = max(materialShininess, 1.0); float NdotH = saturate(dot(N, H)); float spec = pow(NdotH, specPow) * NdotL; float3 diffuse = albedo * NdotL; float3 specular = materialSpecular.rgb * spec; return (diffuse + specular) * Lcol * attenuation; } float4 PSMain(VSOut i) : SV_TARGET { float3 N = normalize(i.worldNrm); float3 V = normalize(cameraPos.xyz - i.worldPos); float4 texCol = g_albedo.Sample(g_samp, i.uv); float3 albedo = materialDiffuse.rgb * i.color.rgb * texCol.rgb; float3 result = sceneAmbient.rgb * albedo; [unroll] for (int n = 0; n < 8; ++n) { if (n >= lightCount) break; result += evaluateLight(lights[n], i.worldPos, N, V, albedo); } float alpha = materialDiffuse.a * i.color.a * texCol.a; return float4(result, alpha); } )HLSL"
inline constexpr int kMaxLights = 16
struct alignas(16) GpuLightData
struct alignas(16) CbLights
constexpr const char* kMultiLightPS = R"hlsl( cbuffer CbLighting : register(b1) { float3 LightDir; float _pad0; float3 LightColor; float _pad1; float3 AmbientColorLegacy; float _pad2; float3 CameraPos; float _pad3; float4 MaterialDiffuse; float4 MaterialSpecular; float MaterialShininess; float3 _pad4; }; struct LightData { float3 position; float type; // 0=Directional, 1=Point, 2=Spot float3 direction; float range; float4 color; // rgb + intensity in w float innerCone; float outerCone; float2 padding; }; cbuffer CbLights : register(b2) { LightData lights[16]; int lightCount; float3 ambientColor; }; struct PSInput { float4 Position : SV_POSITION; float3 WorldPos : TEXCOORD0; float3 WorldNorm : TEXCOORD1; float2 TexCoord : TEXCOORD2; float4 Color : COLOR0; }; float4 PSMain(PSInput input) : SV_TARGET { float3 N = normalize(input.WorldNorm); float3 V = normalize(CameraPos - input.WorldPos); float3 totalDiffuse = float3(0, 0, 0); float3 totalSpecular = float3(0, 0, 0); for (int i = 0; i < lightCount; i++) { float3 lightColor = lights[i].color.rgb * lights[i].color.w; float3 L; float attenuation = 1.0; if (lights[i].type < 0.5) { // Directional light L = normalize(-lights[i].direction); } else { // Point or Spot light float3 toLight = lights[i].position - input.WorldPos; float dist = length(toLight); L = toLight / max(dist, 0.0001); // Distance attenuation with range cutoff float rangeSq = lights[i].range * lights[i].range; attenuation = max(1.0 - (dist * dist) / rangeSq, 0.0); attenuation *= attenuation; if (lights[i].type > 1.5) { // Spot light: cone angle falloff float cosAngle = dot(-L, normalize(lights[i].direction)); float spotFactor = saturate( (cosAngle - lights[i].outerCone) / max(lights[i].innerCone - lights[i].outerCone, 0.0001)); attenuation *= spotFactor * spotFactor; } } // Diffuse float NdotL = max(dot(N, L), 0.0); totalDiffuse += lightColor * NdotL * attenuation; // Specular (Blinn-Phong) float3 H = normalize(L + V); float NdotH = max(dot(N, H), 0.0); float specFactor = pow(NdotH, MaterialShininess); totalSpecular += lightColor * MaterialSpecular.rgb * specFactor * attenuation; } float3 ambient = ambientColor * MaterialDiffuse.rgb; float3 diffuse = totalDiffuse * MaterialDiffuse.rgb; float3 finalColor = ambient + diffuse + totalSpecular; float alpha = MaterialDiffuse.a * input.Color.a; return float4(finalColor * input.Color.rgb, alpha); } )hlsl"
class MultiLightSystem 23
template <typename T> using ComPtr = Microsoft::WRL::ComPtr<T>
MultiLightSystem() noexcept = default
[[nodiscard]] bool isInitialized() const noexcept
[[nodiscard]] int lightCount() const noexcept
void init(ID3D11Device* device)
void setLights(const std::vector<Light>& lights)
void setAmbient(const sgc::Colorf& color) noexcept
void bind(ID3D11DeviceContext* context)
void unbind(ID3D11DeviceContext* context)
constexpr const char* FLAT_PS_3D = R"hlsl( cbuffer CbLighting : register(b1) { float3 LightDir; float _pad0; float3 LightColor; float _pad1; float3 AmbientColor; float _pad2; float3 CameraPos; float _pad3; float4 MaterialDiffuse; float4 MaterialSpecular; float MaterialShininess; float3 _pad4; }; struct PSInput { float4 Position : SV_POSITION; float3 WorldPos : TEXCOORD0; float3 WorldNorm : TEXCOORD1; float2 TexCoord : TEXCOORD2; float4 Color : COLOR0; }; float4 PSMain(PSInput input) : SV_TARGET { float3 N = normalize(input.WorldNorm); float3 L = normalize(-LightDir); float NdotL = max(dot(N, L), 0.0); // 完全2値: 明か暗か float shade = (NdotL > 0.3) ? 1.0 : 0.55; float3 color = MaterialDiffuse.rgb * shade; return float4(color * input.Color.rgb, MaterialDiffuse.a * input.Color.a); } )hlsl"
constexpr const char* POSTERIZE_PS_3D = R"hlsl( cbuffer CbLighting : register(b1) { float3 LightDir; float _pad0; float3 LightColor; float _pad1; float3 AmbientColor; float _pad2; float3 CameraPos; float _pad3; float4 MaterialDiffuse; float4 MaterialSpecular; float MaterialShininess; float3 _pad4; }; struct PSInput { float4 Position : SV_POSITION; float3 WorldPos : TEXCOORD0; float3 WorldNorm : TEXCOORD1; float2 TexCoord : TEXCOORD2; float4 Color : COLOR0; }; float4 PSMain(PSInput input) : SV_TARGET { float3 N = normalize(input.WorldNorm); float3 L = normalize(-LightDir); float3 V = normalize(CameraPos - input.WorldPos); float3 ambient = AmbientColor * MaterialDiffuse.rgb; float NdotL = max(dot(N, L), 0.0); float3 diffuse = LightColor * MaterialDiffuse.rgb * NdotL; float3 raw = ambient + diffuse; // 4段階にポスタライズ float levels = 4.0; raw = floor(raw * levels + 0.5) / levels; return float4(raw * input.Color.rgb, MaterialDiffuse.a * input.Color.a); } )hlsl"
constexpr const char* HALFTONE_PS_3D = R"hlsl( cbuffer CbLighting : register(b1) { float3 LightDir; float _pad0; float3 LightColor; float _pad1; float3 AmbientColor; float _pad2; float3 CameraPos; float _pad3; float4 MaterialDiffuse; float4 MaterialSpecular; float MaterialShininess; float3 _pad4; }; struct PSInput { float4 Position : SV_POSITION; float3 WorldPos : TEXCOORD0; float3 WorldNorm : TEXCOORD1; float2 TexCoord : TEXCOORD2; float4 Color : COLOR0; }; float4 PSMain(PSInput input) : SV_TARGET { float3 N = normalize(input.WorldNorm); float3 L = normalize(-LightDir); float NdotL = max(dot(N, L), 0.0); float brightness = NdotL * 0.7 + 0.3; // スクリーン空間のドットパターン float2 screenUV = input.Position.xy; float dotSize = 6.0; float2 cell = fmod(screenUV, dotSize) / dotSize - 0.5; float dist = length(cell); float dotThreshold = (1.0 - brightness) * 0.5; float pattern = (dist < dotThreshold) ? 0.4 : 1.0; float3 color = MaterialDiffuse.rgb * pattern; return float4(color * input.Color.rgb, MaterialDiffuse.a * input.Color.a); } )hlsl"
constexpr const char* HATCHING_PS_3D = R"hlsl( cbuffer CbLighting : register(b1) { float3 LightDir; float _pad0; float3 LightColor; float _pad1; float3 AmbientColor; float _pad2; float3 CameraPos; float _pad3; float4 MaterialDiffuse; float4 MaterialSpecular; float MaterialShininess; float3 _pad4; }; struct PSInput { float4 Position : SV_POSITION; float3 WorldPos : TEXCOORD0; float3 WorldNorm : TEXCOORD1; float2 TexCoord : TEXCOORD2; float4 Color : COLOR0; }; float4 PSMain(PSInput input) : SV_TARGET { float3 N = normalize(input.WorldNorm); float3 L = normalize(-LightDir); float NdotL = max(dot(N, L), 0.0); float brightness = NdotL * 0.6 + 0.4; // スクリーン空間の斜線パターン float2 screenUV = input.Position.xy; // 明るさに応じてハッチング密度を変える float hatch1 = fmod(screenUV.x + screenUV.y, 4.0) < 1.0 ? 0.0 : 1.0; float hatch2 = fmod(screenUV.x - screenUV.y, 6.0) < 1.0 ? 0.0 : 1.0; float hatch3 = fmod(screenUV.x + screenUV.y * 0.5, 3.0) < 0.8 ? 0.0 : 1.0; float pattern = 1.0; if (brightness < 0.3) pattern = hatch1 * hatch2 * hatch3; // 3層ハッチング(暗い) else if (brightness < 0.55) pattern = hatch1 * hatch2; // 2層(中間) else if (brightness < 0.8) pattern = hatch1; // 1層(やや明) // ベース色 + ハッチングパターン float3 paperColor = float3(0.95, 0.92, 0.88); // 紙の色 float3 inkColor = MaterialDiffuse.rgb * 0.15; // インクの色 float3 color = lerp(inkColor, paperColor, pattern); return float4(color, 1.0); } )hlsl"
constexpr const char* GRADIENT_MAP_PS_3D = R"hlsl( cbuffer CbLighting : register(b1) { float3 LightDir; float _pad0; float3 LightColor; float _pad1; float3 AmbientColor; float _pad2; float3 CameraPos; float _pad3; float4 MaterialDiffuse; float4 MaterialSpecular; float MaterialShininess; float3 _pad4; }; struct PSInput { float4 Position : SV_POSITION; float3 WorldPos : TEXCOORD0; float3 WorldNorm : TEXCOORD1; float2 TexCoord : TEXCOORD2; float4 Color : COLOR0; }; float4 PSMain(PSInput input) : SV_TARGET { float3 N = normalize(input.WorldNorm); float3 L = normalize(-LightDir); float NdotL = max(dot(N, L), 0.0) * 0.8 + 0.2; // 暖色(影)→ 素材色(中間)→ 明るい暖色(ハイライト) float3 shadowColor = MaterialDiffuse.rgb * float3(0.4, 0.3, 0.5); // 紫がかった影 float3 midColor = MaterialDiffuse.rgb; float3 highlightColor = MaterialDiffuse.rgb * float3(1.1, 1.05, 0.9); // 暖色ハイライト float3 color; if (NdotL < 0.5) color = lerp(shadowColor, midColor, NdotL * 2.0); else color = lerp(midColor, highlightColor, (NdotL - 0.5) * 2.0); return float4(saturate(color) * input.Color.rgb, MaterialDiffuse.a * input.Color.a); } )hlsl"
constexpr const char* SILHOUETTE_PS_3D = R"hlsl( cbuffer CbLighting : register(b1) { float3 LightDir; float _pad0; float3 LightColor; float _pad1; float3 AmbientColor; float _pad2; float3 CameraPos; float _pad3; float4 MaterialDiffuse; float4 MaterialSpecular; float MaterialShininess; float3 _pad4; }; struct PSInput { float4 Position : SV_POSITION; float3 WorldPos : TEXCOORD0; float3 WorldNorm : TEXCOORD1; float2 TexCoord : TEXCOORD2; float4 Color : COLOR0; }; float4 PSMain(PSInput input) : SV_TARGET { float3 N = normalize(input.WorldNorm); float3 V = normalize(CameraPos - input.WorldPos); // エッジ検出: 視線と法線の角度が大きい→エッジ float edge = 1.0 - abs(dot(N, V)); edge = smoothstep(0.3, 0.8, edge); // エッジ部分は素材色、中心は薄い色 float3 edgeColor = MaterialDiffuse.rgb * 0.2; float3 fillColor = MaterialDiffuse.rgb * 0.85; float3 color = lerp(fillColor, edgeColor, edge); // 強いリムライト float rim = pow(1.0 - saturate(dot(N, V)), 3.0); color += rim * 0.4 * MaterialDiffuse.rgb; return float4(color * input.Color.rgb, MaterialDiffuse.a * input.Color.a); } )hlsl"
constexpr const char* WATERCOLOR_PS_3D = R"hlsl( cbuffer CbLighting : register(b1) { float3 LightDir; float _pad0; float3 LightColor; float _pad1; float3 AmbientColor; float _pad2; float3 CameraPos; float _pad3; float4 MaterialDiffuse; float4 MaterialSpecular; float MaterialShininess; float3 _pad4; }; struct PSInput { float4 Position : SV_POSITION; float3 WorldPos : TEXCOORD0; float3 WorldNorm : TEXCOORD1; float2 TexCoord : TEXCOORD2; float4 Color : COLOR0; }; float4 PSMain(PSInput input) : SV_TARGET { float3 N = normalize(input.WorldNorm); float3 L = normalize(-LightDir); float3 V = normalize(CameraPos - input.WorldPos); float NdotL = max(dot(N, L), 0.0); // ソフトなトゥーン(滑らかな遷移) float shade = smoothstep(0.0, 0.6, NdotL) * 0.6 + 0.4; // 紙のテクスチャ風ノイズ(スクリーン空間) float2 uv = input.Position.xy * 0.03; float noise = frac(sin(dot(uv, float2(12.9898, 78.233))) * 43758.5453); noise = noise * 0.08 - 0.04; // 微小な変動 // 色を少し彩度上げてパステル調に float3 baseColor = MaterialDiffuse.rgb; float grey = dot(baseColor, float3(0.299, 0.587, 0.114)); baseColor = lerp(float3(grey, grey, grey), baseColor, 1.3); // 彩度ブースト baseColor = lerp(baseColor, float3(1, 1, 1), 0.15); // 白っぽく(水彩の透明感) float3 color = baseColor * shade + noise; // エッジを少し暗くする(水彩の輪郭にじみ) float edge = 1.0 - abs(dot(N, V)); edge = smoothstep(0.5, 0.9, edge); color = lerp(color, baseColor * 0.5, edge * 0.3); return float4(saturate(color) * input.Color.rgb, MaterialDiffuse.a * input.Color.a); } )hlsl"
`constexpr std::string_view NORMAL_MAP_VS = R"hlsl(
`constexpr std::string_view NORMAL_MAP_PS = R"hlsl(
VSOutput VSMain(VSInput input)
Texture2D NormalTexture : register(t1)
SamplerState samp : register(s0)
cbuffer CbLighting : register(b1)
cbuffer CbNormalMap : register(b2)
struct VertexWithTangent 3
constexpr VertexWithTangent() noexcept = default
constexpr VertexWithTangent( const sgc::Vec3f& position, const sgc::Vec3f& normal, const sgc::Vec2f& texCoord, const sgc::Colorf& color, const sgc::Vec4f& tangent) noexcept
explicit constexpr VertexWithTangent(const Vertex3D& v) noexcept
struct NormalMapTexture 5
Microsoft::WRL::ComPtr<ID3D11Texture2D> texture
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> srv
std::uint32_t width = 0
std::uint32_t height = 0
[[nodiscard]] bool valid() const noexcept
struct VSInput 5
float3 Position : POSITION
float3 Normal : NORMAL
float2 TexCoord : TEXCOORD0
float4 Color : COLOR0
float4 Tangent : TANGENT0
struct VSOutput 7
float4 Position : SV_POSITION
float3 WorldPos : TEXCOORD0
float3 WorldNorm : TEXCOORD1
float2 TexCoord : TEXCOORD2
float4 Color : COLOR0
float3 WorldTan : TEXCOORD3
float3 WorldBitan : TEXCOORD4
struct PSInput 7
float4 Position : SV_POSITION
float3 WorldPos : TEXCOORD0
float3 WorldNorm : TEXCOORD1
float2 TexCoord : TEXCOORD2
float4 Color : COLOR0
float3 WorldTan : TEXCOORD3
float3 WorldBitan : TEXCOORD4
class NormalMapHelper 17
template <typename T> using ComPtr = Microsoft::WRL::ComPtr<T>
NormalMapHelper() noexcept = default
void init(ID3D11Device* device)
[[nodiscard]] bool isInitialized() const noexcept
[[nodiscard]] NormalMapTexture createNormalMapFromMemory( ID3D11Device* device, const std::uint8_t* pixels, int width, int height)
static void computeTangents( const std::vector<Vertex3D>& vertices, const std::vector<std::uint32_t>& indices, std::vector<VertexWithTangent>& outVertices)
void setNormalMap(std::uint32_t meshId, const NormalMapTexture& normalMap)
void removeNormalMap(std::uint32_t meshId)
[[nodiscard]] bool hasNormalMap(std::uint32_t meshId) const noexcept
void bind(ID3D11DeviceContext* context, std::uint32_t meshId, float normalMapStrength = 1.0f)
void unbind(ID3D11DeviceContext* context)
[[nodiscard]] const ComPtr<ID3D11InputLayout>& inputLayout() const noexcept
[[nodiscard]] const ComPtr<ID3D11VertexShader>& vertexShader() const noexcept
[[nodiscard]] const ComPtr<ID3D11PixelShader>& pixelShader() const noexcept
[[nodiscard]] inline ObjVertexKey parseFaceVertex(const std::string& token)
[[nodiscard]] inline std::optional<Mesh> loadObjFromString(std::string_view objData)
[[nodiscard]] inline std::optional<Mesh> loadObjFromFile(const std::string& filePath)
struct ObjVertexKey 4
int posIdx = -1
int texIdx = -1
int normIdx = -1
bool operator==(const ObjVertexKey& other) const noexcept
struct ObjVertexKeyHash 2
std::size_t operator()(const ObjVertexKey& key) const noexcept
[[nodiscard]] inline std::optional<Mesh> loadObjWithMaterials(const std::string& filePath)
struct CullAABB 2
float minX, minY, minZ
float maxX, maxY, maxZ
struct CullResult 3
int totalObjects = 0
int visibleObjects = 0
int culledObjects = 0
class OcclusionCuller 4
void resize(int width, int height)
void updateDepth(const float* depthData, int width, int height)
[[nodiscard]] bool isOccluded(const CullAABB& aabb, const float viewProj[16]) const
[[nodiscard]] CullResult testBatch( const std::vector<CullAABB>& aabbs, const float viewProj[16]) const
class OffscreenRenderer3D 14
OffscreenRenderer3D(int width, int height)
void beginScene()
void addMesh(const Mesh& mesh, const sgc::Vec3f& position = {}, const sgc::Vec3f& rotation = {}, const sgc::Vec3f& scale = {1,1,1}, const Material& material = Material::defaultMaterial())
void addLight(const Light& light)
void render(const Camera3D& camera)
[[nodiscard]] Texture texture() const
[[nodiscard]] const RenderTexture& renderTexture() const noexcept
void resize(int width, int height)
[[nodiscard]] int width() const noexcept
[[nodiscard]] int height() const noexcept
void setClearColor(const sgc::Colorf& color) noexcept
[[nodiscard]] Scene3D& scene() noexcept
[[nodiscard]] const Scene3D& scene() const noexcept
struct alignas(16) PBRShaderConstants
struct PBRMaterial 12
float metallic = 0.0f
float roughness = 0.5f
float ao = 1.0f
std::string albedoMapKey
std::string normalMapKey
std::string metallicRoughnessMapKey
std::string aoMapKey
std::string emissiveMapKey
[[nodiscard]] bool hasAnyMap() const noexcept
[[nodiscard]] static PBRMaterial defaultMaterial() noexcept
[[nodiscard]] static PBRMaterial metal(const sgc::Colorf& color, float rough = 0.3f) noexcept
[[nodiscard]] static PBRMaterial dielectric(const sgc::Colorf& color, float rough = 0.5f) noexcept
struct PBREnvironment 5
std::string irradianceMapKey
std::string prefilteredMapKey
std::string brdfLutKey
float ambientIntensity = 1.0f
[[nodiscard]] bool isValid() const noexcept
class PBRRenderer 79
PBRRenderer() noexcept = default
bool init(ID3D11Device* device)
bool initShaders(ID3D11Device* device)
[[nodiscard]] const PBRShaderSet& shaders() const noexcept
[[nodiscard]] bool isInitialized() const noexcept
void setMaterial(const PBRMaterial& material) noexcept
[[nodiscard]] const PBRMaterial& material() const noexcept
void setEnvironment(const PBREnvironment& env) noexcept
[[nodiscard]] const PBREnvironment& environment() const noexcept
[[nodiscard]] static bool shouldUsePBR(const PBRMaterial& mat) noexcept
void drawMesh(const sgc::Mat4f& worldMatrix, const sgc::Mat4f& viewMatrix, const sgc::Mat4f& projMatrix, const sgc::Vec3f& cameraPos, const sgc::Vec3f& lightDir, const sgc::Colorf& lightColor, float lightIntensity = 1.0f)
[[nodiscard]] sgc::Colorf computeLighting( const sgc::Vec3f& worldPos, const sgc::Vec3f& normal, const sgc::Vec3f& cameraPos, const sgc::Vec3f& lightDir, const sgc::Colorf& lightColor, float lightIntensity = 1.0f) const noexcept
`constexpr std::string_view kPBR_VS = R"hlsl(
`constexpr std::string_view kPBR_BRDF_COMMON = R"hlsl(
`constexpr std::string_view kPBR_CBUFFER_COMMON = R"hlsl(
`constexpr std::string_view kPBR_PS_BODY = R"hlsl(
`constexpr std::string_view kPBR_IBL_PS_BODY = R"hlsl(
`constexpr std::string_view kPBR_SHADOW_PS_BODY = R"hlsl(
`constexpr std::string_view kIBL_IRRADIANCE_PS = R"hlsl(
`constexpr std::string_view kIBL_PREFILTER_PS = R"hlsl(
`constexpr std::string_view kIBL_BRDF_LUT_PS = R"hlsl(
`constexpr std::string_view kFULLSCREEN_QUAD_VS = R"hlsl(
`constexpr std::string_view kCUBEMAP_FACE_VS = R"hlsl(
VSOutput VSMain(VSInput input)
// ── GGX / Trowbridge-Reitz Normal Distribution ──────────── float DistributionGGX(float3 N, float3 H, float roughness)
// ── Schlick-GGX Geometry (single direction) ─────────────── float GeometrySchlickGGX(float NdotV, float roughness)
// ── Smith's Geometry (combined) ─────────────────────────── float GeometrySmith(float3 N, float3 V, float3 L, float roughness)
// ── Schlick-GGX for IBL (different k remapping) ────────── float GeometrySchlickGGX_IBL(float NdotV, float roughness)
float GeometrySmith_IBL(float3 N, float3 V, float3 L, float roughness)
// ── Fresnel (Schlick approximation) ────────────────────── float3 FresnelSchlick(float cosTheta, float3 F0)
// ── Fresnel with roughness (for IBL ambient) ──────────── float3 FresnelSchlickRoughness(float cosTheta, float3 F0, float roughness)
// ── ACES Filmic Tone Mapping ───────────────────────────── float3 ACESFilm(float3 x)
// ── Normal mapping via TBN matrix ──────────────────────── float3 ApplyNormalMap(float3 sampledNormal, float3 T, float3 B, float3 N)
// ── Textures & Samplers ───────────────────────────────── Texture2D tAlbedo : register(t0)
Texture2D tNormal : register(t1)
Texture2D tMetalRough : register(t2)
Texture2D tAO : register(t3)
Texture2D tEmissive : register(t4)
SamplerState sSampler : register(s0)
// ── Lighting Calculation ──────────────────────────────── // Evaluate Cook-Torrance for a single directional light float3 EvalDirectionalLight(float3 N, float3 V, float3 lightDir, float3 lightColor, float lightIntensity, float3 albedo, float metallic, float roughness, float3 F0)
// Evaluate Cook-Torrance for a single point light float3 EvalPointLight(float3 N, float3 V, float3 worldPos, float3 lightPos, float3 lightColor, float lightRange, float3 albedo, float metallic, float roughness, float3 F0)
// ── Textures & Samplers ───────────────────────────────── Texture2D tAlbedo : register(t0)
Texture2D tNormal : register(t1)
Texture2D tMetalRough : register(t2)
Texture2D tAO : register(t3)
Texture2D tEmissive : register(t4)
TextureCube tIrradiance : register(t5)
TextureCube tPrefiltered : register(t6)
Texture2D tBRDFLut : register(t7)
SamplerState sSampler : register(s0)
SamplerState sClampSampler : register(s1)
Texture2D tAlbedo : register(t0)
Texture2D tNormal : register(t1)
Texture2D tMetalRough : register(t2)
Texture2D tAO : register(t3)
Texture2D tEmissive : register(t4)
Texture2DArray tShadowMap : register(t8)
SamplerState sSampler : register(s0)
SamplerComparisonState sShadowSampler : register(s2)
// ── Cascade Shadow Map Selection ──────────────────────── int SelectCascade(float viewDepth)
// ── PCF 3x3 Shadow Sampling ──────────────────────────── float SampleShadowPCF(float3 worldPos, int cascadeIndex)
SamplerState sSampler : register(s0)
cbuffer CbIrradiance : register(b0)
SamplerState sSampler : register(s0)
cbuffer CbPrefilter : register(b0)
// GGX NDF for prefilter float DistributionGGX_Prefilter(float NdotH, float roughness)
// Radical inverse (Van der Corput sequence) float RadicalInverse_VdC(uint bits)
float2 Hammersley(uint i, uint N)
// GGX importance sampling float3 ImportanceSampleGGX(float2 Xi, float3 N, float roughness)
float RadicalInverse_VdC(uint bits)
float2 Hammersley(uint i, uint N)
float3 ImportanceSampleGGX(float2 Xi, float3 N, float roughness)
float GeometrySchlickGGX_IBL(float NdotV, float roughness)
float GeometrySmith_IBL(float NdotV, float NdotL, float roughness)
float2 IntegrateBRDF(float NdotV, float roughness)
VSOutput VSMain(uint vertexID : SV_VertexID)
VSOutput VSMain(uint vertexID : SV_VertexID)
inline bool CompilePBRShader(std::string_view source, const char* entryPoint, const char* target, ID3DBlob** blob)
[[nodiscard]] inline PBRShaderSet CompilePBRShaders(ID3D11Device* device)
struct VSInput 4
float3 Position : POSITION
float3 Normal : NORMAL
float2 TexCoord : TEXCOORD0
float4 Tangent : TANGENT
struct VSOutput 6
float4 Position : SV_POSITION
float3 WorldPos : TEXCOORD0
float3 WorldNorm : TEXCOORD1
float3 WorldTan : TEXCOORD2
float3 WorldBitan : TEXCOORD3
float2 TexCoord : TEXCOORD4
struct PSInput 6
float4 Position : SV_POSITION
float3 WorldPos : TEXCOORD0
float3 WorldNorm : TEXCOORD1
float3 WorldTan : TEXCOORD2
float3 WorldBitan : TEXCOORD3
float2 TexCoord : TEXCOORD4
struct PSInput 2
float4 Position : SV_POSITION
float3 WorldDir : TEXCOORD0
struct PSInput 2
float4 Position : SV_POSITION
float3 WorldDir : TEXCOORD0
struct VSOutput 2
float4 Position : SV_POSITION
float3 WorldDir : TEXCOORD0
struct PBRShaderSet 12
Microsoft::WRL::ComPtr<ID3D11VertexShader> pbrVS
Microsoft::WRL::ComPtr<ID3D11PixelShader> pbrPS
Microsoft::WRL::ComPtr<ID3D11PixelShader> pbrIBL_PS
Microsoft::WRL::ComPtr<ID3D11PixelShader> pbrShadowPS
Microsoft::WRL::ComPtr<ID3D11PixelShader> iblIrradiancePS
Microsoft::WRL::ComPtr<ID3D11PixelShader> iblPrefilterPS
Microsoft::WRL::ComPtr<ID3D11PixelShader> iblBrdfLutPS
Microsoft::WRL::ComPtr<ID3D11VertexShader> fullscreenQuadVS
Microsoft::WRL::ComPtr<ID3D11VertexShader> cubemapFaceVS
Microsoft::WRL::ComPtr<ID3D11InputLayout> pbrInputLayout
bool valid = false
static constexpr std::string_view PARTICLE_COLLISION_CS_HLSL = R"( struct Particle { float3 position; float pad0; float3 velocity; float life; }; struct CollisionEvent { uint particleIndex; float contactX; float contactY; float contactZ; float penetrationDepth; float pad0; float pad1; float pad2; }; cbuffer CollisionParams : register(b0) { float4x4 viewProj; // CPU側で transposed() してアップロード済み float depthThreshold; float restitution; float friction; float deltaTime; int depthWidth; int depthHeight; int maxParticles; int _pad; }; RWStructuredBuffer<Particle> particles : register(u0); AppendStructuredBuffer<CollisionEvent> events : register(u1); Texture2D<float> depthBuffer : register(t0); [numthreads(64, 1, 1)] void CSMain(uint3 dtid : SV_DispatchThreadID) { uint id = dtid.x; if (id >= (uint)maxParticles) { return; } Particle p = particles[id]; if (p.life <= 0.0) { return; } // mul(matrix, column_vec): CPU側 transposed() + HLSL左matrix → sgc * vec float4 clip = mul(viewProj, float4(p.position, 1.0)); if (clip.w <= 0.0) { return; } float3 ndc = clip.xyz / clip.w; if (any(abs(ndc.xy) > 1.0)) { return; } if (ndc.z < 0.0 || ndc.z > 1.0) { return; } float2 uv = ndc.xy * float2(0.5, -0.5) + 0.5; int2 px = int2(uv * float2((float)depthWidth, (float)depthHeight)); px = clamp(px, int2(0,0), int2(depthWidth-1, depthHeight-1)); float scene_z = depthBuffer.Load(int3(px, 0)); float diff = ndc.z - scene_z; if (diff > depthThreshold) { // 反射応答(Y軸法線を仮定) float3 normal = float3(0.0, 1.0, 0.0); float vDotN = dot(p.velocity, normal); if (vDotN < 0.0) { p.velocity = p.velocity - (1.0 + restitution) * vDotN * normal; p.velocity.xz *= (1.0 - friction); } particles[id] = p; CollisionEvent ev; ev.particleIndex = id; ev.contactX = p.position.x; ev.contactY = p.position.y; ev.contactZ = p.position.z; ev.penetrationDepth = diff; ev.pad0 = 0.0; ev.pad1 = 0.0; ev.pad2 = 0.0; events.Append(ev); } } )"
struct ParticleCollisionConfig 7
float depthThreshold = 0.01f
float restitution = 0.3f
float friction = 0.5f
float stickyThreshold = 0.05f
bool enableCollision = true
bool enableSticky = false
int maxCollisionsPerFrame = 1024
struct ParticleCollisionEvent 2
std::uint32_t particleIndex = 0
float penetrationDepth = 0.0f
struct ParticleCollisionStats 4
int totalParticles = 0
int collisionsDetected = 0
int collisionsResolved = 0
float resolveTimeMs = 0.0f
struct CollisionParticle 4
float position[3]
float pad0
float velocity[3]
float life
struct CollisionEvent_GPU 6
std::uint32_t particleIndex
float contactX
float contactY
float contactZ
float penetrationDepth
float pad[3]
class ParticleCollisionResolver 17
ParticleCollisionResolver() = default
~ParticleCollisionResolver()
ParticleCollisionResolver(const ParticleCollisionResolver&) = delete
ParticleCollisionResolver& operator=(const ParticleCollisionResolver&) = delete
ParticleCollisionResolver(ParticleCollisionResolver&&) noexcept = default
ParticleCollisionResolver& operator=(ParticleCollisionResolver&&) noexcept = default
bool init(int maxParticles, const ParticleCollisionConfig& config = {})
void setCamera(const float* viewMatrix, const float* projMatrix)
[[nodiscard]] std::vector<ParticleCollisionEvent> resolve(float deltaTime)
[[nodiscard]] ParticleCollisionStats stats() const noexcept
[[nodiscard]] ParticleCollisionConfig& config() noexcept
[[nodiscard]] const ParticleCollisionConfig& config() const noexcept
bool init(ID3D11Device* device, int maxParticles, const ParticleCollisionConfig& cfg = {})
void shutdown()
void setCameraVP(const float* vpRowMajor)
void uploadParticles(const CollisionParticle* data, int count)
void uploadDepth(const float* data, int width, int height)
struct Particle3D 5
float size = 0.2f
float endSize = 0.0f
float life = 1.0f
float maxLife = 1.0f
bool alive = false
struct ParticleEmitter3D 9
float emitSpread = 0.5f
float emitSpeed = 2.0f
float emitSpeedVariance = 0.5f
float startSize = 0.3f
float endSize = 0.0f
float particleLife = 1.0f
float particleLifeVariance = 0.3f
float emitRate = 10.0f
bool active = true
class ParticleSystem3D 8
explicit ParticleSystem3D(int maxParticles = 256)
void setEmitter(const ParticleEmitter3D& emitter)
ParticleEmitter3D& emitter() noexcept
const ParticleEmitter3D& emitter() const noexcept
void update(float dt)
void fillBillboards(Billboard3D& billboards) const
[[nodiscard]] int aliveCount() const noexcept
void clear()
enum RenderMode 2
Forward
Deferred
struct DrawCommand3D 3
const Mesh* mesh = nullptr
sgc::Mat4f transform
Material material
class Pipeline3D 15
Pipeline3D() noexcept = default
void setDevice(gfx::IDevice* device) noexcept
void setRenderMode(RenderMode mode) noexcept
[[nodiscard]] RenderMode renderMode() const noexcept
[[nodiscard]] gfx::IDevice* device() const noexcept
void begin(const Camera3D& camera)
void submitMesh(const Mesh& mesh, const sgc::Mat4f& transform, const Material& material)
void submitLight(const Light& light)
void end()
[[nodiscard]] int drawCallCount() const noexcept
[[nodiscard]] const std::vector<DrawCommand3D>& drawCommands() const noexcept
[[nodiscard]] const std::vector<Light>& lights() const noexcept
[[nodiscard]] const sgc::Mat4f& viewMatrix() const noexcept
[[nodiscard]] const sgc::Mat4f& projectionMatrix() const noexcept
[[nodiscard]] const sgc::Mat4f& viewProjectionMatrix() const noexcept
class PostEffects 4
static void bloom(RenderTexture& rt, float threshold = 0.7f, float intensity = 0.5f, int radius = 3)
static void vignette(RenderTexture& rt, float strength = 0.5f, float radius = 0.8f)
static void saturation(RenderTexture& rt, float amount = 1.2f)
static void contrast(RenderTexture& rt, float amount = 1.1f)
class PostProcessManager 52
template <typename T> using ComPtr = Microsoft::WRL::ComPtr<T>
PostProcessManager() noexcept = default
void init(ID3D11Device* device, int screenW, int screenH)
void resize(int w, int h)
void setConfig(const PostProcessConfig& config)
void beginScene(ID3D11DeviceContext* context)
void endScene( ID3D11DeviceContext* context, ID3D11RenderTargetView* backbufferRTV)
[[nodiscard]] bool isEnabled() const noexcept
void setEnabled(bool enabled) noexcept
void enableBloom(float threshold = 0.8f, float intensity = 1.0f)
void enableVignette(float intensity = 0.5f, float radius = 0.8f)
void enableColorGrading( float brightness = 0.0f, float contrast = 1.0f, float saturation = 1.0f)
void enableFrostGlass(float blurAmount = 2.0f)
void enableFXAA(FXAAQuality quality = FXAAQuality::Medium)
void disableFXAA()
void disableAll()
[[nodiscard]] GpuTexture2D captureSceneTexture()
[[nodiscard]] bool isInitialized() const noexcept
[[nodiscard]] ID3D11ShaderResourceView* sceneTextureSRV() const noexcept
[[nodiscard]] ID3D11DepthStencilView* depthStencilView() const noexcept
[[nodiscard]] PostProcessChain* chain() const noexcept
[[nodiscard]] const PostProcessConfig& config() const noexcept
`constexpr std::string_view PP_FULLSCREEN_VS = R"hlsl(
`constexpr std::string_view PP_BLOOM_EXTRACT_PS = R"hlsl(
`constexpr std::string_view PP_BLOOM_COMBINE_PS = R"hlsl(
`constexpr std::string_view PP_GAUSSIAN_BLUR_PS = R"hlsl(
`constexpr std::string_view PP_COLOR_GRADING_PS = R"hlsl(
`constexpr std::string_view PP_VIGNETTE_PS = R"hlsl(
`constexpr std::string_view PP_CHROMATIC_ABERRATION_PS = R"hlsl(
`constexpr std::string_view PP_FILM_GRAIN_PS = R"hlsl(
`constexpr std::string_view PP_FADE_PS = R"hlsl(
`constexpr std::string_view PP_FROST_GLASS_PS = R"hlsl(
VSOutput VSMain(uint vertexId : SV_VertexID)
SamplerState linearSampler : register(s0)
cbuffer BloomParams : register(b0)
Texture2D bloomTexture : register(t1)
SamplerState linearSampler : register(s0)
SamplerState linearSampler : register(s0)
cbuffer BlurParams : register(b0)
float gaussWeight(int offset, float s)
SamplerState linearSampler : register(s0)
cbuffer ColorGradingParams : register(b0)
SamplerState linearSampler : register(s0)
cbuffer VignetteParams : register(b0)
SamplerState linearSampler : register(s0)
cbuffer ChromaticParams : register(b0)
SamplerState linearSampler : register(s0)
cbuffer FilmGrainParams : register(b0)
SamplerState linearSampler : register(s0)
cbuffer FadeParams : register(b0)
SamplerState linearSampler : register(s0)
cbuffer FrostParams : register(b0)
struct PSInput 2
float4 position : SV_POSITION
float2 texCoord : TEXCOORD0
struct PSInput 2
float4 position : SV_POSITION
float2 texCoord : TEXCOORD0
struct PSInput 2
float4 position : SV_POSITION
float2 texCoord : TEXCOORD0
struct PSInput 2
float4 position : SV_POSITION
float2 texCoord : TEXCOORD0
struct PSInput 2
float4 position : SV_POSITION
float2 texCoord : TEXCOORD0
struct PSInput 2
float4 position : SV_POSITION
float2 texCoord : TEXCOORD0
struct PSInput 2
float4 position : SV_POSITION
float2 texCoord : TEXCOORD0
struct PSInput 2
float4 position : SV_POSITION
float2 texCoord : TEXCOORD0
struct PSInput 8
float4 position : SV_POSITION
float2 texCoord : TEXCOORD0
inline constexpr bool kUsePrecompiledShaders = true
inline constexpr bool kUsePrecompiledShaders = false
[[nodiscard]] inline ShaderBytecode precompiledVS3D() noexcept
[[nodiscard]] inline ShaderBytecode precompiledPS3D() noexcept
[[nodiscard]] inline ShaderBytecode precompiledVS2D() noexcept
[[nodiscard]] inline ShaderBytecode precompiledPS2D() noexcept
struct ShaderBytecode 3
const uint8_t* data = nullptr
std::size_t size = 0
[[nodiscard]] bool valid() const noexcept
struct RenderPass 3
std::string name
bool enabled = true
std::function<void()> execute
class RenderGraph 7
void addPass(const std::string& name, std::function<void()> executeFunc)
bool setPassEnabled(const std::string& name, bool enabled)
[[nodiscard]] int execute()
[[nodiscard]] std::size_t passCount() const noexcept
void clear() noexcept
[[nodiscard]] const std::vector<RenderPass>& passes() const noexcept
#pragma once #include <algorithm> #include <cstdint> #include <cstring> #include <memory> #include <stack> #include <vector> #include <sgc/math/Rect.hpp> #include <mitiru/gfx/IBuffer.hpp> #include <mitiru/gfx/ICommandList.hpp> #include <mitiru/gfx/IDevice.hpp> #include <mitiru/gfx/IPipeline.hpp> #include <mitiru/render/DefaultShaders.hpp> #include <mitiru/render/StyledRectBatch.hpp> #include <mitiru/render/Vertex2D.hpp> #ifdef __EMSCRIPTEN__ #include <GLES3/gl3.h> #include <mitiru/gfx/webgl/WebGlShader.hpp> #include <mitiru/gfx/webgl/WebGlBuffer.hpp> #endif #ifdef _WIN32 #include <mitiru/gfx/dx11/Dx11Buffer.hpp> #include <mitiru/gfx/dx11/Dx11CommandList.hpp> #include <mitiru/gfx/dx11/Dx11Device.hpp> #include <mitiru/gfx/dx11/Dx11Pipeline.hpp> #include <mitiru/gfx/dx11/Dx11Shader.hpp> #include <d3d12.h> #include <d3dcompiler.h> #include <wrl/client.h> #include <mitiru/gfx/dx12/Dx12Device.hpp> #include <mitiru/gfx/dx12/Dx12SwapChain.hpp> #pragma comment(lib, "d3dcompiler.lib") #endif namespace mitiru::render
struct ValidationReport 7
int totalTests = 0
int passed = 0
int failed = 0
std::vector<std::string> errors
void record(const std::string& name, bool success, const std::string& errorMsg = {})
[[nodiscard]] bool allPassed() const noexcept
void merge(const ValidationReport& other)
class RenderPipelineValidator 6
RenderPipelineValidator() noexcept = default
[[nodiscard]] ValidationReport validateDX11Pipeline(Renderer3D& renderer) const
[[nodiscard]] ValidationReport validateDX12Pipeline( Renderer3D_DX12& renderer) const
[[nodiscard]] ValidationReport validateToonPipeline( ToonPipeline& pipeline) const
[[nodiscard]] ValidationReport validatePBRShaders( ID3D11Device* device) const
[[nodiscard]] ValidationReport validateStub() const
enum CullMode 3
None
Back
Front
struct RenderState3D 11
bool wireframe = false
CullMode cullMode = CullMode::Back
bool depthTest = true
bool depthWrite = true
bool blendEnabled = false
[[nodiscard]] static constexpr RenderState3D opaque() noexcept
[[nodiscard]] static constexpr RenderState3D transparent() noexcept
[[nodiscard]] static constexpr RenderState3D wireframeState() noexcept
[[nodiscard]] static constexpr RenderState3D noCull() noexcept
[[nodiscard]] constexpr bool operator==(const RenderState3D& other) const noexcept
[[nodiscard]] constexpr bool operator!=(const RenderState3D& other) const noexcept
class RenderTexture 9
RenderTexture(int width, int height)
void clear(const sgc::Colorf& color = {0, 0, 0, 1})
void drawRect(const sgc::Rectf& rect, const sgc::Colorf& color)
void setPixel(int x, int y, const sgc::Colorf& color)
[[nodiscard]] Texture texture() const
[[nodiscard]] sgc::Colorf pixelAt(int x, int y) const noexcept
[[nodiscard]] int width() const noexcept
[[nodiscard]] int height() const noexcept
[[nodiscard]] const std::vector<uint8_t>& pixels() const noexcept
class Renderer2D 16
Renderer2D() noexcept = default
explicit Renderer2D(float screenWidth, float screenHeight) noexcept
void beginFrame() noexcept
void endFrame() noexcept
void drawRect(const sgc::Rectf& rect, const sgc::Colorf& color)
void drawRectFrame(const sgc::Rectf& rect, const sgc::Colorf& color, float thickness = 1.0f)
void drawCircle(const sgc::Vec2f& center, float radius, const sgc::Colorf& color, int segments = 32)
void drawLine(const sgc::Vec2f& from, const sgc::Vec2f& to, const sgc::Colorf& color, float thickness = 1.0f)
void drawTriangle(const sgc::Vec2f& p0, const sgc::Vec2f& p1, const sgc::Vec2f& p2, const sgc::Colorf& color)
void drawText(const sgc::Vec2f& position, std::string_view text, const sgc::Colorf& color, float fontSize = 16.0f)
void setCamera(const Camera2D& camera) noexcept
[[nodiscard]] Camera2D& camera() noexcept
[[nodiscard]] const Camera2D& camera() const noexcept
[[nodiscard]] int totalDrawCalls() const noexcept
[[nodiscard]] SpriteBatch& spriteBatch() noexcept
[[nodiscard]] ShapeRenderer& shapeRenderer() noexcept
struct Renderer2DBridgeConfig 3
float screenW = 1280.0f
float screenH = 720.0f
bool vsync = true
class Renderer2DBridge 24
explicit Renderer2DBridge(std::unique_ptr<sgc::graphics::IRenderer2D> inner) noexcept
void drawCircle(sgc::Vec2f center, float radius, sgc::graphics::Color fill)
void drawCircleOutline(sgc::Vec2f center, float radius, sgc::graphics::Color stroke, float thickness)
void drawRect(sgc::Vec2f pos, sgc::Vec2f size, sgc::graphics::Color fill)
void drawRectOutline(sgc::Vec2f pos, sgc::Vec2f size, sgc::graphics::Color stroke, float thickness)
void drawLine(sgc::Vec2f from, sgc::Vec2f to, sgc::graphics::Color color, float thickness)
void drawTriangle(sgc::Vec2f a, sgc::Vec2f b, sgc::Vec2f c, sgc::graphics::Color fill)
void drawPolygon(const std::vector<sgc::Vec2f>& points, sgc::graphics::Color fill)
void drawBezier(sgc::Vec2f p0, sgc::Vec2f p1, sgc::Vec2f p2, sgc::Vec2f p3, sgc::graphics::Color color, float thickness, int segments = 32)
void drawText(sgc::Vec2f pos, const std::string& text, float fontSize, sgc::graphics::Color color)
void setViewMatrix(const sgc::Mat4f& mat)
[[nodiscard]] sgc::Vec2f getScreenSize() const
void beginFrame()
void endFrame()
void drawCircleWithGlow(sgc::Vec2f center, float radius, sgc::graphics::Color fillColor, sgc::graphics::Color glowColor, float glowRadius)
void drawRectWithGlow(sgc::Vec2f pos, sgc::Vec2f size, sgc::graphics::Color fillColor, sgc::graphics::Color glowColor, float glowRadius)
void drawLineWithGlow(sgc::Vec2f from, sgc::Vec2f to, sgc::graphics::Color color, sgc::graphics::Color glowColor, float thickness, float glowThickness)
void pushTransform(const sgc::Mat4f& mat)
void popTransform()
[[nodiscard]] int transformStackDepth() const noexcept
void setCamera(const sgc::graphics::Camera2D& camera)
[[nodiscard]] sgc::graphics::IRenderer2D& inner() noexcept
[[nodiscard]] const sgc::graphics::IRenderer2D& inner() const noexcept
#pragma once #include <cstdint> #include <cstring> #include <memory> #include <vector> #include <sgc/math/Mat4.hpp> #include <sgc/math/Vec3.hpp> #include <sgc/math/Vec4.hpp> #include <sgc/types/Color.hpp> #include <mitiru/render/GlmBridge.hpp> #include <mitiru/render/Camera3D.hpp> #include <mitiru/render/DefaultShaders3D.hpp> #include <mitiru/render/ToonShaders3D.hpp> #include <mitiru/render/NPRShaders3D.hpp> #include <mitiru/render/MultiLightShaders3D.hpp> #include <mitiru/render/Light.hpp> #include <mitiru/render/LightArrayCB.hpp> #include <mitiru/render/Cubemap.hpp> #include <mitiru/render/Skybox.hpp> #include <mitiru/render/Material.hpp> #include <mitiru/render/Mesh.hpp> #include <mitiru/render/RenderState3D.hpp> #include <mitiru/render/Texture.hpp> #include <mitiru/render/Vertex3D.hpp> #include <mitiru/gfx/IBuffer.hpp> #include <mitiru/gfx/IDevice.hpp> #include <mitiru/render/IRenderer3D.hpp> #ifdef _WIN32 #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif #ifndef NOMINMAX #define NOMINMAX #endif #include <Windows.h> #include <d3d11.h> #include <d3dcompiler.h> #include <wrl/client.h> #pragma comment(lib, "d3dcompiler.lib") #pragma comment(lib, "d3d11.lib") #include <mitiru/gfx/dx11/Dx11Buffer.hpp> #include <mitiru/gfx/dx11/Dx11Device.hpp> #include <mitiru/gfx/dx11/Dx11Shader.hpp> #endif namespace mitiru::render
class Renderer3D_DX12 : public IRenderer3D 78
Renderer3D_DX12()
~Renderer3D_DX12()
Renderer3D_DX12(const Renderer3D_DX12&) = delete
Renderer3D_DX12& operator=(const Renderer3D_DX12&) = delete
Renderer3D_DX12(Renderer3D_DX12&&) noexcept = default
Renderer3D_DX12& operator=(Renderer3D_DX12&&) noexcept = default
void initialize(gfx::Dx12Device* device, const Config& cfg = {})
[[nodiscard]] bool isInitialized() const noexcept override
void resize(float width, float height)
void beginFrame(const sgc::Colorf& clearColor = {0.2f, 0.2f, 0.3f, 1.0f}) override
void setCamera(const Camera3D& camera) override
void setLight(const Light& light) override
void setAmbientColor(const sgc::Colorf& color) override
[[nodiscard]] sgc::Colorf ambientColor() const noexcept override
void drawMesh(const Mesh& mesh, const sgc::Mat4f& worldTransform, const Material& material) override
void endFrame() override
void finalizeFrame()
[[nodiscard]] int drawCallCount() const noexcept override
void setOutlineEnabled(bool enabled) noexcept override
[[nodiscard]] bool isOutlineEnabled() const noexcept override
void setOutlineMode(OutlineMode mode) noexcept override
[[nodiscard]] OutlineMode outlineMode() const noexcept override
void setTonemapExposure(float exposure) override
[[nodiscard]] float tonemapExposure() const noexcept override
void setTonemapGamma(float gamma) override
[[nodiscard]] float tonemapGamma() const noexcept override
void setFXAAEnabled(bool enabled) noexcept
[[nodiscard]] bool isFXAAEnabled() const noexcept
void setFXAAQuality(float subpixQuality, float edgeThreshold, float edgeThresholdMin) noexcept
[[nodiscard]] ID3D12GraphicsCommandList* getCommandList() noexcept
[[nodiscard]] ID3D12Device* getNativeDevice() noexcept
[[nodiscard]] gfx::Dx12Device* getDx12Device() noexcept
[[nodiscard]] ID3D12Resource* getDepthBuffer() noexcept
[[nodiscard]] ID3D12Resource* getNormalBuffer() noexcept
[[nodiscard]] ID3D12RootSignature* getMainRootSignature() noexcept
[[nodiscard]] ID3D12RootSignature* getOutlinePostRootSig() noexcept
[[nodiscard]] ID3D12DescriptorHeap* getDepthSRVHeap() noexcept
[[nodiscard]] ComPtr<ID3D12Resource> createUploadBufferPublic(UINT64 sizeBytes) const
void keepTempResource(ComPtr<ID3D12Resource> resource)
void restoreMainState()
static void getInputLayout(D3D12_INPUT_ELEMENT_DESC* desc, UINT& count)
void destroy()
[[nodiscard]] bool isFrameActive() const noexcept override
void resetFrameActive() noexcept override
void setOverlayScreen(const Screen* screen) noexcept override
void setLights(std::span<const Light> lights) override
void setUseMultiLight(bool useMulti) override
[[nodiscard]] bool useMultiLight() const noexcept override
void setShaderMode(ShaderMode3D mode) override
[[nodiscard]] ShaderMode3D shaderMode() const noexcept
void setShadowEnabled(bool enabled) noexcept
[[nodiscard]] bool isShadowEnabled() const noexcept
void setShadowDirection(const sgc::Vec3f& dir) noexcept
[[nodiscard]] DirectionalShadowConfig& shadowConfig() noexcept
[[nodiscard]] const DirectionalShadowConfig& shadowConfig() const noexcept
[[nodiscard]] std::span<const Light> lights() const noexcept
void setSkybox(const Cubemap& cubemap) override
void setSkyboxEnabled(bool enabled) override
[[nodiscard]] bool isSkyboxEnabled() const noexcept override
[[nodiscard]] bool hasOverlaySupport() const noexcept override
[[nodiscard]] ID3D12GraphicsCommandList* getCommandList() const noexcept
[[nodiscard]] void* nativeCommandList() const noexcept override
[[nodiscard]] void* nativeDevice() const noexcept override
[[nodiscard]] void* nativeSwapChain() const noexcept override
`constexpr std::string_view PP_SSAO_PS = R"hlsl(
`constexpr std::string_view PP_SSAO_BLUR_PS = R"hlsl(
`constexpr std::string_view PP_SSAO_COMPOSITE_PS = R"hlsl(
Texture2D noiseTexture : register(t1)
SamplerState pointClampSampler : register(s0)
SamplerState noiseWrapSampler : register(s1)
cbuffer SSAOParams : register(b0)
// ── 深度値からビュー空間Z座標を復元する ────────────────── float linearizeDepth(float d)
// ── UV+深度からビュー空間位置を復元する ───────────────── float3 reconstructViewPos(float2 uv, float depth)
// ── 深度バッファから近似法線を求める ──────────────────── float3 estimateNormal(float2 uv, float2 texelSize)
SamplerState pointClampSampler : register(s0)
cbuffer SSAOBlurParams : register(b0)
Texture2D aoTexture : register(t1)
SamplerState linearSampler : register(s0)
struct PSInput 2
float4 position : SV_POSITION
float2 texCoord : TEXCOORD0
struct PSInput 2
float4 position : SV_POSITION
float2 texCoord : TEXCOORD0
struct PSInput 2
float4 position : SV_POSITION
float2 texCoord : TEXCOORD0
struct SSAOConfig 5
float radius = 0.5f
float bias = 0.025f
float intensity = 1.0f
float nearPlane = 0.1f
float farPlane = 100.0f
class SSAOPass : public PostProcessPass 9
template <typename T> using ComPtr = Microsoft::WRL::ComPtr<T>
SSAOPass( ID3D11Device* device, const ComPtr<ID3D11VertexShader>& fullscreenVS, const ComPtr<ID3D11SamplerState>& sampler, std::uint32_t screenW, std::uint32_t screenH)
void setDepthSRV( ID3D11ShaderResourceView* depthSRV) noexcept
void setProjection(const float* proj) noexcept
void setConfig(const SSAOConfig& cfg) noexcept
[[nodiscard]] ID3D11ShaderResourceView* aoSRV() const noexcept
void apply( ID3D11DeviceContext* context, ID3D11ShaderResourceView* inputSRV, ID3D11RenderTargetView* outputRTV, std::uint32_t screenW, std::uint32_t screenH) override
[[nodiscard]] std::string_view name() const noexcept override
[[nodiscard]] const SSAOConfig& config() const noexcept
class Scene3D 8
Scene3D() noexcept = default
void addObject(RenderObject obj)
void addLight(Light light)
void clear()
[[nodiscard]] const std::vector<RenderObject>& objects() const noexcept
[[nodiscard]] const std::vector<Light>& lights() const noexcept
[[nodiscard]] std::size_t objectCount() const noexcept
[[nodiscard]] std::size_t lightCount() const noexcept
class ScenePlacer 5
static void placeOnSurface(Scene3D& scene, const Mesh& mesh, float surfaceY, sgc::Vec2f xz, float scale, const Material& material)
static void place(Scene3D& scene, const Mesh& mesh, sgc::Vec3f position, float scale, const Material& material)
static void placeOnTop(Scene3D& scene, const Mesh& itemMesh, const Mesh& baseMesh, sgc::Vec3f basePosition, float baseScale, sgc::Vec2f offsetXZ, float itemScale, const Material& material)
static void placeRow(Scene3D& scene, const Mesh& mesh, sgc::Vec3f startPos, float spacing, int count, float scale, const Material& material)
[[nodiscard]] inline ScreenshotData capture( const gfx::IDevice& device, int width, int height, std::uint64_t frameNumber = 0)
struct ScreenshotData 9
std::vector<std::uint8_t> pixels
int width = 0
int height = 0
std::uint64_t frameNumber = 0
[[nodiscard]] bool isValid() const noexcept
[[nodiscard]] std::uint8_t pixelR(int x, int y) const noexcept
[[nodiscard]] std::uint8_t pixelG(int x, int y) const noexcept
[[nodiscard]] std::uint8_t pixelB(int x, int y) const noexcept
[[nodiscard]] std::uint8_t pixelA(int x, int y) const noexcept
enum ButtonState 4
Normal
Hovered
Pressed
Disabled
enum NotificationType 4
Info
Success
Warning
Error
enum ArrowDirection 4
Up
Down
Left
Right
struct PanelStyle 6
float cornerRadius = 0.0f
float borderWidth = 0.0f
float shadowBlur = 0.0f
float backdropBlur = 0.0f
float opacity = 1.0f
float gradientAngle = 0.0f
struct ButtonStyle 5
PanelStyle normal
PanelStyle hovered
PanelStyle pressed
PanelStyle disabled
float fontSize = 16.0f
struct CardStyle 5
PanelStyle panel
float titleFontSize = 18.0f
float bodyFontSize = 14.0f
float imageHeight = 120.0f
float padding = 12.0f
struct ProgressBarStyle 3
PanelStyle track
float cornerRadius = 4.0f
float height = 8.0f
struct PostProcessSettings 8
bool bloomEnabled = false
float bloomThreshold = 1.0f
float bloomIntensity = 0.5f
bool vignetteEnabled = false
float vignetteIntensity = 0.3f
float brightness = 1.0f
float contrast = 1.0f
float saturation = 1.0f
class ScreenEnhanced 27
explicit ScreenEnhanced(Screen& screen) noexcept
[[nodiscard]] Screen& screen() noexcept
[[nodiscard]] const Screen& screen() const noexcept
[[nodiscard]] bool hasSdfFont() const noexcept
void setSdfFontReady(bool ready) noexcept
void drawSdfText(const sgc::Vec2f& pos, std::string_view text, float fontSize, const sgc::Colorf& color)
void drawSdfTextWithOutline(const sgc::Vec2f& pos, std::string_view text, float fontSize, const sgc::Colorf& textColor, const sgc::Colorf& outlineColor, float outlineWidth)
void drawSdfTextWithShadow(const sgc::Vec2f& pos, std::string_view text, float fontSize, const sgc::Colorf& textColor, const sgc::Colorf& shadowColor, const sgc::Vec2f& shadowOffset)
void drawRoundedRect(const sgc::Rectf& rect, float cornerRadius, const sgc::Colorf& fillColor)
void drawRoundedRectWithBorder(const sgc::Rectf& rect, float cornerRadius, const sgc::Colorf& fillColor, const sgc::Colorf& borderColor, float borderWidth)
void drawRoundedRectWithShadow(const sgc::Rectf& rect, float cornerRadius, const sgc::Colorf& fillColor, const sgc::Colorf& shadowColor, float shadowBlur, const sgc::Vec2f& shadowOffset)
void drawPill(const sgc::Rectf& rect, const sgc::Colorf& fillColor)
void drawPanel(const sgc::Rectf& rect, const PanelStyle& style)
void drawLinearGradient(const sgc::Rectf& rect, float angleDeg, const sgc::Colorf& colorFrom, const sgc::Colorf& colorTo)
void drawRadialGradient(const sgc::Rectf& rect, const sgc::Colorf& centerColor, const sgc::Colorf& edgeColor)
void drawButton(const sgc::Rectf& rect, std::string_view text, ButtonState state, const ButtonStyle& style)
void drawCard(const sgc::Rectf& rect, std::string_view title, std::string_view body, const Texture* imageTexture, const CardStyle& style)
void drawTooltip(const sgc::Rectf& rect, std::string_view text, ArrowDirection arrowDir)
void drawNotification(const sgc::Rectf& rect, std::string_view icon, std::string_view title, std::string_view message, NotificationType type)
void drawProgressBar(const sgc::Rectf& rect, float progress, const ProgressBarStyle& style)
void beginPostProcess()
void endPostProcess()
void setBloom(bool enabled, float threshold = 1.0f, float intensity = 0.5f) noexcept
void setVignette(bool enabled, float intensity = 0.3f) noexcept
void setColorGrading(float brightness, float contrast, float saturation) noexcept
[[nodiscard]] const PostProcessSettings& postProcessSettings() const noexcept
void drawRoundedRectBorderOnly(const sgc::Rectf& rect, float cornerRadius, const sgc::Colorf& borderColor, float borderWidth)
class SdfTextRenderer 16
SdfTextRenderer() = default
explicit SdfTextRenderer(const SdfFontAtlas& atlas) noexcept
void setAtlas(const SdfFontAtlas& atlas) noexcept
[[nodiscard]] bool ready() const noexcept
[[nodiscard]] SdfTextSize measureText(std::string_view text, float fontSize) const
[[nodiscard]] std::vector<SdfWrappedLine> wrapText( std::string_view text, float fontSize, float maxWidth) const
template <typename BatchType> void drawText(BatchType& batch, std::string_view text, float x, float y, float fontSize, const sgc::Colorf& color) const
template <typename BatchType> void drawTextWithOutline(BatchType& batch, std::string_view text, float x, float y, float fontSize, const sgc::Colorf& textColor, const sgc::Colorf& outlineColor, float outlineWidth = 0.1f) const
template <typename BatchType> void drawTextWithShadow(BatchType& batch, std::string_view text, float x, float y, float fontSize, const sgc::Colorf& textColor, const sgc::Colorf& shadowColor, const sgc::Vec2f& shadowOffset = {2.0f, 2.0f}) const
template <typename BatchType> void drawTextWithGlow(BatchType& batch, std::string_view text, float x, float y, float fontSize, const sgc::Colorf& textColor, const sgc::Colorf& glowColor, float glowRadius = 0.2f) const
template <typename BatchType> void drawTextWithEffect(BatchType& batch, std::string_view text, float x, float y, float fontSize, const sgc::Colorf& textColor, const SdfTextEffect& effect) const
template <typename ScreenType> void drawTextSoftware(ScreenType& screen, std::string_view text, float x, float y, float fontSize, const sgc::Colorf& color) const
template <typename ScreenType> void drawTextSoftwareWithOutline(ScreenType& screen, std::string_view text, float x, float y, float fontSize, const sgc::Colorf& textColor, const sgc::Colorf& outlineColor, float outlineWidth = 0.1f) const
template <typename ScreenType> void drawTextSoftwareWithShadow(ScreenType& screen, std::string_view text, float x, float y, float fontSize, const sgc::Colorf& textColor, const sgc::Colorf& shadowColor, const sgc::Vec2f& shadowOffset = {2.0f, 2.0f}, float shadowSoftness = 0.15f) const
template <typename ScreenType> void drawTextSoftwareWithGlow(ScreenType& screen, std::string_view text, float x, float y, float fontSize, const sgc::Colorf& textColor, const sgc::Colorf& glowColor, float glowRadius = 0.2f) const
template <typename ScreenType> void drawTextSoftwareWithEffect(ScreenType& screen, std::string_view text, float x, float y, float fontSize, const sgc::Colorf& textColor, const SdfTextEffect& effect) const
struct SdfShaderLogic 10
[[nodiscard]] static float textAlpha(float dist, float smoothing) noexcept
[[nodiscard]] static float outlineAlpha(float dist, float smoothing, float outlineWidth) noexcept
[[nodiscard]] static float glowAlpha(float dist, float smoothing, float glowRadius) noexcept
[[nodiscard]] static sgc::Colorf compositeOutline( const sgc::Colorf& textColor, const sgc::Colorf& outlineColor, float textA, float outlineA) noexcept
`constexpr std::string_view GPU_SDF_PS = R"hlsl(
SamplerState samp : register(s0)
cbuffer SdfParams : register(b1)
[[nodiscard]] inline Microsoft::WRL::ComPtr<ID3D11PixelShader> createSdfPixelShader(ID3D11Device* device)
inline void beginSdfRendering(ID3D11DeviceContext* context, SdfFontGpu& gpu, GpuSpriteBatch& batch)
inline void endSdfRendering(ID3D11DeviceContext* context, SdfFontGpu& gpu, GpuSpriteBatch& batch)
struct PSInput 3
float4 position : SV_POSITION
float2 texCoord : TEXCOORD0
float4 color : COLOR0
struct SdfShaderParams 3
float outlineWidth = 0.0f
float glowRadius = 0.0f
float smoothing = 1.0f
class SdfFontGpu 11
SdfFontGpu() noexcept = default
void init(ID3D11Device* device, const SdfFontAtlas& atlas)
void beginSdfRendering(ID3D11DeviceContext* context, GpuSpriteBatch& batch)
void endSdfRendering(ID3D11DeviceContext* context, GpuSpriteBatch& batch)
void drawText(GpuSpriteBatch& batch, std::string_view text, float x, float y, float fontSize, const sgc::Colorf& color)
void drawTextWithOutline(GpuSpriteBatch& batch, std::string_view text, float x, float y, float fontSize, const sgc::Colorf& textColor, const sgc::Colorf& outlineColor, float outlineWidth)
void drawTextWithShadow(GpuSpriteBatch& batch, std::string_view text, float x, float y, float fontSize, const sgc::Colorf& textColor, const sgc::Colorf& shadowColor, float shadowOffsetX, float shadowOffsetY)
void drawTextWithGlow(GpuSpriteBatch& batch, std::string_view text, float x, float y, float fontSize, const sgc::Colorf& textColor, const sgc::Colorf& glowColor, float glowRadius)
[[nodiscard]] bool isInitialized() const noexcept
[[nodiscard]] const GpuTexture2D& atlasTexture() const noexcept
[[nodiscard]] bool isSdfActive() const noexcept
class ShaderLoader 6
static void setShaderDirectory(const std::string& dir)
[[nodiscard]] static const std::string& getShaderDirectory()
[[nodiscard]] static std::optional<std::string> loadFromFile( const std::string& relativePath)
[[nodiscard]] static std::string load( const std::string& relativePath, std::string_view fallback)
static void clearCache()
[[nodiscard]] static const std::string& loadCached( const std::string& relativePath, std::string_view fallback)
struct DirectionalShadowConfig 6
int mapSize = 1024
float orthoHalfExtent = 20.0f
float nearClip = 0.1f
float farClip = 100.0f
float depthBias = 0.001f
float pcfRadius = 1.5f
class DirectionalShadow 6
[[nodiscard]] DirectionalShadowConfig& config() noexcept
[[nodiscard]] const DirectionalShadowConfig& config() const noexcept
void setLightDirection(const sgc::Vec3f& dir) noexcept
[[nodiscard]] sgc::Vec3f lightDirection() const noexcept
[[nodiscard]] sgc::Mat4f lightViewMatrix(const sgc::Vec3f& sceneFocus) const noexcept
[[nodiscard]] sgc::Mat4f lightProjectionMatrix() const noexcept
struct ShadowMapConfig 4
int resolution = 2048
float orthoSize = 50.0f
float nearPlane = 0.1f
float farPlane = 100.0f
class ShadowMap 12
ShadowMap() noexcept = default
void initialize(const ShadowMapConfig& cfg)
[[nodiscard]] bool isInitialized() const noexcept
[[nodiscard]] const ShadowMapConfig& config() const noexcept
void beginShadowPass(const Light& light)
void recordMesh(const Mesh& mesh, const sgc::Mat4f& worldTransform)
void endShadowPass() noexcept
[[nodiscard]] const sgc::Mat4f& lightVP() const noexcept
[[nodiscard]] float sampleDepth(float u, float v) const noexcept
[[nodiscard]] bool isInShadow( const sgc::Vec3f& worldPos, float bias = 0.005f) const noexcept
[[nodiscard]] const std::vector<float>& depthBuffer() const noexcept
constexpr const char* SHADOW_DEPTH_VS = R"hlsl( cbuffer LightVP : register(b0) { float4x4 lightViewProj; }; struct VSInput { float3 position : POSITION; }; struct VSOutput { float4 position : SV_POSITION; }; VSOutput main(VSInput input) { VSOutput o; // 行列は転置済みで upload されるため HLSL では mul(mat, col_vec) = sgc * vec o.position = mul(lightViewProj, float4(input.position, 1.0)); return o; } )hlsl"
struct ShadowMapConfig3D 5
int resolution = 1024
float orthoSize = 15.0f
float nearPlane = 0.1f
float farPlane = 50.0f
float bias = 0.005f
class ShadowPass3D 19
using ComPtr = Microsoft::WRL::ComPtr<ID3D11ShaderResourceView>;
ShadowPass3D() = default
~ShadowPass3D()
ShadowPass3D(const ShadowPass3D&) = delete
ShadowPass3D& operator=(const ShadowPass3D&) = delete
ShadowPass3D(ShadowPass3D&&) = default
ShadowPass3D& operator=(ShadowPass3D&&) = default
void setConfig(const ShadowMapConfig3D& config)
const ShadowMapConfig3D& config() const noexcept
[[nodiscard]] sgc::Mat4f computeLightVP(const Light& light) const noexcept
[[nodiscard]] const sgc::Mat4f& lightViewProjection() const noexcept
void setLightViewProjection(const sgc::Mat4f& vp) noexcept
[[nodiscard]] bool isInitialized() const noexcept
[[nodiscard]] bool init(ID3D11Device* device)
void shutdown()
void beginShadowRender(ID3D11DeviceContext* ctx)
void endShadowRender(ID3D11DeviceContext* ctx)
[[nodiscard]] ID3D11ShaderResourceView* getShadowSRV() const noexcept
[[nodiscard]] void* getShadowSRV() const noexcept
enum ShadowFilterMode 3
Hard
PCF
VSM
struct ShadowConfig 7
int cascadeCount = 4
int mapSize = 2048
ShadowFilterMode filterMode = ShadowFilterMode::PCF
int pcfRadius = 1
float bias = 0.005f
float normalBias = 0.02f
float vsmBlurRadius = 2.0f
struct CascadeInfo 9
sgc::Mat4f lightViewProj
float splitNear = 0.0f
float splitFar = 0.0f
float bias = 0.005f
std::vector<float> depthBuffer
std::vector<float> momentBuffer
Microsoft::WRL::ComPtr<ID3D11Texture2D> shadowTexture
Microsoft::WRL::ComPtr<ID3D11DepthStencilView> dsv
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> srv
class CascadedShadowMap 14
CascadedShadowMap() noexcept = default
void initialize(const ShadowConfig& cfg = {})
[[nodiscard]] bool isInitialized() const noexcept
[[nodiscard]] int cascadeCount() const noexcept
[[nodiscard]] const ShadowConfig& config() const noexcept
[[nodiscard]] const CascadeInfo& cascade(int index) const
void updateCascades(const sgc::Mat4f& cameraView, const sgc::Mat4f& cameraProj, const sgc::Vec3f& lightDir, float cameraNear, float cameraFar)
void beginShadowPass(int cascadeIndex)
void recordMesh(const Mesh& mesh, const sgc::Mat4f& worldTransform)
void endShadowPass()
[[nodiscard]] float sampleShadow(const sgc::Vec3f& worldPos, float cameraDepth) const noexcept
[[nodiscard]] const std::vector<float>& depthBuffer(int cascadeIndex) const
constexpr const char* SHADOWED_VS_3D = R"hlsl( cbuffer CameraVP : register(b0) { float4x4 cameraViewProj; }; cbuffer LightVP : register(b1) { float4x4 lightViewProj; }; struct VSInput { float3 position : POSITION; }; struct VSOutput { float4 clipPos : SV_POSITION; float4 shadowPos : SHADOWPOS; }; VSOutput VSMain(VSInput input) { VSOutput o; float4 worldPos = float4(input.position, 1.0); // 行列は転置済みで upload されるため HLSL では mul(mat, col_vec) = sgc * vec o.clipPos = mul(cameraViewProj, worldPos); o.shadowPos = mul(lightViewProj, worldPos); return o; } )hlsl"
constexpr const char* SHADOWED_PS_3D = R"hlsl( Texture2D<float> shadowMap : register(t0); SamplerComparisonState shadowSampler : register(s0); struct PSInput { float4 clipPos : SV_POSITION; float4 shadowPos : SHADOWPOS; }; float4 PSMain(PSInput input) : SV_TARGET { // shadowPos.xyz / shadowPos.w で NDC→[0,1] テクスチャ座標へ変換 float3 shadowNdc = input.shadowPos.xyz / input.shadowPos.w; float2 shadowUv = shadowNdc.xy * float2(0.5, -0.5) + float2(0.5, 0.5); float receiverZ = shadowNdc.z - 0.005; // バイアス // テクスチャ範囲外はライト扱い float lit = 1.0; if (shadowUv.x >= 0.0 && shadowUv.x <= 1.0 && shadowUv.y >= 0.0 && shadowUv.y <= 1.0) { lit = shadowMap.SampleCmpLevelZero(shadowSampler, shadowUv, receiverZ); } // 視覚スポットチェック用に強コントラスト: シャドウ=黒、ライト=白 // (将来 Phong 拡張時に置き換える) return float4(lit, lit, lit, 1.0); } )hlsl"
class ShapeRenderer 12
void drawCircle(const sgc::Vec2f& center, float radius, const sgc::Colorf& color, int segments = 32)
void drawLine(const sgc::Vec2f& from, const sgc::Vec2f& to, const sgc::Colorf& color, float thickness = 1.0f)
void drawTriangle(const sgc::Vec2f& p0, const sgc::Vec2f& p1, const sgc::Vec2f& p2, const sgc::Colorf& color)
void drawPolygon(std::span<const sgc::Vec2f> points, const sgc::Colorf& color)
void drawEllipse(const sgc::Vec2f& center, float radiusX, float radiusY, const sgc::Colorf& color, int segments = 32)
void drawRing(const sgc::Vec2f& center, float outerR, float innerR, const sgc::Colorf& color, int segments = 32)
void flush() noexcept
[[nodiscard]] std::size_t vertexCount() const noexcept
[[nodiscard]] std::size_t indexCount() const noexcept
[[nodiscard]] int drawCallCount() const noexcept
[[nodiscard]] const std::vector<Vertex2D>& vertices() const noexcept
[[nodiscard]] const std::vector<std::uint32_t>& indices() const noexcept
struct Bone 4
std::string name
int parentIndex = -1
sgc::Mat4f bindPose
sgc::Mat4f localTransform
struct AnimationKeyframe 1
float time = 0.0f
struct BoneTrack 2
int boneIndex = -1
std::vector<AnimationKeyframe> keyframes
struct AnimationClip 4
std::string name
float duration = 0.0f
bool looping = true
std::vector<BoneTrack> tracks
struct MorphTarget 3
std::string name
std::vector<sgc::Vec3f> positionDeltas
float weight = 0.0f
class Skeleton 7
void addBone(const Bone& bone)
[[nodiscard]] int boneCount() const noexcept
[[nodiscard]] const Bone& bone(int index) const
Bone& bone(int index)
[[nodiscard]] int findBone(const std::string& name) const
[[nodiscard]] std::vector<sgc::Mat4f> computeWorldTransforms() const
[[nodiscard]] std::vector<sgc::Mat4f> computeSkinningMatrices() const
class AnimationPlayer3D 6
void setSkeleton(Skeleton* skeleton) noexcept
void play(const AnimationClip& clip)
void stop()
void update(float dt)
[[nodiscard]] bool isPlaying() const noexcept
[[nodiscard]] float currentTime() const noexcept
class Skybox 15
template <typename T> using ComPtr = Microsoft::WRL::ComPtr<T>
Skybox() = default
explicit Skybox(Cubemap cubemap) noexcept
[[nodiscard]] const Cubemap& cubemap() const noexcept
void setCubemap(Cubemap cubemap) noexcept
[[nodiscard]] bool hasValidCubemap() const noexcept
[[nodiscard]] bool isInitialized() const noexcept
bool initializeDx11(gfx::Dx11Device* device)
bool initializeDx11(ID3D11Device* d3d)
void drawDx11(ID3D11DeviceContext* ctx, const Camera3D& camera) const
void drawDx11(ID3D11DeviceContext* ctx, const sgc::Mat4f& viewMatrix, const sgc::Mat4f& projMatrix) const
bool initializeDx11(void* )
void drawDx11(void* , const Camera3D& ) const
inline constexpr const char* SKYBOX_VS_HLSL = R"HLSL( cbuffer CbSkyTransform : register(b0) { float4x4 viewNoTranslation; float4x4 projection; }; struct VSIn { float3 pos : POSITION; }; struct VSOut { float4 svpos : SV_POSITION; float3 dir : TEXCOORD0; }; VSOut VSMain(VSIn i) { VSOut o; o.dir = i.pos; float4 wp = mul(float4(i.pos, 0.0), viewNoTranslation); wp = mul(wp, projection); // svpos.z = w -> NDC z = 1, i.e. furthest plane, so depth test // LESS_EQUAL with a cleared 1.0 depth buffer leaves the skybox // visible only where no scene geometry has drawn. o.svpos = wp.xyww; return o; } )HLSL"
inline constexpr const char* SKYBOX_PS_HLSL = R"HLSL( TextureCube g_sky : register(t0); SamplerState g_samp : register(s0); struct VSOut { float4 svpos : SV_POSITION; float3 dir : TEXCOORD0; }; float4 PSMain(VSOut i) : SV_TARGET { return g_sky.Sample(g_samp, normalize(i.dir)); } )HLSL"
struct Triangle3D 5
sgc::Vec3f a
sgc::Vec3f b
sgc::Vec3f c
sgc::Colorf color
[[nodiscard]] float avgZ() const noexcept
class SoftwareRenderer3D 17
SoftwareRenderer3D(float screenW, float screenH) noexcept
void setCamera(const sgc::Vec3f& eye, const sgc::Vec3f& target, const sgc::Vec3f& up)
void setProjection(float fovRad, float nearZ, float farZ)
[[nodiscard]] sgc::Vec2f project(const sgc::Vec3f& worldPos) const
void drawTriangle3D(Screen& screen, const sgc::Vec3f& a, const sgc::Vec3f& b, const sgc::Vec3f& c, const sgc::Colorf& color) const
void drawBox(Screen& screen, const sgc::Vec3f& center, const sgc::Vec3f& size, const sgc::Colorf& color) const
void drawAxes(Screen& screen, float length) const
void drawFilledTriangle3D(Screen& screen, const sgc::Vec3f& a, const sgc::Vec3f& b, const sgc::Vec3f& c, const sgc::Colorf& color) const
void drawFilledBox(Screen& screen, const sgc::Vec3f& center, const sgc::Vec3f& size, const sgc::Colorf& color) const
void drawFilledPyramid(Screen& screen, const sgc::Vec3f& base, float baseSize, float height, const sgc::Colorf& color) const
void drawSphere(Screen& screen, const sgc::Vec3f& center, float radius, int rings, int segments, const sgc::Colorf& color) const
void drawFloorPlane(Screen& screen, const sgc::Vec3f& center, float extent, const sgc::Colorf& color) const
void drawGrid(Screen& screen, float extent, int divisions, const sgc::Colorf& color) const
void drawScene(Screen& screen, std::vector<Triangle3D>& tris) const
void drawTexturedTriangle3D(Screen& screen, const sgc::Vec3f& a, const sgc::Vec3f& b, const sgc::Vec3f& c, const Texture& tex, float u0, float v0, float u1, float v1, float u2, float v2) const
void drawTexturedQuad3D(Screen& screen, const sgc::Vec3f& v0, const sgc::Vec3f& v1, const sgc::Vec3f& v2, const sgc::Vec3f& v3, const Texture& tex) const
void drawTexturedBox(Screen& screen, const sgc::Vec3f& center, const sgc::Vec3f& size, const Texture& tex) const
class OctreeNode 5
explicit OctreeNode(const AABB& bounds, int maxDepth = 6, int maxObjects = 8) noexcept
void insert(const T& object, const AABB& objBounds)
[[nodiscard]] std::vector<T> query(const AABB& region) const
void clear() noexcept
[[nodiscard]] std::size_t size() const noexcept
class GridPartition2D 6
GridPartition2D(float originX, float originY, float width, float height, float cellSize)
void insert(const T& object, float x, float y)
[[nodiscard]] std::vector<T> queryRadius(float cx, float cy, float radius) const
void clear()
[[nodiscard]] int cols() const noexcept
[[nodiscard]] int rows() const noexcept
enum SpritePivot : std::uint8_t 12
Center
BottomCenter
[[nodiscard]] inline sgc::Mat4f cylindricalBillboardMatrix( const sgc::Vec3f& objectPos, const sgc::Vec3f& cameraPos) noexcept
[[nodiscard]] inline float bounceOut(float t) noexcept
[[nodiscard]] inline float elasticOut(float t) noexcept
[[nodiscard]] inline float cubicOut(float t) noexcept
[[nodiscard]] inline float backOut(float t, float overshoot = 1.70158f) noexcept
[[nodiscard]] inline sgc::Mat4f popupRotationMatrix(float angle) noexcept
[[nodiscard]] inline sgc::Mat4f sprite3DWorldMatrix( const sgc::Vec3f& position, const sgc::Vec3f& cameraPos, float popupAngle = 0.0f, float scale = 1.0f) noexcept
constexpr const char* SPRITE3D_VERTEX_SHADER = R"glsl(#version 300 es precision highp float; layout(location = 0) in vec3 aPos; layout(location = 1) in vec2 aTexCoord; uniform mat4 uMVP; out vec2 vTexCoord; void main() { gl_Position = uMVP * vec4(aPos, 1.0); vTexCoord = aTexCoord; } )glsl"
constexpr const char* SPRITE3D_FRAGMENT_SHADER = R"glsl(#version 300 es precision highp float; in vec2 vTexCoord; uniform sampler2D uTexture; uniform vec4 uTint; // スプライトのティント色(デフォルト白) uniform float uAlphaClip; // アルファクリッピング閾値(通常0.1〜0.5) out vec4 fragColor; void main() { vec4 texel = texture(uTexture, vTexCoord) * uTint; // アルファクリッピング: // 透過ピクセル(α < threshold)を完全に破棄し、 // Zバッファへの書き込みを防ぐ。 // これにより半透明の重なり順が正しく処理される。 if (texel.a < uAlphaClip) { discard; } fragColor = texel; } )glsl"
constexpr const char* SPRITE3D_FLAT_FRAGMENT_SHADER = R"glsl(#version 300 es precision highp float; in vec2 vTexCoord; uniform vec4 uTint; uniform float uAlphaClip; out vec4 fragColor; void main() { if (uTint.a < uAlphaClip) { discard; } fragColor = uTint; } )glsl"
struct Vertex3DSprite 2
sgc::Vec3f position
sgc::Vec2f texCoord
struct QuadMesh 3
std::array<Vertex3DSprite, 4> vertices
std::array<std::uint32_t, 6> indices
[[nodiscard]] static QuadMesh create(float width, float height, SpritePivot pivot = SpritePivot::Center) noexcept
struct PopupAnimation 8
float duration = 0.4f
float elapsed = 0.0f
bool active = false
bool finished = false
void start(float dur = 0.4f) noexcept
void update(float dt) noexcept
[[nodiscard]] float progress() const noexcept
[[nodiscard]] float rotationX() const noexcept
struct Sprite3DInstance 8
float width = 1.0f
float height = 1.5f
float scale = 1.0f
float alphaClip = 0.1f
SpritePivot pivot = SpritePivot::BottomCenter
PopupAnimation popup
bool billboard = true
[[nodiscard]] sgc::Mat4f worldMatrix( const sgc::Vec3f& cameraPos, const sgc::Vec3f* cameraRight = nullptr, const sgc::Vec3f* cameraUp = nullptr) const noexcept
class Sprite3DRenderer 5
bool init()
void submit(const Sprite3DInstance& instance, GLuint textureId = 0)
void flush(const Camera3D& camera)
[[nodiscard]] GLuint loadTexture(const std::string& path)
[[nodiscard]] bool isInitialized() const noexcept
enum AnimatorState 4
Playing
Paused
Stopped
Finished
enum AnimatorDirection 2
Forward
Reverse
struct SpriteFrame 3
float duration = 0.1f
float offsetX = 0.0f
float offsetY = 0.0f
struct SpriteAnimation 5
std::string name
std::vector<SpriteFrame> frames
bool looping = false
bool pingPong = false
[[nodiscard]] float totalDuration() const noexcept
class SpriteAnimationSet 6
void add(const SpriteAnimation& animation)
void add(SpriteAnimation&& animation)
[[nodiscard]] const SpriteAnimation* get(const std::string& name) const
[[nodiscard]] std::vector<std::string> names() const
[[nodiscard]] std::size_t count() const noexcept
[[nodiscard]] bool contains(const std::string& name) const
class SpriteSheet 9
SpriteSheet() = default
[[nodiscard]] static SpriteSheet create(const Texture& texture, int frameWidth, int frameHeight, int frameCount = 0)
[[nodiscard]] static SpriteSheet createFromFrames(const Texture& texture, std::vector<SpriteFrame> frames)
[[nodiscard]] SpriteFrame getFrame(int index) const
[[nodiscard]] int frameCount() const noexcept
[[nodiscard]] const Texture& texture() const noexcept
[[nodiscard]] int frameWidth() const noexcept
[[nodiscard]] int frameHeight() const noexcept
[[nodiscard]] const std::vector<SpriteFrame>& frames() const noexcept
class SpriteAnimator 20
using AnimationCallback = std::function<void(const std::string& animationName)>;
using FrameCallback = std::function<void(int frameIndex)>;
void setAnimationSet(const SpriteAnimationSet& animationSet)
void play(const std::string& animationName)
void pause() noexcept
void resume() noexcept
void stop() noexcept
void update(float dt)
[[nodiscard]] SpriteFrame currentFrame() const
[[nodiscard]] int currentFrameIndex() const noexcept
[[nodiscard]] bool isPlaying() const noexcept
[[nodiscard]] bool isFinished() const noexcept
[[nodiscard]] AnimatorState state() const noexcept
void setSpeed(float multiplier) noexcept
[[nodiscard]] float speed() const noexcept
void setDirection(AnimatorDirection direction) noexcept
[[nodiscard]] AnimatorDirection direction() const noexcept
[[nodiscard]] const std::string& currentAnimationName() const noexcept
void onAnimationComplete(AnimationCallback callback)
void onFrameChanged(FrameCallback callback)
class SpriteAnimationBuilder 7
explicit SpriteAnimationBuilder(std::string name)
SpriteAnimationBuilder& addFrame(const sgc::Recti& sourceRect, float duration, float offsetX = 0.0f, float offsetY = 0.0f)
SpriteAnimationBuilder& addFrame(const SpriteFrame& frame)
SpriteAnimationBuilder& addFramesFromSheet(const SpriteSheet& sheet, int startIndex, int count, float frameDuration)
SpriteAnimationBuilder& setLooping(bool looping)
SpriteAnimationBuilder& setPingPong(bool pingPong)
[[nodiscard]] SpriteAnimation build() const
class SpriteAnimationCache 7
void store(const std::string& name, const SpriteAnimationSet& animationSet)
void store(const std::string& name, SpriteAnimationSet&& animationSet)
[[nodiscard]] const SpriteAnimationSet* retrieve(const std::string& name) const
[[nodiscard]] bool contains(const std::string& name) const
bool remove(const std::string& name)
void clear()
[[nodiscard]] std::size_t count() const noexcept
class SpriteBatch 14
void begin() noexcept
void drawSprite(std::uint32_t textureId, const sgc::Rectf& destRect, const sgc::Rectf& srcRect, const sgc::Colorf& color, float rotation = 0.0f)
void drawRect(const sgc::Rectf& rect, const sgc::Colorf& color)
void drawRectGradient4(const sgc::Rectf& rect, const sgc::Colorf& tl, const sgc::Colorf& tr, const sgc::Colorf& br, const sgc::Colorf& bl)
void drawQuadGradient4(const sgc::Vec2f corners[4], const sgc::Colorf& tl, const sgc::Colorf& tr, const sgc::Colorf& br, const sgc::Colorf& bl)
void drawRectFrame(const sgc::Rectf& rect, const sgc::Colorf& color, float thickness = 1.0f)
void end() noexcept
[[nodiscard]] std::size_t vertexCount() const noexcept
[[nodiscard]] std::size_t indexCount() const noexcept
[[nodiscard]] int drawCallCount() const noexcept
[[nodiscard]] const std::vector<Vertex2D>& vertices() const noexcept
[[nodiscard]] const std::vector<std::uint32_t>& indices() const noexcept
using TextureId = std::uint32_t;
inline constexpr TextureId kInvalidTextureId = 0
class SpriteRenderer 15
SpriteRenderer() = default
~SpriteRenderer()
SpriteRenderer(const SpriteRenderer&) = delete
SpriteRenderer& operator=(const SpriteRenderer&) = delete
SpriteRenderer(SpriteRenderer&& other) noexcept
SpriteRenderer& operator=(SpriteRenderer&& other) noexcept
bool init(ID3D11Device* device, ID3D11DeviceContext* context) noexcept
[[nodiscard]] TextureId loadTexture(const std::string& path)
[[nodiscard]] TextureId createFromPixels(std::uint32_t width, std::uint32_t height, const void* pixels)
void drawSprite(TextureId tex, const sgc::Rectf& dest, const sgc::Rectf& src = {}, float alpha = 1.0f, bool flipX = false)
[[nodiscard]] ID3D11ShaderResourceView* getSRV(TextureId tex) const
[[nodiscard]] std::uint32_t getWidth(TextureId tex) const noexcept
[[nodiscard]] std::uint32_t getHeight(TextureId tex) const noexcept
[[nodiscard]] std::size_t textureCount() const noexcept
void release()
struct PackedSprite 3
std::string name
sgc::Rectf sourceRect
sgc::Rectf destRect
struct PackResult 5
Texture atlas
std::vector<PackedSprite> sprites
int atlasWidth = 0
int atlasHeight = 0
bool success = false
class SpriteSheetPacker 8
SpriteSheetPacker() = default
void addImage(std::string_view name, const Texture& texture)
void addDirectory(std::string_view path, std::string_view extension)
[[nodiscard]] PackResult pack(int maxWidth = 2048, int maxHeight = 2048, int padding = 1)
[[nodiscard]] std::string exportJson() const
[[nodiscard]] Texture exportTexture() const
void clear()
[[nodiscard]] std::size_t sourceCount() const noexcept
struct AsepriteParseResult 2
SpriteSheet sheet
SpriteAnimationSet animations
class SpriteSheetParser 2
[[nodiscard]] static SpriteAnimationSet parseAsepriteJson(const std::string& jsonString)
[[nodiscard]] static AsepriteParseResult parseAsepriteJsonWithTexture( const std::string& jsonString, const Texture& texture)
enum Edge 4
Top
Right
Bottom
Left
enum PathCommand : uint8_t 7
MoveTo
LineTo
QuadTo
CubicTo
Close
using Fill = Gradient;
`using ShapeData = std::variant< ShapeRect, ShapeCircle, ShapeEllipse, ShapeTriangle, ShapeLine, ShapeArc, ShapePie, ShapeRing, ShapePolygon, ShapePath>;`
struct Color 7
static constexpr sgc::Colorf hex(uint32_t rgb)
static constexpr sgc::Colorf rgb(uint8_t r, uint8_t g, uint8_t b)
static constexpr sgc::Colorf rgba(uint8_t r, uint8_t g, uint8_t b, float a)
static constexpr sgc::Colorf rgba(float r, float g, float b, float a)
static constexpr sgc::Colorf white()
static constexpr sgc::Colorf black()
static constexpr sgc::Colorf transparent()
struct ColorStop 1
float offset = 0
struct Gradient 10
enum `Type` { Solid, Linear, Radial }
Type type = Type::Solid
float angle = 0
float radius = 0.5f
uint8_t stopCount = 0
static Gradient solid(sgc::Colorf c)
static Gradient linear(float angleDeg, std::initializer_list<ColorStop> stopList)
static Gradient radial(sgc::Vec2f ctr, float rad, std::initializer_list<ColorStop> stopList)
Gradient(sgc::Colorf c)
Gradient() = default
struct Shadow 3
float x = 0
float y = 0
float blur = 0
struct Corners 5
float tl = 0
float tr = 0
float br = 0
float bl = 0
static constexpr Corners all(float r)
struct Stroke 1
float width = 0
struct StyleTransform 1
float rotate = 0
struct Style 3
float opacity = 1.0f
static Style lerp(const Style& a, const Style& b, float t)
static Style merge(const Style& base, const Style& over)
struct ZigzagStyle 2
float toothSize = 12
Edge edge = Edge::Bottom
struct ShapeRect 1
sgc::Rectf rect
struct ShapeCircle 2
sgc::Vec2f center
float radius = 0
struct ShapeEllipse 3
sgc::Vec2f center
float rx = 0
float ry = 0
struct ShapeTriangle 3
sgc::Vec2f p0
sgc::Vec2f p1
sgc::Vec2f p2
struct ShapeLine 3
sgc::Vec2f from
sgc::Vec2f to
float thickness = 1
struct ShapeArc 4
sgc::Vec2f center
float radius = 0
float startAngle = 0
float endAngle = 0
struct ShapePie 4
sgc::Vec2f center
float radius = 0
float startAngle = 0
float endAngle = 0
struct ShapeRing 3
sgc::Vec2f center
float outer = 0
float inner = 0
struct ShapePolygon 1
std::vector<sgc::Vec2f> points
struct PathPoint 1
PathCommand cmd = PathCommand::MoveTo
struct ShapePath 6
std::vector<PathPoint> commands
ShapePath& moveTo(float x, float y)
ShapePath& lineTo(float x, float y)
ShapePath& quadTo(float cx, float cy, float x, float y)
ShapePath& cubicTo(float c1x, float c1y, float c2x, float c2y, float x, float y)
ShapePath& close()
struct StyledVertex2D 2
constexpr StyledVertex2D() noexcept = default
constexpr StyledVertex2D(const sgc::Vec2f& pos, const sgc::Vec2f& uv, const sgc::Colorf& col, const sgc::Vec4f& rect) noexcept
class StyledRectBatch 7
void begin() noexcept
void addRect(const sgc::Rectf& rect, const Style& style, const Transform2D& worldXform = Transform2D::identity())
void end() noexcept
[[nodiscard]] const std::vector<StyledVertex2D>& vertices() const noexcept
[[nodiscard]] const std::vector<std::uint32_t>& indices() const noexcept
[[nodiscard]] const StyleConstants& currentStyle() const noexcept
[[nodiscard]] bool hasData() const noexcept
class StyledCircleBatch 8
void begin() noexcept
void addCircle(const sgc::Vec2f& center, float radius, const Style& style, const Transform2D& worldXform = Transform2D::identity())
void addEllipse(const sgc::Vec2f& center, float rx, float ry, const Style& style, const Transform2D& worldXform = Transform2D::identity())
void end() noexcept
[[nodiscard]] const std::vector<StyledVertex2D>& vertices() const noexcept
[[nodiscard]] const std::vector<std::uint32_t>& indices() const noexcept
[[nodiscard]] const StyleConstants& currentStyle() const noexcept
[[nodiscard]] bool hasData() const noexcept
class StyledShapeRenderer 14
void begin()
void end()
void drawCircle(const ShapeCircle& shape, const Style& style)
void drawEllipse(const ShapeEllipse& shape, const Style& style)
void drawTriangle(const ShapeTriangle& shape, const Style& style)
void drawLine(const ShapeLine& shape, const Style& style)
void drawArc(const ShapeArc& shape, const Style& style)
void drawPie(const ShapePie& shape, const Style& style)
void drawRing(const ShapeRing& shape, const Style& style)
void drawPolygon(const ShapePolygon& shape, const Style& style)
void drawPath(const ShapePath& shape, const Style& style)
[[nodiscard]] const std::vector<Vertex2D>& vertices() const
[[nodiscard]] const std::vector<uint32_t>& indices() const
[[nodiscard]] bool hasData() const
enum SSSProfile : int 8
Skin = 0
Marble
Wax
Milk
`constexpr std::string_view SSS_BLUR_PS = R"hlsl(
Texture2D depthTexture : register(t1)
SamplerState linearClampSampler : register(s0)
cbuffer SSSParams : register(b0)
struct PSInput 2
float4 position : SV_Position
float2 uv : TEXCOORD0
struct SSSConfig 4
float sssWidth = 0.012f
float maxDepthDiff = 0.01f
float correction = 80.0f
bool enabled = true
class SubsurfaceScatterEffect 23
template <typename T> using ComPtr = Microsoft::WRL::ComPtr<T>
SubsurfaceScatterEffect() = default
~SubsurfaceScatterEffect() = default
SubsurfaceScatterEffect(const SubsurfaceScatterEffect&) = delete
SubsurfaceScatterEffect& operator=(const SubsurfaceScatterEffect&) = delete
SubsurfaceScatterEffect(SubsurfaceScatterEffect&&) noexcept = default
SubsurfaceScatterEffect& operator=(SubsurfaceScatterEffect&&) noexcept = default
bool init(ID3D11Device* device, int width, int height)
void apply(ID3D11DeviceContext* context, ID3D11ShaderResourceView* sceneSRV, ID3D11ShaderResourceView* depthSRV, ID3D11RenderTargetView* outputRTV) const
void setProfile(SSSProfile profile) noexcept
[[nodiscard]] SSSConfig& config() noexcept
[[nodiscard]] const SSSConfig& config() const noexcept
[[nodiscard]] ID3D11ShaderResourceView* pingRTSRV() const noexcept
`constexpr std::string_view TAA_RESOLVE_PS = R"hlsl(
`constexpr std::string_view TAA_COPY_PS = R"hlsl(
Texture2D historyTexture : register(t1)
Texture2D depthTexture : register(t2)
SamplerState linearClampSampler : register(s0)
SamplerState pointClampSampler : register(s1)
cbuffer TAAParams : register(b0)
// ── 近傍のAABBを計算する ───────────────────────── void computeNeighborhoodAABB( float2 uv, float2 texel, out float3 aabbMin, out float3 aabbMax)
// ── ヒストリー色をAABBにクランプする ────────────────── float3 clipToAABB(float3 color, float3 aabbMin, float3 aabbMax)
SamplerState pointClampSampler : register(s0)
struct PSInput 2
float4 position : SV_POSITION
float2 texCoord : TEXCOORD0
struct PSInput 2
float4 position : SV_POSITION
float2 texCoord : TEXCOORD0
struct TAAConfig 2
float blendFactor = 0.1f
float motionScale = 1.0f
class TAAEffect 8
template <typename T> using ComPtr = Microsoft::WRL::ComPtr<T>
void init(ID3D11Device* device, std::uint32_t screenW, std::uint32_t screenH)
void setDepthSRV( ID3D11ShaderResourceView* depthSRV) noexcept
void setConfig(const TAAConfig& cfg) noexcept
[[nodiscard]] const TAAConfig& config() const noexcept
[[nodiscard]] std::array<float, 2> currentJitter() const noexcept
void advanceFrame() noexcept
void apply( ID3D11DeviceContext* context, ID3D11ShaderResourceView* inputSRV, ID3D11RenderTargetView* outputRTV, std::uint32_t screenW, std::uint32_t screenH)
class Texture 9
Texture() = default
Texture(int width, int height, const std::vector<std::uint8_t>& pixels)
[[nodiscard]] static Texture solid(int w, int h, std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t a = 255)
[[nodiscard]] static Texture checker(int w, int h, int tileSize, std::uint8_t r1, std::uint8_t g1, std::uint8_t b1, std::uint8_t r2, std::uint8_t g2, std::uint8_t b2)
[[nodiscard]] int width() const noexcept
[[nodiscard]] int height() const noexcept
[[nodiscard]] const std::vector<std::uint8_t>& pixels() const noexcept
[[nodiscard]] bool valid() const noexcept
[[nodiscard]] std::uint32_t pixelAt(int x, int y) const
struct AtlasRegion 11
int x = 0
int y = 0
int width = 0
int height = 0
int atlasWidth = 0
int atlasHeight = 0
[[nodiscard]] float u0() const noexcept
[[nodiscard]] float v0() const noexcept
[[nodiscard]] float u1() const noexcept
[[nodiscard]] float v1() const noexcept
[[nodiscard]] bool valid() const noexcept
class TextureAtlas 10
explicit TextureAtlas(int atlasSize = 2048)
AtlasRegion add(const std::string& name, const Texture& tex)
[[nodiscard]] AtlasRegion getRegion(const std::string& name) const
[[nodiscard]] const Texture& texture() const noexcept
[[nodiscard]] int regionCount() const noexcept
[[nodiscard]] int atlasSize() const noexcept
constexpr std::uint32_t FLIPPED_HORIZONTALLY = 0x80000000u
constexpr std::uint32_t FLIPPED_VERTICALLY = 0x40000000u
constexpr std::uint32_t FLIPPED_DIAGONALLY = 0x20000000u
`constexpr std::uint32_t ALL_FLAGS = FLIPPED_HORIZONTALLY | FLIPPED_VERTICALLY | FLIPPED_DIAGONALLY`
struct TiledObject 9
int id = 0
std::string name
std::string type
float x = 0.0f
float y = 0.0f
float width = 0.0f
float height = 0.0f
bool visible = true
[[nodiscard]] sgc::Rectf toRect() const noexcept
struct TiledObjectLayer 3
std::string name
std::vector<TiledObject> objects
bool visible = true
struct TiledMapResult 5
Tilemap tilemap
std::vector<TiledObjectLayer> objectLayers
[[nodiscard]] const TiledObjectLayer* findObjectLayer( const std::string& name) const
[[nodiscard]] std::vector<sgc::Rectf> collectCollisionRects() const
[[nodiscard]] std::vector<TiledObject> findObjectsByType( const std::string& typeName) const
class TiledMapLoader 1
[[nodiscard]] static std::optional<TiledMapResult> loadTiledMap( const std::string& jsonString)
enum TileFlip : std::uint8_t 4
None = 0
Horizontal = 1 << 0
Vertical = 1 << 1
Diagonal = 1 << 2
enum AutoTileNeighbor : std::uint8_t 14
None = 0
Top = 1 << 0
TopRight = 1 << 1
Right = 1 << 2
BottomRight= 1 << 3
Bottom = 1 << 4
BottomLeft = 1 << 5
Left = 1 << 6
TopLeft = 1 << 7
[[nodiscard]] constexpr TileFlip operator|(TileFlip a, TileFlip b) noexcept
[[nodiscard]] constexpr TileFlip operator&(TileFlip a, TileFlip b) noexcept
[[nodiscard]] constexpr bool hasFlag(TileFlip flags, TileFlip test) noexcept
[[nodiscard]] constexpr AutoTileNeighbor operator|(AutoTileNeighbor a, AutoTileNeighbor b) noexcept
[[nodiscard]] constexpr AutoTileNeighbor operator&(AutoTileNeighbor a, AutoTileNeighbor b) noexcept
struct TilesetConfig 9
Texture texture
int tileWidth = 16
int tileHeight = 16
int columns = 1
int spacing = 0
int margin = 0
int firstGid = 1
[[nodiscard]] sgc::Rectf getTileRect(int tileId) const noexcept
[[nodiscard]] sgc::Rectf getTileUV(int tileId) const noexcept
struct AnimatedTile 3
std::vector<int> tileIds
float frameDuration = 0.2f
[[nodiscard]] int currentTileId(float elapsedTime) const noexcept
struct AutoTileRules 4
std::unordered_map<std::uint8_t, int> maskToTileId
int defaultTileId = 0
void addRule(std::uint8_t mask, int tileId)
[[nodiscard]] int resolve(std::uint8_t mask) const
struct TilemapLayer 15
std::string name
int width = 0
int height = 0
std::vector<int> data
bool visible = true
float opacity = 1.0f
float offsetX = 0.0f
float offsetY = 0.0f
float parallaxX = 1.0f
float parallaxY = 1.0f
[[nodiscard]] int getTile(int tileX, int tileY) const noexcept
void setTile(int tileX, int tileY, int tileId) noexcept
[[nodiscard]] TileFlip getFlip(int tileX, int tileY) const noexcept
void setFlip(int tileX, int tileY, TileFlip flip) noexcept
void resize(int w, int h)
struct Tilemap 5
std::vector<TilemapLayer> layers
std::vector<TilesetConfig> tilesets
int mapWidth = 0
int mapHeight = 0
[[nodiscard]] const TilesetConfig* findTileset(int gid) const noexcept
class TilemapCollision 8
TilemapCollision(const TilemapLayer& collisionLayer, int tileWidth, int tileHeight, std::vector<int> solidTileIds = {})
[[nodiscard]] bool isSolid(int tileX, int tileY) const noexcept
[[nodiscard]] int getTileAt(float worldX, float worldY) const noexcept
[[nodiscard]] sgc::Rectf getCollisionRect(int tileX, int tileY) const noexcept
[[nodiscard]] bool overlapsAnySolid(const sgc::Rectf& rect) const noexcept
[[nodiscard]] const TilemapLayer& layer() const noexcept
[[nodiscard]] int tileWidth() const noexcept
[[nodiscard]] int tileHeight() const noexcept
class TilemapRenderer 21
TilemapRenderer() noexcept = default
void setAnimatedTile(int baseTileId, AnimatedTile anim)
void removeAnimatedTile(int baseTileId)
void updateAnimation(float dt) noexcept
void resetAnimation() noexcept
void setAutoTileRules(int terrainTileId, AutoTileRules rules)
void applyAutoTile(TilemapLayer& layer, int terrainTileId) const
void drawLayer(Screen& screen, const TilemapLayer& layer, const TilesetConfig& tileset, float cameraX, float cameraY, float viewportW, float viewportH) const
void drawTilemap(Screen& screen, const Tilemap& tilemap, float cameraX, float cameraY) const
void drawTilemap(Screen& screen, const Tilemap& tilemap, float cameraX, float cameraY, float viewportW, float viewportH) const
[[nodiscard]] int lastDrawnTileCount() const noexcept
[[nodiscard]] float elapsedTime() const noexcept
constexpr const char* kTOON_VS = R"hlsl( cbuffer CbToon : register(b0) { float4x4 World; float4x4 View; float4x4 Projection; float3 CameraPos; float _pad0; float3 LightDir; float _pad1; // lighting params (pixel shader only) float4 BandThresholds[2]; // 8 floats packed into 2 float4 float4 BandBrightness[2]; int BandCount; float AmbientStrength; float SpecularSize; float SpecularSmoothness; float4 SpecularColor; float4 ShadowColor; float RimEnabled; float RimWidth; float RimSmoothness; float _pad2; float4 RimColor; }; struct VSInput { float3 Position : POSITION; float3 Normal : NORMAL; float2 TexCoord : TEXCOORD0; float4 Color : COLOR0; }; struct VSOutput { float4 Position : SV_POSITION; float3 WorldPos : TEXCOORD0; float3 WorldNorm : TEXCOORD1; float2 TexCoord : TEXCOORD2; float4 Color : COLOR0; float3 ViewDir : TEXCOORD3; }; VSOutput VSMain(VSInput input) { VSOutput output; float4 worldPos = mul(float4(input.Position, 1.0), World); output.WorldPos = worldPos.xyz; output.WorldNorm = normalize(mul(input.Normal, (float3x3)World)); float4 viewPos = mul(worldPos, View); output.Position = mul(viewPos, Projection); output.TexCoord = input.TexCoord; output.Color = input.Color; output.ViewDir = normalize(CameraPos - worldPos.xyz); return output; } )hlsl"
constexpr const char* kTOON_PS = R"hlsl( cbuffer CbToon : register(b0) { float4x4 World; float4x4 View; float4x4 Projection; float3 CameraPos; float _pad0; float3 LightDir; float _pad1; float4 BandThresholds[2]; // [0].xyzw = bands 0-3, [1].xyzw = bands 4-7 float4 BandBrightness[2]; int BandCount; float AmbientStrength; float SpecularSize; float SpecularSmoothness; float4 SpecularColor; float4 ShadowColor; float RimEnabled; float RimWidth; float RimSmoothness; float _pad2; float4 RimColor; }; Texture2D albedoTex : register(t0); SamplerState sampLinear : register(s0); struct PSInput { float4 Position : SV_POSITION; float3 WorldPos : TEXCOORD0; float3 WorldNorm : TEXCOORD1; float2 TexCoord : TEXCOORD2; float4 Color : COLOR0; float3 ViewDir : TEXCOORD3; }; float getBandThreshold(int idx) { return (idx < 4) ? BandThresholds[0][idx] : BandThresholds[1][idx - 4]; } float getBandBrightness(int idx) { return (idx < 4) ? BandBrightness[0][idx] : BandBrightness[1][idx - 4]; } float4 PSMain(PSInput input) : SV_TARGET { float3 N = normalize(input.WorldNorm); float3 L = normalize(-LightDir); float3 V = normalize(input.ViewDir); float3 H = normalize(L + V); float NdotL = dot(N, L); float NdotH = max(dot(N, H), 0.0); float NdotV = max(dot(N, V), 0.0); // --- N-band quantized diffuse --- float brightness = getBandBrightness(BandCount - 1); // darkest band default for (int i = 0; i < BandCount; ++i) { float threshold = getBandThreshold(i); float edge = smoothstep(threshold - 0.02, threshold + 0.02, NdotL); brightness = lerp(brightness, getBandBrightness(i), edge); } // shadow color tinting: blend toward shadow color in dark areas float shadowFactor = 1.0 - brightness; float3 tintedLight = lerp(float3(1, 1, 1), ShadowColor.rgb, shadowFactor); // --- Specular (step-based) --- float specMask = smoothstep(SpecularSize - SpecularSmoothness, SpecularSize + SpecularSmoothness, NdotH); // Only show specular on lit side float litSide = step(0.01, NdotL); float3 specContrib = SpecularColor.rgb * SpecularColor.a * specMask * litSide; // --- Rim light (fresnel) --- float3 rimContrib = float3(0, 0, 0); if (RimEnabled > 0.5) { float rim = 1.0 - NdotV; float rimMask = smoothstep(RimWidth - RimSmoothness, RimWidth + RimSmoothness, rim); // Rim visible on lit side only for artistic look float rimLit = smoothstep(-0.1, 0.3, NdotL); rimContrib = RimColor.rgb * RimColor.a * rimMask * rimLit; } // --- Combine --- float4 albedo = albedoTex.Sample(sampLinear, input.TexCoord) * input.Color; float3 ambient = albedo.rgb * AmbientStrength; float3 diffuse = albedo.rgb * brightness * tintedLight; float3 finalColor = ambient + diffuse + specContrib + rimContrib; return float4(finalColor, albedo.a); } )hlsl"
constexpr const char* kOUTLINE_HULL_VS = R"hlsl( cbuffer CbOutline : register(b0) { float4x4 World; float4x4 View; float4x4 Projection; float3 CameraPos; float OutlineWidth; float4 OutlineColor; float ScaleWithDistance; float3 _pad; }; struct VSInput { float3 Position : POSITION; float3 Normal : NORMAL; float2 TexCoord : TEXCOORD0; float4 Color : COLOR0; }; struct VSOutput { float4 Position : SV_POSITION; }; VSOutput VSMain(VSInput input) { VSOutput output; float3 worldPos = mul(float4(input.Position, 1.0), World).xyz; float3 worldNormal = normalize(mul(input.Normal, (float3x3)World)); // Distance-based width scaling float dist = length(CameraPos - worldPos); float scale = (ScaleWithDistance > 0.5) ? saturate(dist * 0.1) : 1.0; // Expand along normal in world space float3 expanded = worldPos + worldNormal * OutlineWidth * scale; float4 viewPos = mul(float4(expanded, 1.0), View); output.Position = mul(viewPos, Projection); return output; } )hlsl"
constexpr const char* kOUTLINE_PS = R"hlsl( cbuffer CbOutline : register(b0) { float4x4 World; float4x4 View; float4x4 Projection; float3 CameraPos; float OutlineWidth; float4 OutlineColor; float ScaleWithDistance; float3 _pad; }; struct PSInput { float4 Position : SV_POSITION; }; float4 PSMain(PSInput input) : SV_TARGET { return OutlineColor; } )hlsl"
constexpr const char* kOUTLINE_SCREEN_PS = R"hlsl( Texture2D sceneTexture : register(t0); Texture2D depthTexture : register(t1); Texture2D normalTexture : register(t2); SamplerState sampPoint : register(s0); cbuffer CbScreenOutline : register(b0) { float2 TexelSize; // 1.0/screenW, 1.0/screenH float DepthThreshold; float NormalThreshold; float4 OutlineColor; float LineWidth; int Mode; // 0=depth, 1=normal, 2=both float2 _pad; }; struct PSInput { float4 Position : SV_POSITION; float2 TexCoord : TEXCOORD0; }; // Roberts Cross edge detection (sharper than Sobel for thin lines) float robertsCrossDepth(float2 uv) { float2 offset = TexelSize * LineWidth; float d00 = depthTexture.Sample(sampPoint, uv).r; float d11 = depthTexture.Sample(sampPoint, uv + offset).r; float d10 = depthTexture.Sample(sampPoint, uv + float2(offset.x, 0)).r; float d01 = depthTexture.Sample(sampPoint, uv + float2(0, offset.y)).r; float g1 = d00 - d11; float g2 = d10 - d01; return sqrt(g1 * g1 + g2 * g2); } float robertsCrossNormal(float2 uv) { float2 offset = TexelSize * LineWidth; float3 n00 = normalTexture.Sample(sampPoint, uv).rgb; float3 n11 = normalTexture.Sample(sampPoint, uv + offset).rgb; float3 n10 = normalTexture.Sample(sampPoint, uv + float2(offset.x, 0)).rgb; float3 n01 = normalTexture.Sample(sampPoint, uv + float2(0, offset.y)).rgb; float3 g1 = n00 - n11; float3 g2 = n10 - n01; return sqrt(dot(g1, g1) + dot(g2, g2)); } float4 PSMain(PSInput input) : SV_TARGET { float4 scene = sceneTexture.Sample(sampPoint, input.TexCoord); float edge = 0.0; if (Mode == 0 || Mode == 2) // depth { float depthEdge = robertsCrossDepth(input.TexCoord); edge = max(edge, step(DepthThreshold, depthEdge)); } if (Mode == 1 || Mode == 2) // normal { float normalEdge = robertsCrossNormal(input.TexCoord); edge = max(edge, step(NormalThreshold, normalEdge)); } float3 result = lerp(scene.rgb, OutlineColor.rgb, edge * OutlineColor.a); return float4(result, scene.a); } )hlsl"
constexpr const char* kFULLSCREEN_VS = R"hlsl( struct VSOutput { float4 Position : SV_POSITION; float2 TexCoord : TEXCOORD0; }; VSOutput VSMain(uint vertexId : SV_VertexID) { VSOutput output; output.TexCoord = float2((vertexId << 1) & 2, vertexId & 2); output.Position = float4( output.TexCoord.x * 2.0 - 1.0, -(output.TexCoord.y * 2.0 - 1.0), 0.0, 1.0); return output; } )hlsl"
struct alignas(16) CbToon
struct alignas(16) CbOutline
struct alignas(16) CbScreenOutline
struct ToonLightingConfig 7
int bandCount = 3
float specularSize = 0.9f
float specularSmoothness = 0.05f
bool rimEnabled = true
float rimWidth = 0.3f
float rimSmoothness = 0.1f
float ambientStrength = 0.1f
struct ToonOutlineConfig 6
enum `Method : uint8_t` { InvertedHull, ScreenSpaceDepth, ScreenSpaceNormal, ScreenSpaceDepthNormal, None }
Method method = Method::InvertedHull
float width = 0.02f
float depthThreshold = 0.1f
float normalThreshold = 0.4f
bool scaleWithDistance = true
struct ToonConfig 2
ToonLightingConfig lighting
ToonOutlineConfig outline
class ToonPipeline 27
template <typename T> using ComPtr = Microsoft::WRL::ComPtr<T>
ToonPipeline() noexcept = default
bool init(ID3D11Device* device)
void shutdown()
void setConfig(const ToonConfig& cfg)
[[nodiscard]] const ToonConfig& config() const noexcept
[[nodiscard]] bool isInitialized() const noexcept
void beginToonPass(ID3D11DeviceContext* ctx)
void drawMesh(ID3D11DeviceContext* ctx, ID3D11Buffer* vb, ID3D11Buffer* ib, int indexCount, const float* worldMatrix, const float* viewMatrix, const float* projMatrix, const float* lightDir, const float* cameraPos)
void endToonPass(ID3D11DeviceContext* ctx)
void beginOutlinePass(ID3D11DeviceContext* ctx)
void drawOutline(ID3D11DeviceContext* ctx, ID3D11Buffer* vb, ID3D11Buffer* ib, int indexCount, const float* worldMatrix, const float* viewMatrix, const float* projMatrix, const float* cameraPos)
void endOutlinePass(ID3D11DeviceContext* ctx)
void applyScreenSpaceOutline(ID3D11DeviceContext* ctx, ID3D11ShaderResourceView* sceneSRV, ID3D11ShaderResourceView* depthSRV, ID3D11ShaderResourceView* normalSRV, ID3D11RenderTargetView* outputRTV, int screenW, int screenH)
bool initDemo(ID3D11Device* device)
void renderDemo(ID3D11DeviceContext* ctx, ID3D11RenderTargetView* rtv, ID3D11DepthStencilView* dsv, int screenW, int screenH, float timeSeconds)
constexpr const char* TOON_VS_3D = R"hlsl( cbuffer CbTransform : register(b0) { float4x4 World; float4x4 View; float4x4 Projection; }; struct VSInput { float3 Position : POSITION; float3 Normal : NORMAL; float2 TexCoord : TEXCOORD0; float4 Color : COLOR0; }; struct VSOutput { float4 Position : SV_POSITION; float3 WorldPos : TEXCOORD0; float3 WorldNorm : TEXCOORD1; float2 TexCoord : TEXCOORD2; float4 Color : COLOR0; }; VSOutput VSMain(VSInput input) { VSOutput output; float4 worldPos = mul(World, float4(input.Position, 1.0)); output.WorldPos = worldPos.xyz; output.WorldNorm = normalize(mul((float3x3)World, input.Normal)); float4 viewPos = mul(View, worldPos); output.Position = mul(Projection, viewPos); output.TexCoord = input.TexCoord; output.Color = input.Color; return output; } )hlsl"
constexpr const char* TOON_PS_3D = R"hlsl( cbuffer CbLighting : register(b1) { float3 LightDir; float _pad0; float3 LightColor; float _pad1; float3 AmbientColor; float _pad2; float3 CameraPos; float _pad3; float4 MaterialDiffuse; float4 MaterialSpecular; float MaterialShininess; float3 _pad4; }; struct PSInput { float4 Position : SV_POSITION; float3 WorldPos : TEXCOORD0; float3 WorldNorm : TEXCOORD1; float2 TexCoord : TEXCOORD2; float4 Color : COLOR0; }; struct PSOutput { float4 Color : SV_TARGET0; float4 Normal : SV_TARGET1; }; PSOutput PSMain(PSInput input) { PSOutput output; float3 N = normalize(input.WorldNorm); float3 L = normalize(-LightDir); float3 V = normalize(CameraPos - input.WorldPos); // アンビエント float3 ambient = AmbientColor * MaterialDiffuse.rgb; // ディフューズ — NdotLを量子化 float rawNdotL = max(dot(N, L), 0.0); float toon = (rawNdotL > 0.5) ? 1.0 : (rawNdotL > 0.15) ? 0.6 : 0.3; float3 diffuse = LightColor * MaterialDiffuse.rgb * toon; // スペキュラー float3 H = normalize(L + V); float NdotH = max(dot(N, H), 0.0); float specFactor = pow(NdotH, MaterialShininess) * 0.3; float3 specular = LightColor * MaterialSpecular.rgb * specFactor; float3 finalColor = ambient + diffuse + specular; float alpha = MaterialDiffuse.a * input.Color.a; output.Color = float4(finalColor * input.Color.rgb, alpha); // 法線をRT1に出力([0,1]にパック + NdotVをアルファに) float NdotV = max(dot(N, V), 0.0); output.Normal = float4(N * 0.5 + 0.5, NdotV); return output; } )hlsl"
constexpr const char* OUTLINE_VS_3D = R"hlsl( cbuffer CbTransform : register(b0) { float4x4 World; float4x4 View; float4x4 Projection; }; struct VSInput { float3 Position : POSITION; float3 Normal : NORMAL; float2 TexCoord : TEXCOORD0; float4 Color : COLOR0; }; struct VSOutput { float4 Position : SV_POSITION; float4 Color : COLOR0; }; VSOutput VSMain(VSInput input) { VSOutput output; float3 expandedPos = input.Position + input.Normal * 0.012; float4 worldPos = mul(World, float4(expandedPos, 1.0)); float4 viewPos = mul(View, worldPos); output.Position = mul(Projection, viewPos); // アウトラインをメインパスの奥に押し出す(深度バッファで隠れる) output.Position.z += 0.002 * output.Position.w; output.Color = float4(0.1, 0.08, 0.06, 1.0); return output; } )hlsl"
constexpr const char* OUTLINE_PS_3D = R"hlsl( struct PSInput { float4 Position : SV_POSITION; float4 Color : COLOR0; }; float4 PSMain(PSInput input) : SV_TARGET { return input.Color; } )hlsl"
constexpr const char* OUTLINE_POST_VS = R"hlsl( struct VSOutput { float4 Position : SV_POSITION; float2 TexCoord : TEXCOORD0; }; VSOutput VSMain(uint vertexID : SV_VertexID) { VSOutput output; // フルスクリーン三角形(3頂点、頂点バッファ不要) output.TexCoord = float2((vertexID << 1) & 2, vertexID & 2); output.Position = float4(output.TexCoord * float2(2, -2) + float2(-1, 1), 0, 1); return output; } )hlsl"
constexpr const char* OUTLINE_POST_PS = R"hlsl( // MSAA 4x (ENG-105 v2) — sample 0 のみ参照 Texture2DMS<float, 4> DepthTexture : register(t0); Texture2DMS<float4, 4> NormalTexture : register(t1); cbuffer CbOutline : register(b0) { float2 TexelSize; // 1.0 / viewport size float OutlineWidth; // アウトライン太さ(ピクセル) float Threshold; // エッジ検出閾値 }; struct PSInput { float4 Position : SV_POSITION; float2 TexCoord : TEXCOORD0; }; float sampleDepth(int2 pos) { return DepthTexture.Load(pos, 0); } float linearizeDepth(float d, float near, float far) { return near * far / (far - d * (far - near)); } float4 PSMain(PSInput input) : SV_TARGET { int2 pos = int2(input.Position.xy); int w = max(int(OutlineWidth), 1); float nearZ = 0.1; float farZ = 100.0; // 中心基準の深度差分(二重線防止)+ NdotVフィルタ float dC = linearizeDepth(sampleDepth(pos), nearZ, farZ); float dL = linearizeDepth(sampleDepth(pos + int2(-w, 0)), nearZ, farZ); float dR = linearizeDepth(sampleDepth(pos + int2( w, 0)), nearZ, farZ); float dU = linearizeDepth(sampleDepth(pos + int2( 0,-w)), nearZ, farZ); float dD = linearizeDepth(sampleDepth(pos + int2( 0, w)), nearZ, farZ); float edge = max(max(abs(dC - dL), abs(dC - dR)), max(abs(dC - dU), abs(dC - dD))); float4 normalData = NormalTexture.Load(pos, 0); float NdotV = normalData.a; if (edge > Threshold && NdotV > 0.15) { return float4(0.1, 0.08, 0.06, 1.0); } discard; return float4(0, 0, 0, 0); } )hlsl"
constexpr const char* OUTLINE_POST_PS_LAPLACIAN = R"hlsl( // MSAA 4x (ENG-105 v2) — sample 0 のみ参照 Texture2DMS<float, 4> DepthTexture : register(t0); Texture2DMS<float4, 4> NormalTexture : register(t1); cbuffer CbOutline : register(b0) { float2 TexelSize; float OutlineWidth; float Threshold; }; struct PSInput { float4 Position : SV_POSITION; float2 TexCoord : TEXCOORD0; }; float3 unpackNormal(float4 data) { return data.rgb * 2.0 - 1.0; } float4 PSMain(PSInput input) : SV_TARGET { int2 pos = int2(input.Position.xy); int w = max(int(OutlineWidth), 1); // 中心と4近傍の法線を取得 float3 nC = unpackNormal(NormalTexture.Load(pos, 0)); float3 nL = unpackNormal(NormalTexture.Load(pos + int2(-w, 0), 0)); float3 nR = unpackNormal(NormalTexture.Load(pos + int2( w, 0), 0)); float3 nU = unpackNormal(NormalTexture.Load(pos + int2( 0,-w), 0)); float3 nD = unpackNormal(NormalTexture.Load(pos + int2( 0, w), 0)); // 法線の差異: 1 - dot(n1, n2) で角度差を測定 float edge = max(max(1.0 - dot(nC, nL), 1.0 - dot(nC, nR)), max(1.0 - dot(nC, nU), 1.0 - dot(nC, nD))); float NdotV = NormalTexture.Load(pos, 0).a; if (edge > Threshold && NdotV > 0.15) { return float4(0.1, 0.08, 0.06, 1.0); } discard; return float4(0, 0, 0, 0); } )hlsl"
constexpr const char* OUTLINE_POST_PS_DEPTH_NDOTV = R"hlsl( // MSAA 4x (ENG-105 v2) — sample 0 のみ参照 Texture2DMS<float, 4> DepthTexture : register(t0); Texture2DMS<float4, 4> NormalTexture : register(t1); cbuffer CbOutline : register(b0) { float2 TexelSize; float OutlineWidth; float Threshold; }; struct PSInput { float4 Position : SV_POSITION; float2 TexCoord : TEXCOORD0; }; float sampleDepth(int2 pos) { return DepthTexture.Load(pos, 0); } float linearizeDepth(float d, float nearZ, float farZ) { return nearZ * farZ / (farZ - d * (farZ - nearZ)); } float4 PSMain(PSInput input) : SV_TARGET { int2 pos = int2(input.Position.xy); int w = max(int(OutlineWidth), 1); float nearZ = 0.1; float farZ = 100.0; // 中心基準の深度差分(二重線防止) float dC = linearizeDepth(sampleDepth(pos), nearZ, farZ); float dL = linearizeDepth(sampleDepth(pos + int2(-w, 0)), nearZ, farZ); float dR = linearizeDepth(sampleDepth(pos + int2( w, 0)), nearZ, farZ); float dU = linearizeDepth(sampleDepth(pos + int2( 0,-w)), nearZ, farZ); float dD = linearizeDepth(sampleDepth(pos + int2( 0, w)), nearZ, farZ); float edge = max(max(abs(dC - dL), abs(dC - dR)), max(abs(dC - dU), abs(dC - dD))); // NdotVフィルタ: 凹面内部(NdotV低)を抑制 float4 normalData = NormalTexture.Load(pos, 0); float NdotV = normalData.a; float ndotVMask = smoothstep(0.1, 0.35, NdotV); if (edge * ndotVMask > Threshold) { return float4(0.1, 0.08, 0.06, 1.0); } discard; return float4(0, 0, 0, 0); } )hlsl"
constexpr const char* OUTLINE_POST_PS_COLOR_EDGE = R"hlsl( // MSAA 4x (ENG-105 v2) — sample 0 のみ参照 Texture2DMS<float, 4> DepthTexture : register(t0); Texture2DMS<float4, 4> NormalTexture : register(t1); cbuffer CbOutline : register(b0) { float2 TexelSize; float OutlineWidth; float Threshold; }; struct PSInput { float4 Position : SV_POSITION; float2 TexCoord : TEXCOORD0; }; float sampleDepth(int2 pos) { return DepthTexture.Load(pos, 0); } float linearizeDepth(float d, float nearZ, float farZ) { return nearZ * farZ / (farZ - d * (farZ - nearZ)); } float3 unpackNormal(float4 data) { return data.rgb * 2.0 - 1.0; } float4 PSMain(PSInput input) : SV_TARGET { int2 pos = int2(input.Position.xy); int w = max(int(OutlineWidth), 1); float nearZ = 0.1; float farZ = 100.0; // 中心基準の深度差分 float dC = linearizeDepth(sampleDepth(pos), nearZ, farZ); float dL = linearizeDepth(sampleDepth(pos + int2(-w, 0)), nearZ, farZ); float dR = linearizeDepth(sampleDepth(pos + int2( w, 0)), nearZ, farZ); float dU = linearizeDepth(sampleDepth(pos + int2( 0,-w)), nearZ, farZ); float dD = linearizeDepth(sampleDepth(pos + int2( 0, w)), nearZ, farZ); float depthEdge = max(max(abs(dC - dL), abs(dC - dR)), max(abs(dC - dU), abs(dC - dD))); // 法線差分 float3 nC = unpackNormal(NormalTexture.Load(pos, 0)); float3 nL = unpackNormal(NormalTexture.Load(pos + int2(-w, 0), 0)); float3 nR = unpackNormal(NormalTexture.Load(pos + int2( w, 0), 0)); float3 nU = unpackNormal(NormalTexture.Load(pos + int2( 0,-w), 0)); float3 nD = unpackNormal(NormalTexture.Load(pos + int2( 0, w), 0)); float normalEdge = max(max(1.0 - dot(nC, nL), 1.0 - dot(nC, nR)), max(1.0 - dot(nC, nU), 1.0 - dot(nC, nD))); float NdotV = NormalTexture.Load(pos, 0).a; // 深度エッジ OR (法線エッジ AND 深度エッジ弱) bool hasEdge = depthEdge > Threshold || (normalEdge > Threshold * 0.8 && depthEdge > Threshold * 0.2); if (hasEdge && NdotV > 0.15) { return float4(0.1, 0.08, 0.06, 1.0); } discard; return float4(0, 0, 0, 0); } )hlsl"
constexpr const char* OUTLINE_POST_PS_DEPTH_COLOR = R"hlsl( // MSAA 4x (ENG-105 v2) — sample 0 のみ参照 Texture2DMS<float, 4> DepthTexture : register(t0); Texture2DMS<float4, 4> NormalTexture : register(t1); Texture2D<float4> ColorTexture : register(t2); cbuffer CbOutline : register(b0) { float2 TexelSize; float OutlineWidth; float Threshold; }; struct PSInput { float4 Position : SV_POSITION; float2 TexCoord : TEXCOORD0; }; float sampleDepth(int2 pos) { return DepthTexture.Load(pos, 0); } float linearizeDepth(float d, float nearZ, float farZ) { return nearZ * farZ / (farZ - d * (farZ - nearZ)); } float luminance(float3 c) { return dot(c, float3(0.299, 0.587, 0.114)); } float4 PSMain(PSInput input) : SV_TARGET { int2 pos = int2(input.Position.xy); float nearZ = 0.1; float farZ = 100.0; int w = max(int(OutlineWidth), 1); // 中心基準の4方向深度差分(中心と比較するので二重線にならない) float dC = linearizeDepth(sampleDepth(pos), nearZ, farZ); float dL = linearizeDepth(sampleDepth(pos + int2(-w, 0)), nearZ, farZ); float dR = linearizeDepth(sampleDepth(pos + int2( w, 0)), nearZ, farZ); float dU = linearizeDepth(sampleDepth(pos + int2( 0,-w)), nearZ, farZ); float dD = linearizeDepth(sampleDepth(pos + int2( 0, w)), nearZ, farZ); float depthEdge = max(max(abs(dC - dL), abs(dC - dR)), max(abs(dC - dU), abs(dC - dD))); // 中心基準の色差分 float lC = luminance(ColorTexture.Load(int3(pos, 0)).rgb); float lL = luminance(ColorTexture.Load(int3(pos + int2(-w, 0), 0)).rgb); float lR = luminance(ColorTexture.Load(int3(pos + int2( w, 0), 0)).rgb); float lU = luminance(ColorTexture.Load(int3(pos + int2( 0,-w), 0)).rgb); float lD = luminance(ColorTexture.Load(int3(pos + int2( 0, w), 0)).rgb); float colorEdge = max(max(abs(lC - lL), abs(lC - lR)), max(abs(lC - lU), abs(lC - lD))); // NdotVフィルタ float4 normalData = NormalTexture.Load(pos, 0); float NdotV = normalData.a; // 深度エッジと色エッジの複合判定 float depthThresh = Threshold; float colorThresh = Threshold * 0.3; bool hasDepthEdge = depthEdge > depthThresh; bool hasColorEdge = colorEdge > colorThresh; if ((hasDepthEdge || (hasColorEdge && depthEdge > depthThresh * 0.3)) && NdotV > 0.15) { return float4(0.1, 0.08, 0.06, 1.0); } discard; return float4(0, 0, 0, 0); } )hlsl"
constexpr const char* TOON_PS_3D_FRESNEL = R"hlsl( cbuffer CbLighting : register(b1) { float3 LightDir; float _pad0; float3 LightColor; float _pad1; float3 AmbientColor; float _pad2; float3 CameraPos; float _pad3; float4 MaterialDiffuse; float4 MaterialSpecular; float MaterialShininess; float3 _pad4; }; struct PSInput { float4 Position : SV_POSITION; float3 WorldPos : TEXCOORD0; float3 WorldNorm : TEXCOORD1; float2 TexCoord : TEXCOORD2; float4 Color : COLOR0; }; struct PSOutput { float4 Color : SV_TARGET0; float4 Normal : SV_TARGET1; }; PSOutput PSMain(PSInput input) { PSOutput output; float3 N = normalize(input.WorldNorm); float3 L = normalize(-LightDir); float3 V = normalize(CameraPos - input.WorldPos); // アンビエント float3 ambient = AmbientColor * MaterialDiffuse.rgb; // ディフューズ — NdotLを量子化 float rawNdotL = max(dot(N, L), 0.0); float toon = (rawNdotL > 0.5) ? 1.0 : (rawNdotL > 0.15) ? 0.6 : 0.3; float3 diffuse = LightColor * MaterialDiffuse.rgb * toon; // スペキュラー float3 H = normalize(L + V); float NdotH = max(dot(N, H), 0.0); float specFactor = pow(NdotH, MaterialShininess) * 0.3; float3 specular = LightColor * MaterialSpecular.rgb * specFactor; // Fresnel: シルエット付近(NdotV小)を暗化してアウトラインに float NdotV = max(dot(N, V), 0.0); float fresnelEdge = 1.0 - smoothstep(0.0, 0.4, NdotV); float3 outlineColor = float3(0.08, 0.06, 0.04); float3 finalColor = ambient + diffuse + specular; finalColor = lerp(finalColor, outlineColor, fresnelEdge * 0.95); float alpha = MaterialDiffuse.a * input.Color.a; output.Color = float4(finalColor * input.Color.rgb, alpha); output.Normal = float4(N * 0.5 + 0.5, NdotV); return output; } )hlsl"
struct Transform2D 24
float a = 1.0f
float b = 0.0f
float c = 0.0f
float d = 1.0f
float tx = 0.0f
float ty = 0.0f
[[nodiscard]] static constexpr Transform2D identity() noexcept
[[nodiscard]] static constexpr Transform2D translate(float tx, float ty) noexcept
[[nodiscard]] static constexpr Transform2D scale(float sx, float sy) noexcept
[[nodiscard]] static Transform2D rotate(float rad) noexcept
[[nodiscard]] static Transform2D rotateAround(float rad, float px, float py) noexcept
[[nodiscard]] constexpr Transform2D operator*(const Transform2D& r) const noexcept
[[nodiscard]] constexpr sgc::Vec2f apply(const sgc::Vec2f& p) const noexcept
[[nodiscard]] constexpr sgc::Vec2f apply(float x, float y) const noexcept
[[nodiscard]] sgc::Rectf applyBounds(const sgc::Rectf& r) const noexcept
[[nodiscard]] float avgScale() const noexcept
[[nodiscard]] float scaleX() const noexcept
[[nodiscard]] float scaleY() const noexcept
[[nodiscard]] float rotation() const noexcept
[[nodiscard]] bool isIdentity() const noexcept
[[nodiscard]] bool isTranslationOnly() const noexcept
[[nodiscard]] bool hasRotation() const noexcept
[[nodiscard]] float translateX() const noexcept
[[nodiscard]] float translateY() const noexcept
struct SortedDrawCommand 2
const Scene3D::RenderObject* object
float distanceToCamera
class TransparencySort 2
static void sortScene(const Scene3D& scene, const Camera3D& camera, std::vector<const Scene3D::RenderObject*>& opaqueOut, std::vector<const Scene3D::RenderObject*>& transparentOut)
class [[deprecated("Use mitiru::vn::TrueTypeFont instead")]] TrueTypeFont
class TrueTypeRenderer 6
bool loadFont(const std::string& fontPath, float pixelHeight = 32.0f)
[[nodiscard]] Texture renderText(const std::string& text, uint8_t r = 255, uint8_t g = 255, uint8_t b = 255, uint8_t a = 255) const
[[nodiscard]] bool isLoaded() const noexcept
[[nodiscard]] float pixelHeight() const noexcept
[[nodiscard]] inline std::string utf8Substr(std::string_view text, std::size_t maxCodepoints)
[[nodiscard]] inline std::size_t utf8Length(std::string_view text)
class TrueTypeScreenRenderer 3
static void drawText(vn::TrueTypeFont& font, Screen& screen, float x, float y, std::string_view text, float fontSize, const sgc::Colorf& color)
static float measureWidth(vn::TrueTypeFont& font, std::string_view text, float fontSize)
static float measureHeight(vn::TrueTypeFont& font, float fontSize)
struct Vertex2D 3
constexpr Vertex2D() noexcept = default
constexpr Vertex2D(const sgc::Vec2f& position, const sgc::Vec2f& texCoord, const sgc::Colorf& color) noexcept
constexpr Vertex2D(const sgc::Vec2f& position, const sgc::Colorf& color) noexcept
struct Vertex3D 3
constexpr Vertex3D() noexcept = default
constexpr Vertex3D(const sgc::Vec3f& position, const sgc::Vec3f& normal, const sgc::Vec2f& texCoord, const sgc::Colorf& color) noexcept
constexpr Vertex3D(const sgc::Vec3f& position, const sgc::Vec3f& normal) noexcept
struct VisualPresets 18
VisualPresets() = delete
[[nodiscard]] static PanelStyle modernPanel() noexcept
[[nodiscard]] static PanelStyle glassmorphism() noexcept
[[nodiscard]] static PanelStyle neonGlow() noexcept
[[nodiscard]] static PanelStyle flatMinimal() noexcept
[[nodiscard]] static PanelStyle gameHud() noexcept
[[nodiscard]] static PanelStyle tooltip() noexcept
[[nodiscard]] static PanelStyle notification(NotificationType type) noexcept
[[nodiscard]] static PanelStyle modalBackdrop() noexcept
`constexpr std::string_view VOLUMETRIC_GODRAYS_PS = R"hlsl(
`constexpr std::string_view VOLUMETRIC_FOG_PS = R"hlsl(
Texture2D depthTexture : register(t1)
SamplerState linearSampler : register(s0)
cbuffer VolumetricParams : register(b0)
Texture2D depthTexture : register(t1)
SamplerState linearSampler : register(s0)
cbuffer FogParams : register(b0)
float linearizeDepth(float d, float near, float far)
struct VolumetricConfig 6
float density = 0.5f
float scattering = 0.3f
int numSteps = 32
float decay = 0.97f
float exposure = 0.25f
float weight = 0.5f
struct FogConfig 4
float density = 0.02f
float startDistance = 10.0f
float heightFalloff = 0.1f
float maxFogFactor = 0.95f
struct PSInput 2
float4 position : SV_POSITION
float2 texCoord : TEXCOORD0
struct PSInput 2
float4 position : SV_POSITION
float2 texCoord : TEXCOORD0
class VolumetricLightPass 8
template <typename T> using ComPtr = Microsoft::WRL::ComPtr<T>
VolumetricLightPass() noexcept = default
void init(ID3D11Device* device, int width, int height)
[[nodiscard]] bool isInitialized() const noexcept
void setConfig(const VolumetricConfig& config) noexcept
[[nodiscard]] const VolumetricConfig& config() const noexcept
void resize(std::uint32_t width, std::uint32_t height) noexcept
void apply(ID3D11DeviceContext* context, ID3D11ShaderResourceView* sceneSRV, ID3D11ShaderResourceView* depthSRV, ID3D11RenderTargetView* outputRTV)
class VolumetricFogPass 8
template <typename T> using ComPtr = Microsoft::WRL::ComPtr<T>
VolumetricFogPass() noexcept = default
void init(ID3D11Device* device, int width, int height)
[[nodiscard]] bool isInitialized() const noexcept
void setConfig(const FogConfig& config) noexcept
[[nodiscard]] const FogConfig& config() const noexcept
void resize(std::uint32_t width, std::uint32_t height) noexcept
void apply(ID3D11DeviceContext* context, ID3D11ShaderResourceView* sceneSRV, ID3D11ShaderResourceView* depthSRV, ID3D11RenderTargetView* outputRTV, const float cameraPos[3], float nearPlane, float farPlane)
enum WorldUIType : uint8_t 3
ProgressBar
Label
Icon
struct WorldUIElement 9
WorldUIType type = WorldUIType::Label
sgc::Vec3f worldPosition
float progress = 0.0f
float barWidth = 60.0f
float barHeight = 8.0f
std::string text
float fontSize = 12.0f
float iconSize = 16.0f
bool visible = true
class WorldUI 35
void add(const WorldUIElement& element)
void clear()
void render(Screen& screen, const Camera3D& camera, float screenWidth, float screenHeight) const
[[nodiscard]] std::size_t elementCount() const noexcept
inline RenderPipeline2D RenderPipeline2D::createFromDx11( gfx::Dx11Device* dx11Device, float screenWidth, float screenHeight)
inline void RenderPipeline2D::submitBatchDx11( const std::vector<Vertex2D>& vertices, const std::vector<std::uint32_t>& indices)
inline Microsoft::WRL::ComPtr<ID3D11InputLayout> RenderPipeline2D::createSdfInputLayout(ID3D11Device* device, const gfx::Dx11Shader& vs)
inline Microsoft::WRL::ComPtr<ID3D11BlendState> RenderPipeline2D::createSdfBlendState(ID3D11Device* device)
inline Microsoft::WRL::ComPtr<ID3D11RasterizerState> RenderPipeline2D::createSdfRasterizerState(ID3D11Device* device)
inline void RenderPipeline2D::submitStyledBatchDx11( const std::vector<StyledVertex2D>& vertices, const std::vector<std::uint32_t>& indices, const StyleConstants& style, std::string_view vsSource, std::string_view psSource, std::unique_ptr<gfx::Dx11Shader>& cachedVS, std::unique_ptr<gfx::Dx11Shader>& cachedPS, Microsoft::WRL::ComPtr<ID3D11InputLayout>& cachedLayout)
inline RenderPipeline2D RenderPipeline2D::createFromDx12( gfx::Dx12Device* dx12Device, float screenWidth, float screenHeight)
inline D3D12_ROOT_SIGNATURE_DESC makeDx12PointRootSigDesc( D3D12_DESCRIPTOR_RANGE& srvRange, D3D12_ROOT_PARAMETER (&params)[3], D3D12_STATIC_SAMPLER_DESC& sampler)
inline Microsoft::WRL::ComPtr<ID3D12RootSignature> createDx12PointRootSig(ID3D12Device* device, const D3D12_ROOT_SIGNATURE_DESC& rsd)
inline void RenderPipeline2D::buildDx12PointFilterResources( ID3D12Device* device, ID3DBlob* vsBlob, ID3DBlob* psBlob, const D3D12_INPUT_ELEMENT_DESC* layout, UINT layoutCount)
inline void RenderPipeline2D::submitBatchDx12( const std::vector<Vertex2D>& vertices, const std::vector<std::uint32_t>& indices)
inline void RenderPipeline2D::submitStyledBatchDx12( const std::vector<StyledVertex2D>& vertices, const std::vector<std::uint32_t>& indices, const StyleConstants& style, std::string_view vsSource, std::string_view psSource, Microsoft::WRL::ComPtr<ID3D12PipelineState>& cachedPso)
inline void RenderPipeline2D::ensureDx12SdfResources( std::string_view vsSource, std::string_view psSource, Microsoft::WRL::ComPtr<ID3DBlob>& cachedVs, Microsoft::WRL::ComPtr<ID3DBlob>& cachedPs, Microsoft::WRL::ComPtr<ID3D12PipelineState>& cachedPso)
inline Microsoft::WRL::ComPtr<ID3D12Resource> RenderPipeline2D::createUploadBufferDx12(ID3D12Device* device, std::uint32_t sizeBytes)
inline void RenderPipeline2D::updateCbDx12(ID3D12Resource* cb, const void* data, size_t bytes)
inline void RenderPipeline2D::updateDx12Buffer( Microsoft::WRL::ComPtr<ID3D12Resource>& buf, std::uint32_t& capacity, const void* data, std::uint32_t bytes)
inline Microsoft::WRL::ComPtr<ID3D12PipelineState> RenderPipeline2D::buildDx12Pso(ID3D12Device* device, ID3D12RootSignature* rootSig, ID3DBlob* vs, ID3DBlob* ps, const D3D12_INPUT_ELEMENT_DESC* layout, UINT layoutCount)
inline void RenderPipeline2D::waitDx12Fence()
inline void RenderPipeline2D::submitPixelGrid( const sgc::Rectf& dest, const std::uint32_t* pixels, int pw, int ph, float screenW, float screenH, PixelArtFilter filter)
inline void RenderPipeline2D::submitPixelGridDx12( const sgc::Rectf& dest, const std::uint32_t* pixels, int pw, int ph, PixelArtFilter filter)
inline constexpr const char* DX12_FXAA_PS_3D = R"hlsl( Texture2D sceneTexture : register(t0); SamplerState linearSampler : register(s0); cbuffer FXAAParams : register(b0) { float2 rcpFrame; // 1.0 / screenSize float subpixQuality; // サブピクセル品質 (0.0-1.0) float edgeThreshold; // エッジ検出閾値 float edgeThresholdMin; // 最小エッジ閾値 float3 fxaaPadding; }; struct PSInput { float4 Position : SV_POSITION; float2 TexCoord : TEXCOORD0; }; float FxaaLuma(float3 rgb) { return dot(rgb, float3(0.299, 0.587, 0.114)); } float3 FxaaTexOff(float2 uv, float2 offset) { return sceneTexture.Sample(linearSampler, uv + offset * rcpFrame).rgb; } float4 PSMain(PSInput input) : SV_TARGET { float2 uv = input.TexCoord; // ── ステップ 1: 中心 + 4 近傍の輝度 ───────────────────── float3 rgbM = sceneTexture.Sample(linearSampler, uv).rgb; float lumaM = FxaaLuma(rgbM); float lumaN = FxaaLuma(FxaaTexOff(uv, float2( 0, -1))); float lumaS = FxaaLuma(FxaaTexOff(uv, float2( 0, 1))); float lumaE = FxaaLuma(FxaaTexOff(uv, float2( 1, 0))); float lumaW = FxaaLuma(FxaaTexOff(uv, float2(-1, 0))); // ── ステップ 2: 局所コントラストで reject ─────────────── float lumaMin = min(lumaM, min(min(lumaN, lumaS), min(lumaE, lumaW))); float lumaMax = max(lumaM, max(max(lumaN, lumaS), max(lumaE, lumaW))); float lumaRange = lumaMax - lumaMin; if (lumaRange < max(edgeThresholdMin, lumaMax * edgeThreshold)) { return float4(rgbM, 1.0); } // ── ステップ 3: 対角輝度を取り、水平/垂直エッジを判定 ──── float lumaNW = FxaaLuma(FxaaTexOff(uv, float2(-1, -1))); float lumaNE = FxaaLuma(FxaaTexOff(uv, float2( 1, -1))); float lumaSW = FxaaLuma(FxaaTexOff(uv, float2(-1, 1))); float lumaSE = FxaaLuma(FxaaTexOff(uv, float2( 1, 1))); float lumaNS = lumaN + lumaS; float lumaEW = lumaE + lumaW; float lumaNWSW = lumaNW + lumaSW; float lumaNESE = lumaNE + lumaSE; float lumaNWNE = lumaNW + lumaNE; float lumaSWSE = lumaSW + lumaSE; float edgeHorz = abs(lumaNWSW - 2.0 * lumaW) + abs(lumaNS - 2.0 * lumaM) * 2.0 + abs(lumaNESE - 2.0 * lumaE); float edgeVert = abs(lumaNWNE - 2.0 * lumaN) + abs(lumaEW - 2.0 * lumaM) * 2.0 + abs(lumaSWSE - 2.0 * lumaS); bool isHorizontal = (edgeHorz >= edgeVert); // ── ステップ 4: ステップ方向 ───────────────────────────── float stepLength = isHorizontal ? rcpFrame.y : rcpFrame.x; float luma1 = isHorizontal ? lumaN : lumaW; float luma2 = isHorizontal ? lumaS : lumaE; float gradient1 = luma1 - lumaM; float gradient2 = luma2 - lumaM; bool is1Steepest = abs(gradient1) >= abs(gradient2); float gradientScaled = 0.25 * max(abs(gradient1), abs(gradient2)); if (!is1Steepest) stepLength = -stepLength; float lumaLocalAvg = is1Steepest ? 0.5 * (luma1 + lumaM) : 0.5 * (luma2 + lumaM); float2 currentUV = uv; if (isHorizontal) currentUV.y += stepLength * 0.5; else currentUV.x += stepLength * 0.5; // ── ステップ 5: エッジ端点探索 (最大 12 ステップ) ──────── float2 offset2 = isHorizontal ? float2(rcpFrame.x, 0.0) : float2(0.0, rcpFrame.y); float2 uv1 = currentUV - offset2; float2 uv2 = currentUV + offset2; float lumaEnd1 = FxaaLuma(sceneTexture.Sample(linearSampler, uv1).rgb) - lumaLocalAvg; float lumaEnd2 = FxaaLuma(sceneTexture.Sample(linearSampler, uv2).rgb) - lumaLocalAvg; bool reached1 = abs(lumaEnd1) >= gradientScaled; bool reached2 = abs(lumaEnd2) >= gradientScaled; bool reachedBoth = reached1 && reached2; if (!reached1) uv1 -= offset2; if (!reached2) uv2 += offset2; static const float QUALITY[12] = { 1.0, 1.0, 1.0, 1.0, 1.0, 1.5, 2.0, 2.0, 2.0, 2.0, 4.0, 8.0 }; [unroll] for (int i = 0; i < 12 && !reachedBoth; i++) { if (!reached1) { lumaEnd1 = FxaaLuma( sceneTexture.Sample(linearSampler, uv1).rgb) - lumaLocalAvg; } if (!reached2) { lumaEnd2 = FxaaLuma( sceneTexture.Sample(linearSampler, uv2).rgb) - lumaLocalAvg; } reached1 = abs(lumaEnd1) >= gradientScaled; reached2 = abs(lumaEnd2) >= gradientScaled; reachedBoth = reached1 && reached2; if (!reached1) uv1 -= offset2 * QUALITY[i]; if (!reached2) uv2 += offset2 * QUALITY[i]; } // ── ステップ 6: ブレンド係数 ────────────────────────────── float dist1 = isHorizontal ? (uv.x - uv1.x) : (uv.y - uv1.y); float dist2 = isHorizontal ? (uv2.x - uv.x) : (uv2.y - uv.y); bool isDir1 = dist1 < dist2; float distFinal = min(dist1, dist2); float edgeLength = dist1 + dist2; float pixelOffset = -distFinal / max(edgeLength, 1e-5) + 0.5; bool isLumaCenterSmaller = lumaM < lumaLocalAvg; bool correctVariation = ((isDir1 ? lumaEnd1 : lumaEnd2) < 0.0) != isLumaCenterSmaller; float finalOffset = correctVariation ? pixelOffset : 0.0; // サブピクセル AA をブレンド float lumaAvg = (1.0 / 12.0) * (2.0 * lumaNS + 2.0 * lumaEW + lumaNWSW + lumaNESE); float subpixOffset1 = saturate( abs(lumaAvg - lumaM) / max(lumaRange, 1e-5)); float subpixOffset2 = (-2.0 * subpixOffset1 + 3.0) * subpixOffset1 * subpixOffset1; float subpixOffsetFinal = subpixOffset2 * subpixOffset2 * subpixQuality; finalOffset = max(finalOffset, subpixOffsetFinal); // 最終サンプリング float2 finalUV = uv; if (isHorizontal) finalUV.y += finalOffset * stepLength; else finalUV.x += finalOffset * stepLength; float3 finalColor = sceneTexture.Sample(linearSampler, finalUV).rgb; return float4(finalColor, 1.0); } )hlsl"
inline constexpr const char* DX12_MULTI_LIGHT_PS_3D = R"HLSL( cbuffer CbLighting : register(b1) { float3 _unusedLightDir; float _pad0; float3 _unusedLightColor; float _pad1; float3 _unusedAmbient_b1; float _pad2; float3 CameraPos; float _pad3; float4 MaterialDiffuse; float4 MaterialSpecular; float MaterialShininess; float3 _pad4; }; struct LightEntry { float4 typeAndIntensity; float4 position; float4 direction; float4 color; }; cbuffer CbLightArray : register(b2) { int lightCount; int3 _pad_la; float4 SceneAmbient; LightEntry Lights[8]; }; Texture2D g_albedo : register(t0); SamplerState g_samp : register(s0); struct PSInput { float4 Position : SV_POSITION; float3 WorldPos : TEXCOORD0; float3 WorldNorm : TEXCOORD1; float2 TexCoord : TEXCOORD2; float4 LightSpacePos : TEXCOORD3; float4 Color : COLOR0; }; struct PSOutput { float4 Color : SV_TARGET0; float4 Normal : SV_TARGET1; }; float3 evaluateLight(LightEntry L, float3 worldPos, float3 N, float3 V, float3 albedo, float3 specularCol, float shininess) { int type = (int)L.typeAndIntensity.x; float intensity = L.typeAndIntensity.y; float3 Lcol = L.color.rgb * intensity; float range = L.color.a; float3 Ldir; float attenuation = 1.0; if (type == 0) { Ldir = normalize(-L.direction.xyz); } else { float3 toLight = L.position.xyz - worldPos; float dist = length(toLight); Ldir = toLight / max(dist, 1e-4); attenuation = saturate(1.0 - dist / max(range, 1e-4)); attenuation *= attenuation; if (type == 2) { float3 spotDir = normalize(L.direction.xyz); float cosTheta = dot(-Ldir, spotDir); float inner = L.typeAndIntensity.z; float outer = L.typeAndIntensity.w; float spotFactor = saturate( (cosTheta - outer) / max(inner - outer, 1e-4)); attenuation *= spotFactor; } } float NdotL = saturate(dot(N, Ldir)); float3 H = normalize(Ldir + V); float specPow = max(shininess, 1.0); float NdotH = saturate(dot(N, H)); float spec = pow(NdotH, specPow) * NdotL; float3 diffuse = albedo * NdotL; float3 specular = specularCol * spec; return (diffuse + specular) * Lcol * attenuation; } PSOutput PSMain(PSInput input) { float3 N = normalize(input.WorldNorm); float3 V = normalize(CameraPos - input.WorldPos); float4 texSample = g_albedo.Sample(g_samp, input.TexCoord); float3 albedo = MaterialDiffuse.rgb * input.Color.rgb * texSample.rgb; float3 result = SceneAmbient.rgb * albedo; [unroll] for (int n = 0; n < 8; ++n) { if (n >= lightCount) break; result += evaluateLight(Lights[n], input.WorldPos, N, V, albedo, MaterialSpecular.rgb, MaterialShininess); } float alpha = MaterialDiffuse.a * input.Color.a * texSample.a; PSOutput o; o.Color = float4(result, alpha); float NdotV = max(dot(N, V), 0.0); o.Normal = float4(N * 0.5 + 0.5, NdotV); return o; } )HLSL"
inline constexpr const char* DX12_TOON_PS_3D = R"hlsl( cbuffer CbLighting : register(b1) { float3 LightDir; float _pad0; float3 LightColor; float _pad1; float3 AmbientColor; float _pad2; float3 CameraPos; float _pad3; float4 MaterialDiffuse; float4 MaterialSpecular; float MaterialShininess; float3 _pad4; }; Texture2D g_albedo : register(t0); SamplerState g_samp : register(s0); // LightSpacePos は VS が出力するため PSInput でも宣言してレジスタ整合を取る。 struct PSInput { float4 Position : SV_POSITION; float3 WorldPos : TEXCOORD0; float3 WorldNorm : TEXCOORD1; float2 TexCoord : TEXCOORD2; float4 LightSpacePos : TEXCOORD3; float4 Color : COLOR0; }; struct PSOutput { float4 Color : SV_TARGET0; float4 Normal : SV_TARGET1; }; PSOutput PSMain(PSInput input) { float3 N = normalize(input.WorldNorm); float3 L = normalize(-LightDir); float3 V = normalize(CameraPos - input.WorldPos); float4 texSample = g_albedo.Sample(g_samp, input.TexCoord); float3 albedo = MaterialDiffuse.rgb * input.Color.rgb * texSample.rgb; // アンビエント float3 ambient = AmbientColor * albedo; // ディフューズ — NdotL を 3 段階に量子化(toon 帯) float rawNdotL = saturate(dot(N, L)); float toon = (rawNdotL > 0.5) ? 1.0 : (rawNdotL > 0.15) ? 0.6 : 0.3; float3 diffuse = LightColor * albedo * toon; // ハイライト float3 H = normalize(L + V); float NdotH = saturate(dot(N, H)); float specFactor = pow(NdotH, max(MaterialShininess, 1.0)) * 0.3; float3 specular = LightColor * MaterialSpecular.rgb * specFactor; float alpha = MaterialDiffuse.a * input.Color.a * texSample.a; PSOutput o; o.Color = float4(ambient + diffuse + specular, alpha); float NdotV = saturate(dot(N, V)); o.Normal = float4(N * 0.5 + 0.5, NdotV); return o; } )hlsl"
inline constexpr const char* DX12_PHONG_PS_3D = R"hlsl( cbuffer CbLighting : register(b1) { float3 LightDir; float _pad0; float3 LightColor; float _pad1; float3 AmbientColor; float _pad2; float3 CameraPos; float _pad3; float4 MaterialDiffuse; float4 MaterialSpecular; float MaterialShininess; float3 _pad4; }; Texture2D g_albedo : register(t0); Texture2D g_shadow : register(t1); SamplerState g_samp : register(s0); SamplerComparisonState g_pcf : register(s1); struct PSInput { float4 Position : SV_POSITION; float3 WorldPos : TEXCOORD0; float3 WorldNorm : TEXCOORD1; float2 TexCoord : TEXCOORD2; float4 LightSpacePos : TEXCOORD3; float4 Color : COLOR0; }; struct PSOutput { float4 Color : SV_TARGET0; float4 Normal : SV_TARGET1; }; // 3x3 PCF (depth bias 込み) float samplePCF(float3 ndc) { // ndc: [-1,1] xy → UV [0,1], z → DX [0,1] そのまま float2 uv = float2(ndc.x * 0.5 + 0.5, -ndc.y * 0.5 + 0.5); float depthRef = ndc.z - 0.001; // shadow acne 抑制 if (any(uv < 0) || any(uv > 1)) return 1.0; // light frustum 外は影なし float shadow = 0.0; const float texelSize = 1.0 / 1024.0; // map size に整合させること [unroll] for (int y = -1; y <= 1; ++y) { [unroll] for (int x = -1; x <= 1; ++x) { float2 offset = float2(x, y) * texelSize; shadow += g_shadow.SampleCmpLevelZero(g_pcf, uv + offset, depthRef); } } return shadow / 9.0; } PSOutput PSMain(PSInput input) { float3 N = normalize(input.WorldNorm); float3 L = normalize(-LightDir); float3 V = normalize(CameraPos - input.WorldPos); float4 texSample = g_albedo.Sample(g_samp, input.TexCoord); float3 albedo = MaterialDiffuse.rgb * input.Color.rgb * texSample.rgb; // shadow factor (1.0 = unshadowed) float3 lsNdc = input.LightSpacePos.xyz / max(input.LightSpacePos.w, 1e-4); float shadow = samplePCF(lsNdc); float3 ambient = AmbientColor * albedo; float NdotL = saturate(dot(N, L)); float3 diffuse = LightColor * albedo * NdotL * shadow; float3 H = normalize(L + V); float NdotH = saturate(dot(N, H)); float specPow = max(MaterialShininess, 1.0); float specFactor = pow(NdotH, specPow) * NdotL * shadow; float3 specular = LightColor * MaterialSpecular.rgb * specFactor; float alpha = MaterialDiffuse.a * input.Color.a * texSample.a; PSOutput o; o.Color = float4(ambient + diffuse + specular, alpha); float NdotV = saturate(dot(N, V)); o.Normal = float4(N * 0.5 + 0.5, NdotV); return o; } )hlsl"
inline constexpr const char* DX12_UNLIT_PS_3D = R"hlsl( cbuffer CbLighting : register(b1) { float3 _unusedLightDir; float _pad0; float3 _unusedLightColor; float _pad1; float3 _unusedAmbient; float _pad2; float3 _unusedCameraPos; float _pad3; float4 MaterialDiffuse; float4 _unusedSpecular; float _unusedShininess; float3 _pad4; }; Texture2D g_albedo : register(t0); SamplerState g_samp : register(s0); struct PSInput { float4 Position : SV_POSITION; float3 WorldPos : TEXCOORD0; float3 WorldNorm : TEXCOORD1; float2 TexCoord : TEXCOORD2; float4 LightSpacePos : TEXCOORD3; float4 Color : COLOR0; }; struct PSOutput { float4 Color : SV_TARGET0; float4 Normal : SV_TARGET1; }; PSOutput PSMain(PSInput input) { float3 N = normalize(input.WorldNorm); float4 texSample = g_albedo.Sample(g_samp, input.TexCoord); float3 albedo = MaterialDiffuse.rgb * input.Color.rgb * texSample.rgb; float alpha = MaterialDiffuse.a * input.Color.a * texSample.a; PSOutput o; o.Color = float4(albedo, alpha); o.Normal = float4(N * 0.5 + 0.5, 1.0); return o; } )hlsl"
inline constexpr const char* DX12_FLAT_PS_3D = R"hlsl( cbuffer CbLighting : register(b1) { float3 LightDir; float _pad0; float3 LightColor; float _pad1; float3 AmbientColor; float _pad2; float3 CameraPos; float _pad3; float4 MaterialDiffuse; float4 MaterialSpecular; float MaterialShininess; float3 _pad4; }; Texture2D g_albedo : register(t0); SamplerState g_samp : register(s0); struct PSInput { float4 Position : SV_POSITION; float3 WorldPos : TEXCOORD0; nointerpolation float3 WorldNorm : TEXCOORD1; float2 TexCoord : TEXCOORD2; float4 LightSpacePos : TEXCOORD3; float4 Color : COLOR0; }; struct PSOutput { float4 Color : SV_TARGET0; float4 Normal : SV_TARGET1; }; PSOutput PSMain(PSInput input) { float3 N = normalize(input.WorldNorm); float3 L = normalize(-LightDir); float4 texSample = g_albedo.Sample(g_samp, input.TexCoord); float3 albedo = MaterialDiffuse.rgb * input.Color.rgb * texSample.rgb; float3 ambient = AmbientColor * albedo; float NdotL = saturate(dot(N, L)); float3 diffuse = LightColor * albedo * NdotL; float alpha = MaterialDiffuse.a * input.Color.a * texSample.a; PSOutput o; o.Color = float4(ambient + diffuse, alpha); o.Normal = float4(N * 0.5 + 0.5, NdotL); return o; } )hlsl"
inline constexpr const char* DX12_DEFAULT_VS_3D = R"hlsl( cbuffer CbTransform : register(b0) { float4x4 World; float4x4 View; float4x4 Projection; }; cbuffer CbShadow : register(b3) { float4x4 LightViewProj; }; struct VSInput { float3 Position : POSITION; float3 Normal : NORMAL; float2 TexCoord : TEXCOORD0; float4 Color : COLOR0; }; struct VSOutput { float4 Position : SV_POSITION; float3 WorldPos : TEXCOORD0; float3 WorldNorm : TEXCOORD1; float2 TexCoord : TEXCOORD2; float4 LightSpacePos : TEXCOORD3; float4 Color : COLOR0; }; VSOutput VSMain(VSInput input) { VSOutput output; float4 worldPos = mul(World, float4(input.Position, 1.0)); output.WorldPos = worldPos.xyz; output.WorldNorm = normalize(mul((float3x3)World, input.Normal)); float4 viewPos = mul(View, worldPos); output.Position = mul(Projection, viewPos); // ライト空間位置 — シャドウサンプル PS で参照 output.LightSpacePos = mul(LightViewProj, worldPos); output.TexCoord = input.TexCoord; output.Color = input.Color; return output; } )hlsl"
constexpr const char* OVERLAY2D_VS = R"hlsl( cbuffer CbOverlay2D : register(b0) { float4x4 OrthoProjection; }; struct VS_IN { float2 pos : POSITION; float2 uv : TEXCOORD; float4 color : COLOR; }; struct VS_OUT { float4 pos : SV_POSITION; float2 uv : TEXCOORD; float4 color : COLOR; }; VS_OUT VSMain(VS_IN i) { VS_OUT o; o.pos = mul(OrthoProjection, float4(i.pos, 0.0, 1.0)); o.uv = i.uv; o.color = i.color; return o; } )hlsl"
constexpr const char* OVERLAY2D_PS = R"hlsl( struct VS_OUT { float4 pos : SV_POSITION; float2 uv : TEXCOORD; float4 color : COLOR; }; float4 PSMain(VS_OUT i) : SV_TARGET { return i.color; } )hlsl"
struct alignas(256) DX12CbTransform
struct alignas(256) DX12CbLighting
struct Overlay2DVertex 3
float x, y
float u, v
float r, g, b, a
struct OutlineDrawCommand 40
const Mesh* mesh = nullptr
constexpr const char* DX12_TONEMAP_VS = R"HLSL( struct VSOutput { float4 Position : SV_POSITION; float2 TexCoord : TEXCOORD0; }; VSOutput VSMain(uint vertexID : SV_VertexID) { VSOutput output; output.TexCoord = float2((vertexID << 1) & 2, vertexID & 2); output.Position = float4(output.TexCoord * float2(2, -2) + float2(-1, 1), 0, 1); return output; } )HLSL"
constexpr const char* DX12_TONEMAP_PS = R"HLSL( Texture2D<float4> g_hdr : register(t0); SamplerState g_samp : register(s0); cbuffer CbTonemap : register(b0) { float Exposure; // EV stops を線形係数に変換した値 (default 1.0) float Gamma; // 出力ガンマ (default 2.2) float2 _pad0; }; struct PSInput { float4 Position : SV_POSITION; float2 TexCoord : TEXCOORD0; }; // ACES filmic (Krzysztof Narkowicz 近似) // https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/ float3 acesFilmic(float3 x) { const float a = 2.51f; const float b = 0.03f; const float c = 2.43f; const float d = 0.59f; const float e = 0.14f; return saturate((x * (a * x + b)) / (x * (c * x + d) + e)); } float4 PSMain(PSInput input) : SV_TARGET { float4 hdr = g_hdr.Sample(g_samp, input.TexCoord); float3 exposed = hdr.rgb * Exposure; float3 mapped = acesFilmic(exposed); // Gamma encode (linear → sRGB approximation) float invG = 1.0f / max(Gamma, 1e-4f); float3 outRGB = pow(max(mapped, 0.0f), invG.xxx); return float4(outRGB, hdr.a); } )HLSL"
struct alignas(16) TonemapCB
`constexpr std::string_view SSR_PS = R"hlsl(
`constexpr std::string_view PARALLAX_HLSL_FUNCTION = R"hlsl(
`constexpr std::string_view SSS_PS = R"hlsl(
`constexpr std::string_view TESSELLATION_HS = R"hlsl(
`constexpr std::string_view TESSELLATION_DS = R"hlsl(
`constexpr std::string_view OIT_ACCUMULATE_PS = R"hlsl(
`constexpr std::string_view OIT_COMPOSITE_PS = R"hlsl(
`constexpr std::string_view PARTICLE_CS = R"hlsl(
struct alignas(16) SSRCBData
Texture2D sceneDepth : register(t1)
Texture2D sceneNormal : register(t2)
SamplerState samp : register(s0)
cbuffer SSRParams : register(b0)
float curH = heightMap.SampleLevel(samp, curUV, 0).r
float before = heightMap.SampleLevel(samp, prevUV, 0).r - curD + layerD
return lerp(curUV, prevUV, w)
struct alignas(16) SSSCBData
Texture2D thicknessMap : register(t1)
SamplerState samp : register(s0)
cbuffer SSSParams : register(b0)
float3 sssKernel(float off, float rad)
struct alignas(16) TessCBData
HConst HSConst(InputPatch<VOut,3> p, uint pid : SV_PrimitiveID)
[domain("tri")][partitioning("fractional_odd")][outputtopology("triangle_cw")] [outputcontrolpoints(3)][patchconstantfunc("HSConst")] HOut HSMain(InputPatch<VOut,3> p, uint id : SV_OutputControlPointID)
cbuffer MB : register(b1)
Texture2D hmap : register(t0)
SamplerState samp : register(s0)
[domain("tri")] DOut DSMain(HConst hc, float3 b : SV_DomainLocation, const OutputPatch<HOut,3> p)
PSOut PSMain(PSIn i)
Texture2D revealTex : register(t1)
SamplerState samp : register(s0)
struct alignas(16) ParticleUpdateCB
cbuffer U : register(b0)
RWStructuredBuffer<P> particles : register(u0)
float hash(uint s)
[numthreads(256,1,1)] void CSMain(uint3 tid : SV_DispatchThreadID)
struct SSRConfig 4
int maxSteps = 64
float stepSize = 0.05f
float thickness = 0.5f
float fadeEdge = 0.1f
struct PSIn 2
float4 pos : SV_POSITION
float2 uv : TEXCOORD0
class SSRPass : public PostProcessPass 5
explicit SSRPass(ID3D11Device* dev, const SSRConfig& cfg = {})
void apply(ID3D11DeviceContext* ctx, ID3D11ShaderResourceView* in, ID3D11RenderTargetView* out, std::uint32_t w, std::uint32_t h) override
[[nodiscard]] std::string_view name() const noexcept override
void setConfig(const SSRConfig& c) noexcept
[[nodiscard]] const SSRConfig& config() const noexcept
struct ParallaxConfig 3
float heightScale = 0.05f
int minLayers = 8
int maxLayers = 32
struct SSSConfig 2
float scatterRadius = 0.01f
float thickness = 1.0f
struct PSIn 2
float4 pos : SV_POSITION
float2 uv : TEXCOORD0
class SSSPass : public PostProcessPass 5
explicit SSSPass(ID3D11Device* dev, const SSSConfig& cfg = {})
void apply(ID3D11DeviceContext* ctx, ID3D11ShaderResourceView* in, ID3D11RenderTargetView* out, std::uint32_t w, std::uint32_t h) override
[[nodiscard]] std::string_view name() const noexcept override
void setConfig(const SSSConfig& c) noexcept
[[nodiscard]] const SSSConfig& config() const noexcept
struct TessellationConfig 3
float tessellationFactor = 8.0f
float displacementScale = 0.1f
std::string heightMapKey
struct VOut 3
float4 pos : SV_POSITION
float3 norm : NORMAL
float2 uv : TEXCOORD0
struct HOut 3
float4 pos : SV_POSITION
float3 norm : NORMAL
float2 uv : TEXCOORD0
struct HConst 2
float et[3] : SV_TessFactor
float it : SV_InsideTessFactor
struct HOut 3
float4 pos : SV_POSITION
float3 norm : NORMAL
float2 uv : TEXCOORD0
struct HConst 2
float et[3] : SV_TessFactor
float it : SV_InsideTessFactor
struct DOut 3
float4 pos : SV_POSITION
float3 norm : NORMAL
float2 uv : TEXCOORD0
class TessellationShaders 5
explicit TessellationShaders(ID3D11Device* dev, const TessellationConfig& cfg = {})
void bind(ID3D11DeviceContext* ctx) const
static void unbind(ID3D11DeviceContext* ctx)
void setConfig(const TessellationConfig& c) noexcept
[[nodiscard]] const TessellationConfig& config() const noexcept
struct OITConfig 1
bool enabled = true
struct PSOut 2
float4 accum : SV_TARGET0
float reveal : SV_TARGET1
struct PSIn 2
float4 pos : SV_POSITION
float2 uv : TEXCOORD0
class OITPass 7
explicit OITPass(ID3D11Device* dev, const OITConfig& cfg = {})
void resize(std::uint32_t w, std::uint32_t h)
void beginTransparentPass(ID3D11DeviceContext* ctx) const
static void endTransparentPass(ID3D11DeviceContext* ctx)
void composite(ID3D11DeviceContext* ctx, ID3D11RenderTargetView* out) const
void setConfig(const OITConfig& c) noexcept
[[nodiscard]] const OITConfig& config() const noexcept
struct GPUParticleConfig 4
std::uint32_t maxParticles = 100000
float gravity = -9.81f
float drag = 0.98f
float emitRate = 1000.0f
struct GPUParticle 7
float pos[3]
float life
float vel[3]
float maxLife
float color[4]
float size
float pad[3]
class ComputeShaderParticles 6
explicit ComputeShaderParticles(ID3D11Device* dev, const GPUParticleConfig& cfg = {})
void update(ID3D11DeviceContext* ctx, float deltaTime)
[[nodiscard]] ID3D11ShaderResourceView* particleSRV() const noexcept
[[nodiscard]] std::uint32_t particleCount() const noexcept
void setConfig(const GPUParticleConfig& c) noexcept
[[nodiscard]] const GPUParticleConfig& config() const noexcept
struct VignetteConfig 3
float intensity = 0.5f
float radius = 0.8f
float softness = 0.5f
class VignettePass : public PostProcessPass 4
VignettePass( ID3D11Device* device, const ComPtr<ID3D11VertexShader>& fullscreenVS, const ComPtr<ID3D11SamplerState>& sampler)
void setConfig(const VignetteConfig& cfg) noexcept
void apply( ID3D11DeviceContext* context, ID3D11ShaderResourceView* inputSRV, ID3D11RenderTargetView* outputRTV, std::uint32_t screenW, std::uint32_t screenH) override
[[nodiscard]] std::string_view name() const noexcept override
struct ChromaticAberrationConfig 1
float intensity = 1.0f
class ChromaticAberrationPass : public PostProcessPass 4
ChromaticAberrationPass( ID3D11Device* device, const ComPtr<ID3D11VertexShader>& fullscreenVS, const ComPtr<ID3D11SamplerState>& sampler)
void setConfig( const ChromaticAberrationConfig& cfg) noexcept
void apply( ID3D11DeviceContext* context, ID3D11ShaderResourceView* inputSRV, ID3D11RenderTargetView* outputRTV, std::uint32_t screenW, std::uint32_t screenH) override
[[nodiscard]] std::string_view name() const noexcept override
struct FilmGrainConfig 2
float intensity = 0.05f
float speed = 1.0f
class FilmGrainPass : public PostProcessPass 5
FilmGrainPass( ID3D11Device* device, const ComPtr<ID3D11VertexShader>& fullscreenVS, const ComPtr<ID3D11SamplerState>& sampler)
void setConfig(const FilmGrainConfig& cfg) noexcept
void updateTime(float deltaTime) noexcept
void apply( ID3D11DeviceContext* context, ID3D11ShaderResourceView* inputSRV, ID3D11RenderTargetView* outputRTV, std::uint32_t screenW, std::uint32_t screenH) override
[[nodiscard]] std::string_view name() const noexcept override
struct BloomConfig 3
float threshold = 0.8f
float intensity = 1.0f
int blurRadius = 8
class BloomPass : public PostProcessPass 4
BloomPass( ID3D11Device* device, const ComPtr<ID3D11VertexShader>& fullscreenVS, const ComPtr<ID3D11SamplerState>& sampler, std::uint32_t screenW, std::uint32_t screenH)
void setConfig(const BloomConfig& cfg) noexcept
void apply( ID3D11DeviceContext* context, ID3D11ShaderResourceView* inputSRV, ID3D11RenderTargetView* outputRTV, std::uint32_t screenW, std::uint32_t screenH) override
[[nodiscard]] std::string_view name() const noexcept override
struct ColorGradingConfig 7
float brightness = 1.0f
float contrast = 1.0f
float saturation = 1.0f
float gamma = 1.0f
float tintR = 1.0f
float tintG = 1.0f
float tintB = 1.0f
class ColorGradingPass : public PostProcessPass 4
ColorGradingPass( ID3D11Device* device, const ComPtr<ID3D11VertexShader>& fullscreenVS, const ComPtr<ID3D11SamplerState>& sampler)
void setConfig(const ColorGradingConfig& cfg) noexcept
void apply( ID3D11DeviceContext* context, ID3D11ShaderResourceView* inputSRV, ID3D11RenderTargetView* outputRTV, std::uint32_t screenW, std::uint32_t screenH) override
[[nodiscard]] std::string_view name() const noexcept override
struct GaussianBlurConfig 2
int radius = 8
float sigma = 4.0f
class GaussianBlurPass : public PostProcessPass 6
GaussianBlurPass( ID3D11Device* device, const ComPtr<ID3D11VertexShader>& fullscreenVS, const ComPtr<ID3D11SamplerState>& sampler, std::uint32_t screenW, std::uint32_t screenH)
void setConfig(const GaussianBlurConfig& cfg) noexcept
void applyBlur( ID3D11DeviceContext* context, ID3D11ShaderResourceView* inputSRV, ID3D11RenderTargetView* outputRTV, std::uint32_t screenW, std::uint32_t screenH)
void apply( ID3D11DeviceContext* context, ID3D11ShaderResourceView* inputSRV, ID3D11RenderTargetView* outputRTV, std::uint32_t screenW, std::uint32_t screenH) override
[[nodiscard]] std::string_view name() const noexcept override
[[nodiscard]] ID3D11ShaderResourceView* intermediateSRV() const noexcept
struct PostProcessConfig 8
bloom
colorGrading
vignette
chromaticAberration
filmGrain
fade
frostGlass
fxaa
class PostProcessChain 9
PostProcessChain( ID3D11Device* device, std::uint32_t screenW, std::uint32_t screenH)
void addPass(std::unique_ptr<PostProcessPass> pass)
void removePass(std::size_t index)
[[nodiscard]] PostProcessPass* getPass( std::size_t index) const noexcept
[[nodiscard]] std::size_t passCount() const noexcept
[[nodiscard]] std::size_t enabledPassCount() const noexcept
void execute( ID3D11DeviceContext* context, ID3D11ShaderResourceView* sceneTextureSRV, ID3D11RenderTargetView* finalRTV)
void resize(std::uint32_t screenW, std::uint32_t screenH)
[[nodiscard]] static PostProcessChain createFromConfig( ID3D11Device* device, std::uint32_t screenW, std::uint32_t screenH, const PostProcessConfig& config)
class PostProcessPass 12
virtual ~PostProcessPass() = default
virtual void apply( ID3D11DeviceContext* context, ID3D11ShaderResourceView* inputSRV, ID3D11RenderTargetView* outputRTV, std::uint32_t screenW, std::uint32_t screenH) = 0
[[nodiscard]] bool isEnabled() const noexcept
void setEnabled(bool enabled) noexcept
[[nodiscard]] virtual std::string_view name() const noexcept = 0
using ComPtr = Microsoft::WRL::ComPtr<T>;
[[nodiscard]] inline PostProcessRT createRenderTarget( ID3D11Device* device, std::uint32_t w, std::uint32_t h, DXGI_FORMAT format = DXGI_FORMAT_R16G16B16A16_FLOAT)
[[nodiscard]] inline ComPtr<ID3D11PixelShader> compilePostProcessPS( ID3D11Device* device, std::string_view source, const char* entryPoint = "PSMain")
[[nodiscard]] inline ComPtr<ID3D11VertexShader> compileFullscreenVS( ID3D11Device* device)
[[nodiscard]] inline ComPtr<ID3D11Buffer> createConstantBuffer( ID3D11Device* device, std::uint32_t sizeBytes)
inline void updateConstantBuffer( ID3D11DeviceContext* context, ID3D11Buffer* buffer, const void* data, std::uint32_t sizeBytes)
[[nodiscard]] inline ComPtr<ID3D11SamplerState> createLinearClampSampler( ID3D11Device* device)
struct PostProcessRT 5
ComPtr<ID3D11Texture2D> texture
ComPtr<ID3D11ShaderResourceView> srv
ComPtr<ID3D11RenderTargetView> rtv
std::uint32_t width = 0
std::uint32_t height = 0
struct FadeConfig 5
float colorR = 0.0f
float colorG = 0.0f
float colorB = 0.0f
float colorA = 1.0f
float progress = 0.0f
class FadePass : public PostProcessPass 4
FadePass( ID3D11Device* device, const ComPtr<ID3D11VertexShader>& fullscreenVS, const ComPtr<ID3D11SamplerState>& sampler)
void setConfig(const FadeConfig& cfg) noexcept
void apply( ID3D11DeviceContext* context, ID3D11ShaderResourceView* inputSRV, ID3D11RenderTargetView* outputRTV, std::uint32_t screenW, std::uint32_t screenH) override
[[nodiscard]] std::string_view name() const noexcept override
struct FrostGlassConfig 5
float blurAmount = 2.0f
float tintR = 0.9f
float tintG = 0.95f
float tintB = 1.0f
float time = 0.0f
class FrostGlassPass : public PostProcessPass 4
FrostGlassPass( ID3D11Device* device, const ComPtr<ID3D11VertexShader>& fullscreenVS, const ComPtr<ID3D11SamplerState>& sampler)
void setConfig(const FrostGlassConfig& cfg) noexcept
void apply( ID3D11DeviceContext* context, ID3D11ShaderResourceView* inputSRV, ID3D11RenderTargetView* outputRTV, std::uint32_t screenW, std::uint32_t screenH) override
[[nodiscard]] std::string_view name() const noexcept override
struct SdfOutlineEffect 2
bool enabled = false
float width = 0.1f
struct SdfShadowEffect 4
bool enabled = false
float offsetX = 2.0f
float offsetY = 2.0f
float softness = 0.15f
struct SdfGlowEffect 2
bool enabled = false
float radius = 0.2f
struct SdfTextEffect 7
SdfOutlineEffect outline
SdfShadowEffect shadow
SdfGlowEffect glow
[[nodiscard]] static SdfTextEffect none() noexcept
[[nodiscard]] static SdfTextEffect withOutline( const sgc::Colorf& color, float width = 0.1f)
[[nodiscard]] static SdfTextEffect withShadow( const sgc::Colorf& color, float offsetX = 2.0f, float offsetY = 2.0f)
[[nodiscard]] static SdfTextEffect withGlow( const sgc::Colorf& color, float radius = 0.2f)
struct SdfGlyphInfo 11
std::uint32_t codepoint = 0
int x0 = 0
int y0 = 0
int x1 = 0
int y1 = 0
float xoff = 0.0f
float yoff = 0.0f
float xadvance = 0.0f
int sdfPadding = 0
[[nodiscard]] int width() const noexcept
[[nodiscard]] int height() const noexcept
struct SdfFontMetrics 5
float ascent = 0.0f
float descent = 0.0f
float lineGap = 0.0f
float lineHeight = 0.0f
float sdfPixelSize = 0.0f
class SdfFontAtlas 27
SdfFontAtlas() = default
explicit SdfFontAtlas(std::vector<std::uint8_t> fontData, float sdfPixelSize = 32.0f, int sdfPadding = 6)
SdfFontAtlas(SdfFontAtlas&& other) noexcept
SdfFontAtlas& operator=(SdfFontAtlas&& other) noexcept
SdfFontAtlas(const SdfFontAtlas&) = delete
SdfFontAtlas& operator=(const SdfFontAtlas&) = delete
void addCodepointRange(std::uint32_t first, std::uint32_t last)
void addCodepoint(std::uint32_t codepoint)
void addAsciiRange()
void addHiraganaRange()
void addKatakanaRange()
void addCommonKanjiRange()
void addFromString(std::string_view text)
void addCjkPunctuationRange()
void addFullwidthRange()
bool buildAtlas(int atlasPadding = 2)
[[nodiscard]] bool valid() const noexcept
[[nodiscard]] const Texture& texture() const noexcept
[[nodiscard]] int atlasWidth() const noexcept
[[nodiscard]] int atlasHeight() const noexcept
[[nodiscard]] const SdfFontMetrics& metrics() const noexcept
[[nodiscard]] float sdfPixelSize() const noexcept
[[nodiscard]] int sdfPadding() const noexcept
[[nodiscard]] const SdfGlyphInfo* findGlyph(std::uint32_t codepoint) const noexcept
[[nodiscard]] float kerning(std::uint32_t cp1, std::uint32_t cp2, float fontSize) const noexcept
[[nodiscard]] std::size_t glyphCount() const noexcept
[[nodiscard]] const std::unordered_map<std::uint32_t, SdfGlyphInfo>& glyphs() const noexcept
struct SdfTextSize 2
float width = 0.0f
float height = 0.0f
struct SdfWrappedLine 9
std::string_view text
float width = 0.0f
[[nodiscard]] inline float sampleAtlasBilinear( const std::vector<std::uint8_t>& pixels, int w, int h, float x, float y) noexcept
template <typename ScreenType> inline void renderGlyphSoftware(ScreenType& screen, const SdfGlyphInfo& gi, const std::vector<std::uint8_t>& atlasPixels, int atlasW, int atlasH, float cursorX, float baseY, float displayScale, const sgc::Colorf& color, float threshold, float extraSmoothing)
template <typename BatchType> inline void drawText(const SdfFontAtlas& atlas, BatchType& batch, std::string_view text, float x, float y, float fontSize, const sgc::Colorf& color)
template <typename BatchType> inline void drawTextExpanded(const SdfFontAtlas& atlas, BatchType& batch, std::string_view text, float x, float y, float fontSize, const sgc::Colorf& color, float expand)
[[nodiscard]] inline std::vector<std::uint32_t> toCodepoints(std::string_view sv)
[[nodiscard]] inline int nextPow2(int v) noexcept
[[nodiscard]] inline float smoothstep(float edge0, float edge1, float x) noexcept
class Utf8Decoder 4
Utf8Decoder(const char* str, std::size_t len) noexcept
explicit Utf8Decoder(std::string_view sv) noexcept
[[nodiscard]] bool hasNext() const noexcept
[[nodiscard]] std::uint32_t next() noexcept

Sourced from docs/API_CATALOG.md, auto-generated by tools/generate_api_catalog.py.