diff --git a/tests/RHI/D3D12/integration/sphere/GT.ppm b/tests/RHI/D3D12/integration/sphere/GT.ppm index 4aa52a9a..37a204fe 100644 Binary files a/tests/RHI/D3D12/integration/sphere/GT.ppm and b/tests/RHI/D3D12/integration/sphere/GT.ppm differ diff --git a/tests/RHI/D3D12/integration/sphere/Res/Shader/sphere.hlsl b/tests/RHI/D3D12/integration/sphere/Res/Shader/sphere.hlsl index 3cc02c4d..11b83793 100644 --- a/tests/RHI/D3D12/integration/sphere/Res/Shader/sphere.hlsl +++ b/tests/RHI/D3D12/integration/sphere/Res/Shader/sphere.hlsl @@ -28,5 +28,5 @@ VSOut MainVS(Vertex v) { } float4 MainPS(VSOut i) : SV_TARGET { - return gDiffuseTexture.Sample(gSampler, i.texcoord.xy); + return gDiffuseTexture.Sample(gSampler, float2(i.texcoord.x, i.texcoord.y)); } \ No newline at end of file diff --git a/tests/RHI/D3D12/integration/sphere/main.cpp b/tests/RHI/D3D12/integration/sphere/main.cpp index 173f6e52..269b1772 100644 --- a/tests/RHI/D3D12/integration/sphere/main.cpp +++ b/tests/RHI/D3D12/integration/sphere/main.cpp @@ -3,6 +3,7 @@ #include #include #include +#define _USE_MATH_DEFINES #include #include #include @@ -172,24 +173,26 @@ void GenerateSphere(std::vector& vertices, std::vector& indices, vertices.clear(); indices.clear(); - for (int lat = 0; lat <= segments; lat++) { - float theta = lat * 3.14159f / segments; - float sinTheta = sinf(theta); - float cosTheta = cosf(theta); + segments = (segments < 3) ? 3 : segments; - for (int lon = 0; lon <= segments; lon++) { - float phi = lon * 2.0f * 3.14159f / segments; - float sinPhi = sinf(phi); - float cosPhi = cosf(phi); + for (int lat = 0; lat <= segments; ++lat) { + float phi = static_cast(M_PI) * lat / segments; + float sinPhi = sinf(phi); + float cosPhi = cosf(phi); + + for (int lon = 0; lon <= segments; ++lon) { + float theta = static_cast(2 * M_PI) * lon / segments; + float sinTheta = sinf(theta); + float cosTheta = cosf(theta); Vertex v; - v.pos[0] = radius * sinTheta * cosPhi; - v.pos[1] = radius * cosTheta; - v.pos[2] = radius * sinTheta * sinPhi; + v.pos[0] = radius * sinPhi * cosTheta; + v.pos[1] = radius * cosPhi; + v.pos[2] = radius * sinPhi * sinTheta; v.pos[3] = 1.0f; - v.texcoord[0] = (float)lon / segments; - v.texcoord[1] = (float)lat / segments; + v.texcoord[0] = static_cast(lon) / segments; + v.texcoord[1] = static_cast(lat) / segments; v.texcoord[2] = 0.0f; v.texcoord[3] = 0.0f; @@ -197,18 +200,20 @@ void GenerateSphere(std::vector& vertices, std::vector& indices, } } - for (int lat = 0; lat < segments; lat++) { - for (int lon = 0; lon < segments; lon++) { - int first = lat * (segments + 1) + lon; - int second = first + segments + 1; + for (int lat = 0; lat < segments; ++lat) { + for (int lon = 0; lon < segments; ++lon) { + UINT32 topLeft = lat * (segments + 1) + lon; + UINT32 topRight = topLeft + 1; + UINT32 bottomLeft = (lat + 1) * (segments + 1) + lon; + UINT32 bottomRight = bottomLeft + 1; - indices.push_back(first); - indices.push_back(second); - indices.push_back(first + 1); + indices.push_back(topLeft); + indices.push_back(bottomLeft); + indices.push_back(topRight); - indices.push_back(second); - indices.push_back(second + 1); - indices.push_back(first + 1); + indices.push_back(topRight); + indices.push_back(bottomLeft); + indices.push_back(bottomRight); } } } @@ -367,7 +372,7 @@ bool InitD3D12() { psoDesc.RasterizerState.FrontCounterClockwise = FALSE; psoDesc.RasterizerState.DepthClipEnable = TRUE; psoDesc.DepthStencilState.DepthEnable = TRUE; - psoDesc.DepthStencilState.DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ZERO; + psoDesc.DepthStencilState.DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL; psoDesc.DepthStencilState.DepthFunc = D3D12_COMPARISON_FUNC_LESS; psoDesc.BlendState.RenderTarget[0].BlendEnable = FALSE; psoDesc.BlendState.RenderTarget[0].SrcBlend = D3D12_BLEND_ONE;