Fix particle sizes, and add tools for comparing renderers

Particles: Direct3D 9's size limit evidently isn't the documented 64 pixels; unclamped (up to 2048) they match the client's renderer. A compare view shows the left half's scene over the right half, both renderers side by side; %TEMP%\t5de-renderer-view.txt switches views and %TEMP%\t5de-renderer-shaders\fixed_function.hlsl replaces the shaders while the client runs. The renderer process runs from a copy, so the program can be replaced meanwhile. The adapter recognizes only the textures and buffers it made (others reach the client renderer unchanged) and logs the others and render targets.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
dhkatzandClaude Opus 5.5 committed 2026-10-28 06:43:34 -07:00
1 parent 1a45bf9a86
commit 299cd8c312
11 files changed
+239 -28

No files matched your search

+32 -2
View File
@@ -1,5 +1,8 @@
#include "scene.hpp"
#include <algorithm>
#include <array>
#include <cmath>
#include <cstring>
#include <string>
@@ -56,7 +59,7 @@ constexpr std::uint32_t hasColors = 4;
} // namespace
Scene::Scene(IRenderDevice* device, IDeviceContext* context, ISwapChain* swapChain)
: device_(device), context_(context), swapChain_(swapChain)
: device_(device), context_(context), swapChain_(swapChain), shaderSource_(fixedFunctionHlsl)
{
BufferDesc constants;
constants.Name = "Constants";
@@ -86,6 +89,13 @@ Scene::Scene(IRenderDevice* device, IDeviceContext* context, ISwapChain* swapCha
constants_.flags[2] = 127; // the client's alpha reference
}
void Scene::setShaderSource(std::string source)
{
shaderSource_ = std::move(source);
shaders_.clear();
pipelines_.clear();
}
bool Scene::execute(std::span<const std::byte> commands, int offsetX, bool draw)
{
offsetX_ = offsetX;
@@ -546,6 +556,26 @@ void Scene::drawPointSprites(const protocol::Command& command)
constants_.ambient[1], constants_.ambient[2], constants_.texTransform0[0], constants_.texTransform0[1],
constants_.texTransform0[2], constants_.texTransform0[4], constants_.texTransform0[5],
constants_.texTransform0[6]);
// The first sprite: where it is, seen from the camera, and how big it's drawn.
float point[4] = {0, 0, 0, 1};
std::uint32_t color = 0;
std::memcpy(point, payload.data(), 12);
std::memcpy(&color, payload.data() + 12, 4);
const auto transform = [](const float (&p)[4], const float (&m)[16]) {
std::array<float, 4> out{};
for (int column = 0; column < 4; ++column) {
out[column] = p[0] * m[column] + p[1] * m[4 + column] + p[2] * m[8 + column] + p[3] * m[12 + column];
}
return out;
};
const auto world = transform(point, constants_.world);
const float worldPoint[4] = {world[0], world[1], world[2], world[3]};
const auto view = transform(worldPoint, constants_.view);
const float distance = std::sqrt(view[0] * view[0] + view[1] * view[1] + view[2] * view[2]);
log::info(" first sprite at ({:.2f} {:.2f} {:.2f}), color {:08x}, from the camera ({:.2f} {:.2f} {:.2f}): "
"distance {:.2f}, {:.1f} pixels across (viewport height {})",
point[0], point[1], point[2], color, view[0], view[1], view[2], distance,
std::clamp(constants_.viewport[1] / std::max(distance, 1e-4f), 1.0f, 2048.0f), constants_.viewport[1]);
}
IBuffer* buffers[] = {buffer};
context_->SetVertexBuffers(0, 1, buffers, nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION,
@@ -565,7 +595,7 @@ const Scene::Shaders& Scene::shaders(std::uint32_t streams, std::uint32_t textur
const std::string source = std::string("#define HAS_NORMALS ") + ((streams & hasNormals) != 0 ? "1" : "0") +
"\n#define HAS_TEX_COORDS " + ((streams & hasTexCoords) != 0 ? "1" : "0") +
"\n#define HAS_COLORS " + ((streams & hasColors) != 0 ? "1" : "0") +
"\n#define TEXTURES " + std::to_string(textures) + "\n" + fixedFunctionHlsl;
"\n#define TEXTURES " + std::to_string(textures) + "\n" + shaderSource_;
Shaders created;
ShaderCreateInfo info;
info.SourceLanguage = SHADER_SOURCE_LANGUAGE_HLSL;