Skip to content

Commit fa20b7c

Browse files
committed
SlangをColumnMajorに変更
1 parent 7777d80 commit fa20b7c

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

sample/hello_raytracing/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class HelloApp : public App {
115115
vk::ImageLayout::ePresentSrcKHR);
116116
}
117117

118-
std::vector<Vertex> m_vertices{{{-1, 0, 0}}, {{0, -1, 0}}, {{1, 0, 0}}};
118+
std::vector<Vertex> m_vertices{{{-1, 0, 0}}, {{0, 1, 0}}, {{1, 0, 0}}};
119119
std::vector<uint32_t> m_indices{0, 1, 2};
120120
Mesh m_mesh;
121121

sample/hello_raytracing/shaders.slang

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,25 @@ struct RayPayload
1616
float3 color;
1717
};
1818

19+
float2 PixelToScreen(uint2 launchID, uint2 launchSize)
20+
{
21+
float2 screen = ((float2(launchID.xy) + float2(0.5f)) / float2(launchSize.xy)) * 2.0f - 1.0f;
22+
return { screen.x, -screen.y };
23+
}
24+
1925
[shader("raygeneration")]
2026
void rayGenMain()
2127
{
2228
uint3 launchID = DispatchRaysIndex();
2329
uint3 launchSize = DispatchRaysDimensions();
2430

2531
// 画面上のUV座標を [(-1) .. (+1)] にマッピング
26-
float2 uv = (float2(launchID.xy) / float2(launchSize.xy)) * 2.0f - 1.0f;
32+
float2 screen = PixelToScreen(launchID.xy, launchSize.xy);
2733

2834
// 逆行列を使ってワールド座標系でのレイを生成
29-
float4 origin = mul(float4(0, 0, 0, 1), gPush.invView);
30-
float4 target = mul(float4(uv.x, uv.y, 1.0f, 1.0f), gPush.invProj);
31-
float4 direction = mul(float4(normalize(target.xyz), 0), gPush.invView);
35+
float4 origin = mul(gPush.invView, float4(0, 0, 0, 1));
36+
float4 target = mul(gPush.invProj, float4(screen.xy, 1.0f, 1.0f));
37+
float4 direction = mul(gPush.invView, float4(normalize(target.xyz), 0));
3238

3339
// Ray Payload 初期化
3440
RayPayload payload;

src/Compiler/Compiler.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ std::vector<Slang::ComPtr<slang::IBlob>> SlangCompiler::compileShaders(const std
6262
sessionDesc.targetCount = 1;
6363
sessionDesc.compilerOptionEntries = options.data();
6464
sessionDesc.compilerOptionEntryCount = (uint32_t)options.size();
65+
sessionDesc.defaultMatrixLayoutMode = SLANG_MATRIX_LAYOUT_COLUMN_MAJOR;
6566

6667
Slang::ComPtr<slang::ISession> session;
6768
ASSERT_ON_SLANG_FAIL(m_globalSession->createSession(sessionDesc, session.writeRef()));

0 commit comments

Comments
 (0)