|
|
@@ -10,7 +10,8 @@
|
|
|
#define DIRTY_RECTANGLE_OPTIMIZATION
|
|
|
|
|
|
namespace dsr {
|
|
|
-
|
|
|
+
|
|
|
+template <bool HIGH_QUALITY>
|
|
|
static IRect renderModel(Model model, OrthoView view, ImageF32 depthBuffer, ImageRgbaU8 diffuseTarget, ImageRgbaU8 normalTarget, FVector2D worldOrigin, Transform3D modelToWorldSpace);
|
|
|
|
|
|
struct SpriteConfig {
|
|
|
@@ -226,7 +227,7 @@ static IRect drawSprite(const Sprite& sprite, const OrthoView& ortho, const IVec
|
|
|
}
|
|
|
|
|
|
static IRect drawModel(const ModelInstance& instance, const OrthoView& ortho, const IVector2D& worldCenter, ImageF32 targetHeight, ImageRgbaU8 targetColor, ImageRgbaU8 targetNormal) {
|
|
|
- return renderModel(instance.visibleModel, ortho, targetHeight, targetColor, targetNormal, FVector2D(worldCenter.x, worldCenter.y), instance.location);
|
|
|
+ return renderModel<false>(instance.visibleModel, ortho, targetHeight, targetColor, targetNormal, FVector2D(worldCenter.x, worldCenter.y), instance.location);
|
|
|
}
|
|
|
|
|
|
// The camera transform for each direction
|
|
|
@@ -851,6 +852,7 @@ static IRect getBackCulledTriangleBound(LVector2D a, LVector2D b, LVector2D c) {
|
|
|
// Returns the dirty pixel bound based on projected positions
|
|
|
// worldOrigin is the perceived world's origin in target pixel coordinates
|
|
|
// modelToWorldSpace is used to place the model freely in the world
|
|
|
+template <bool HIGH_QUALITY>
|
|
|
static IRect renderModel(Model model, OrthoView view, ImageF32 depthBuffer, ImageRgbaU8 diffuseTarget, ImageRgbaU8 normalTarget, FVector2D worldOrigin, Transform3D modelToWorldSpace) {
|
|
|
// Combine position transforms
|
|
|
Transform3D objectToScreenSpace = modelToWorldSpace * Transform3D(FVector3D(worldOrigin.x, worldOrigin.y, 0.0f), view.worldSpaceToScreenDepth);
|
|
|
@@ -949,11 +951,16 @@ static IRect renderModel(Model model, OrthoView view, ImageF32 depthBuffer, Imag
|
|
|
float height = interpolateUsingAffineWeight(pointA.z, pointB.z, pointC.z, weight);
|
|
|
if (height > *heightPixel) {
|
|
|
FVector3D vertexColor = interpolateUsingAffineWeight(vertexColorA, vertexColorB, vertexColorC, weight);
|
|
|
- FVector3D normal = (normalize(interpolateUsingAffineWeight(normalA, normalB, normalC, weight)) + 1.0f) * 127.5f;
|
|
|
- // Write data directly without saturation (Do not use colors outside of the visible range!)
|
|
|
*heightPixel = height;
|
|
|
+ // Write data directly without saturation (Do not use colors outside of the visible range!)
|
|
|
*diffusePixel = ((uint32_t)vertexColor.x) | ENDIAN_POS_ADDR(((uint32_t)vertexColor.y), 8) | ENDIAN_POS_ADDR(((uint32_t)vertexColor.z), 16) | ENDIAN_POS_ADDR(255, 24);
|
|
|
- *normalPixel = ((uint32_t)normal.x) | ENDIAN_POS_ADDR(((uint32_t)normal.y), 8) | ENDIAN_POS_ADDR(((uint32_t)normal.z), 16) | ENDIAN_POS_ADDR(255, 24);
|
|
|
+ if (HIGH_QUALITY) {
|
|
|
+ FVector3D normal = (normalize(interpolateUsingAffineWeight(normalA, normalB, normalC, weight)) + 1.0f) * 127.5f;
|
|
|
+ *normalPixel = ((uint32_t)normal.x) | ENDIAN_POS_ADDR(((uint32_t)normal.y), 8) | ENDIAN_POS_ADDR(((uint32_t)normal.z), 16) | ENDIAN_POS_ADDR(255, 24);
|
|
|
+ } else {
|
|
|
+ FVector3D normal = (interpolateUsingAffineWeight(normalA, normalB, normalC, weight) + 1.0f) * 127.5f;
|
|
|
+ *normalPixel = ((uint32_t)normal.x) | ENDIAN_POS_ADDR(((uint32_t)normal.y), 8) | ENDIAN_POS_ADDR(((uint32_t)normal.z), 16) | ENDIAN_POS_ADDR(255, 24);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
diffusePixel += 1;
|
|
|
@@ -1017,7 +1024,7 @@ void sprite_generateFromModel(ImageRgbaU8& targetAtlas, String& targetConfigText
|
|
|
image_fill(colorImage[a], ColorRgbaI32(0, 0, 0, 0));
|
|
|
importer_generateNormalsIntoTextureCoordinates(visibleModel);
|
|
|
FVector2D origin = FVector2D((float)width * 0.5f, (float)height * 0.5f);
|
|
|
- renderModel(visibleModel, ortho.view[a], depthBuffer, colorImage[a], normalImage[a], origin, Transform3D());
|
|
|
+ renderModel<true>(visibleModel, ortho.view[a], depthBuffer, colorImage[a], normalImage[a], origin, Transform3D());
|
|
|
// Convert height into an 8 bit channel for saving
|
|
|
for (int y = 0; y < height; y++) {
|
|
|
for (int x = 0; x < width; x++) {
|