Selaa lähdekoodia

fixed additional bug in fog

UwU 1 päivä sitten
vanhempi
commit
50896186ed

+ 0 - 8
src/WallpaperEngine/Data/Assets/Texture.h

@@ -152,14 +152,6 @@ struct Texture {
     std::map<uint32_t, MipmapList> images {};
     std::vector<FrameSharedPtr> frames {};
 
-    /** Spritesheet grid data (from .tex-json metadata) */
-    uint32_t spritesheetCols = 0;
-    uint32_t spritesheetRows = 0;
-    uint32_t spritesheetFrames = 0;
-    float spritesheetDuration = 0.0f;
-
     [[nodiscard]] bool isAnimated () const { return (flags & TextureFlags_IsGif) == TextureFlags_IsGif; }
-
-    [[nodiscard]] bool hasSpritesheet () const { return spritesheetFrames > 0; }
 };
 }

+ 0 - 70
src/WallpaperEngine/Data/Parsers/TextureParser.cpp

@@ -274,34 +274,6 @@ void TextureParser::parseAnimations (Texture& header, const BinaryReader& file)
 	header.gifWidth = (*header.frames.begin ())->width1;
 	header.gifHeight = (*header.frames.begin ())->height1;
     }
-
-    // spritesheets are grid-based; infer the grid from texture size vs. frame size
-    if (!header.frames.empty () && header.width > 0 && header.height > 0) {
-	auto& firstFrame = *header.frames.front ();
-	float frameWidth = firstFrame.width1;
-	float frameHeight = firstFrame.height1;
-
-	if (frameWidth > 0.0f && frameHeight > 0.0f) {
-	    const uint32_t cols = static_cast<uint32_t> (std::round (static_cast<double> (header.width) / frameWidth));
-	    const uint32_t rows
-		= static_cast<uint32_t> (std::round (static_cast<double> (header.height) / frameHeight));
-	    const uint32_t frameCount = static_cast<uint32_t> (header.frames.size ());
-
-	    // only accept the grid if it can hold all frames - otherwise plain GIFs (frameWidth == textureWidth)
-	    // would get treated as 1x1 spritesheets
-	    if (cols > 0 && rows > 0 && cols * rows >= frameCount) {
-		header.spritesheetCols = cols;
-		header.spritesheetRows = rows;
-		header.spritesheetFrames = frameCount;
-
-		float totalDuration = 0.0f;
-		for (const auto& frame : header.frames) {
-		    totalDuration += frame->frametime;
-		}
-		header.spritesheetDuration = totalDuration;
-	    }
-	}
-    }
 }
 
 uint32_t TextureParser::parseTextureFlags (uint32_t value) {
@@ -355,46 +327,4 @@ FIF TextureParser::parseFIF (uint32_t value) {
 	default:
 	    sLog.exception ("unknown free image format: ", value);
     }
-}
-
-TextureUniquePtr TextureParser::parse (
-    const BinaryReader& file, const std::string& filename,
-    std::function<std::string (const std::string&)> metadataLoader
-) {
-    auto result = parse (file);
-
-    if (metadataLoader) {
-	parseSpritesheetMetadata (*result, filename, metadataLoader);
-    }
-
-    return result;
-}
-
-void TextureParser::parseSpritesheetMetadata (
-    Texture& header, const std::string& filename, std::function<std::string (const std::string&)> metadataLoader
-) {
-    try {
-	std::string texJsonContent = metadataLoader (filename + ".tex-json");
-	nlohmann::json texJson = nlohmann::json::parse (texJsonContent);
-
-	if (texJson.contains ("spritesheetsequences") && texJson["spritesheetsequences"].is_array ()) {
-	    auto& sequences = texJson["spritesheetsequences"];
-	    if (!sequences.empty ()) {
-		auto& firstSeq = sequences[0];
-		int frames = firstSeq.value ("frames", 0);
-		float frameWidth = firstSeq.value ("width", 0.0f);
-		float frameHeight = firstSeq.value ("height", 0.0f);
-		float duration = firstSeq.value ("duration", 1.0f);
-
-		if (frames > 0 && frameWidth > 0.0f && frameHeight > 0.0f && header.width > 0 && header.height > 0) {
-		    header.spritesheetCols = static_cast<uint32_t> (std::round (header.width / frameWidth));
-		    header.spritesheetRows = static_cast<uint32_t> (std::round (header.height / frameHeight));
-		    header.spritesheetFrames = static_cast<uint32_t> (frames);
-		    header.spritesheetDuration = duration;
-		}
-	    }
-	}
-    } catch (const std::exception&) {
-	// .tex-json file is optional, only used for spritesheet data
-    }
 }

+ 0 - 7
src/WallpaperEngine/Data/Parsers/TextureParser.h

@@ -18,10 +18,6 @@ using namespace WallpaperEngine::Data::Model;
 class TextureParser {
 public:
     static TextureUniquePtr parse (const BinaryReader& file);
-    static TextureUniquePtr parse (
-	const BinaryReader& file, const std::string& filename,
-	std::function<std::string (const std::string&)> metadataLoader
-    );
     static MipmapSharedPtr parseMipmap (const BinaryReader& file, const Texture& header);
     static FrameSharedPtr parseFrame (const BinaryReader& file);
     static FrameSharedPtr parseFrameV1 (const BinaryReader& file);
@@ -31,9 +27,6 @@ private:
     static void parseTextureHeader (Texture& header, const BinaryReader& file);
     static void parseContainer (Texture& header, const BinaryReader& file);
     static void parseAnimations (Texture& header, const BinaryReader& file);
-    static void parseSpritesheetMetadata (
-	Texture& header, const std::string& filename, std::function<std::string (const std::string&)> metadataLoader
-    );
     static TextureFormat parseTextureFormat (uint32_t value);
     static uint32_t parseTextureFlags (uint32_t value);
     static FIF parseFIF (uint32_t value);

+ 0 - 4
src/WallpaperEngine/Render/AlbumTexture.cpp

@@ -56,10 +56,6 @@ uint32_t AlbumTexture::getFlags () const { return TextureFlags_NoFlags; }
 const std::vector<FrameSharedPtr>& AlbumTexture::getFrames () const { return this->m_frames; }
 const glm::vec4* AlbumTexture::getResolution () const { return &this->m_resolution; }
 bool AlbumTexture::isAnimated () const { return false; }
-uint32_t AlbumTexture::getSpritesheetCols () const { return 1; }
-uint32_t AlbumTexture::getSpritesheetRows () const { return 1; }
-uint32_t AlbumTexture::getSpritesheetFrames () const { return 1; }
-float AlbumTexture::getSpritesheetDuration () const { return 0.0f; }
 
 void AlbumTexture::incrementUsageCount () const { }
 void AlbumTexture::decrementUsageCount () const { }

+ 0 - 4
src/WallpaperEngine/Render/AlbumTexture.h

@@ -20,10 +20,6 @@ public:
     [[nodiscard]] const std::vector<FrameSharedPtr>& getFrames () const override;
     [[nodiscard]] const glm::vec4* getResolution () const override;
     [[nodiscard]] bool isAnimated () const override;
-    [[nodiscard]] uint32_t getSpritesheetCols () const override;
-    [[nodiscard]] uint32_t getSpritesheetRows () const override;
-    [[nodiscard]] uint32_t getSpritesheetFrames () const override;
-    [[nodiscard]] float getSpritesheetDuration () const override;
 
     void incrementUsageCount () const override;
     void decrementUsageCount () const override;

+ 0 - 16
src/WallpaperEngine/Render/CFBO.cpp

@@ -200,22 +200,6 @@ const glm::vec4* CFBO::getResolution () const { return &this->m_resolution; }
 
 bool CFBO::isAnimated () const { return false; }
 
-uint32_t CFBO::getSpritesheetCols () const {
-    return 0; // FBOs don't have spritesheets
-}
-
-uint32_t CFBO::getSpritesheetRows () const {
-    return 0; // FBOs don't have spritesheets
-}
-
-uint32_t CFBO::getSpritesheetFrames () const {
-    return 0; // FBOs don't have spritesheets
-}
-
-float CFBO::getSpritesheetDuration () const {
-    return 0.0f; // FBOs don't have spritesheets
-}
-
 void CFBO::incrementUsageCount () const { }
 void CFBO::decrementUsageCount () const { }
 void CFBO::update () const { }

+ 0 - 4
src/WallpaperEngine/Render/CFBO.h

@@ -50,10 +50,6 @@ public:
     [[nodiscard]] const std::vector<FrameSharedPtr>& getFrames () const override;
     [[nodiscard]] const glm::vec4* getResolution () const override;
     [[nodiscard]] bool isAnimated () const override;
-    [[nodiscard]] uint32_t getSpritesheetCols () const override;
-    [[nodiscard]] uint32_t getSpritesheetRows () const override;
-    [[nodiscard]] uint32_t getSpritesheetFrames () const override;
-    [[nodiscard]] float getSpritesheetDuration () const override;
 
     void incrementUsageCount () const override;
     void decrementUsageCount () const override;

+ 7 - 21
src/WallpaperEngine/Render/CTexture.cpp

@@ -137,20 +137,14 @@ CTexture::~CTexture () {
 }
 
 void CTexture::setupResolution () {
-    if (this->isAnimated ()) {
-	this->m_resolution = { this->m_header->textureWidth, this->m_header->textureHeight, this->m_header->gifWidth,
-			       this->m_header->gifHeight };
+    if (this->m_header->freeImageFormat != FIF_UNKNOWN) {
+	// wpengine-texture format always has one mipmap
+	const auto element = this->m_header->images.find (0)->second.begin ();
+
+	this->m_resolution = { (*element)->width, (*element)->height, this->m_header->width, this->m_header->height };
     } else {
-	if (this->m_header->freeImageFormat != FIF_UNKNOWN) {
-	    // wpengine-texture format always has one mipmap
-	    const auto element = this->m_header->images.find (0)->second.begin ();
-
-	    this->m_resolution
-		= { (*element)->width, (*element)->height, this->m_header->width, this->m_header->height };
-	} else {
-	    this->m_resolution = { this->m_header->textureWidth, this->m_header->textureHeight, this->m_header->width,
-				   this->m_header->height };
-	}
+	this->m_resolution = { this->m_header->textureWidth, this->m_header->textureHeight, this->m_header->width,
+			       this->m_header->height };
     }
 }
 
@@ -246,14 +240,6 @@ const std::vector<FrameSharedPtr>& CTexture::getFrames () const { return this->g
 
 bool CTexture::isAnimated () const { return this->getHeader ().isAnimated (); }
 
-uint32_t CTexture::getSpritesheetCols () const { return this->getHeader ().spritesheetCols; }
-
-uint32_t CTexture::getSpritesheetRows () const { return this->getHeader ().spritesheetRows; }
-
-uint32_t CTexture::getSpritesheetFrames () const { return this->getHeader ().spritesheetFrames; }
-
-float CTexture::getSpritesheetDuration () const { return this->getHeader ().spritesheetDuration; }
-
 void CTexture::incrementUsageCount () const {
     if (this->m_player) {
 	this->m_player->incrementUsageCount ();

+ 0 - 4
src/WallpaperEngine/Render/CTexture.h

@@ -36,10 +36,6 @@ public:
     [[nodiscard]] const glm::vec4* getResolution () const override;
     [[nodiscard]] const std::vector<FrameSharedPtr>& getFrames () const override;
     [[nodiscard]] bool isAnimated () const override;
-    [[nodiscard]] uint32_t getSpritesheetCols () const override;
-    [[nodiscard]] uint32_t getSpritesheetRows () const override;
-    [[nodiscard]] uint32_t getSpritesheetFrames () const override;
-    [[nodiscard]] float getSpritesheetDuration () const override;
 
     /** For video CTextures, playback only starts once usage count goes above zero (initializes mpv if needed) */
     void incrementUsageCount () const override;

+ 10 - 1
src/WallpaperEngine/Render/Objects/CImage.cpp

@@ -2445,7 +2445,16 @@ glm::vec2 CImage::resolveGeometrySize (float sceneWidth, float sceneHeight, glm:
 void CImage::updateScenePosition (
     const glm::vec3& origin, const glm::vec2& size, const glm::vec3& scale, float sceneWidth, float sceneHeight
 ) {
-    const glm::vec2 scaledSize = size * glm::vec2 (scale);
+    glm::vec2 displaySize = size;
+    const glm::vec2 declared = this->getImage ().size;
+    const auto& model = *this->getImage ().model;
+
+    if (!model.fullscreen && !model.autosize && !model.puppet.has_value () && declared.x > 0.0f
+	&& declared.y > 0.0f) {
+	displaySize = declared;
+    }
+
+    const glm::vec2 scaledSize = displaySize * glm::vec2 (scale);
     this->m_pos.x = origin.x - (scaledSize.x / 2.0f);
     this->m_pos.w = origin.y + (scaledSize.y / 2.0f);
     this->m_pos.z = origin.x + (scaledSize.x / 2.0f);

+ 17 - 24
src/WallpaperEngine/Render/Objects/CParticle.cpp

@@ -187,14 +187,8 @@ void CParticle::setup () {
 	}
     }
 
-    // TextureParser computes the spritesheet grid from TEXS frame data (animated textures) or
-    // .tex-json metadata (static textures). GIF-style animated textures (separate GL texture per
-    // frame) get 0 cols/rows since a 1x1 grid can't hold all frames - no SPRITESHEET mode needed,
-    // frame switching happens via texture ID instead.
-    if (const auto texture = getTexture ()) {
-	m_spritesheetCols = static_cast<int> (texture->getSpritesheetCols ());
-	m_spritesheetRows = static_cast<int> (texture->getSpritesheetRows ());
-	m_spritesheetFrames = static_cast<int> (texture->getSpritesheetFrames ());
+    if (const auto texture = getTexture (); texture && texture->isAnimated ()) {
+	m_spritesheetFrames = static_cast<int> (texture->getFrames ().size ());
     }
 
     // wallpaper64.exe system flag 2: only angularvelocityrandom and angularmovement make angular speed a thing, the
@@ -3825,6 +3819,12 @@ void CParticle::setupPass () {
     }
     if (m_spritesheetFrames > 0) {
 	m_passOverride->combos["SPRITESHEET"] = 1;
+	m_passOverride->combos["SPRITESHEETBLEND"]
+	    = (m_particle.flags & 2) == 0 && m_particle.animationMode != "randomframe" ? 1 : 0;
+	if (const auto texture = getTexture ()) {
+	    const glm::vec4* res = texture->getResolution ();
+	    m_passOverride->combos["SPRITESHEETBLENDNPOT"] = res->z < res->x ? 1 : 0;
+	}
     }
     if (m_useTrailRenderer) {
 	m_passOverride->combos["TRAILRENDERER"] = 1;
@@ -4053,22 +4053,15 @@ void CParticle::updateParticleRenderVars () {
 	m_renderVar0 = glm::vec4 (m_trailLength, m_trailMaxLength, m_trailMinLength, 0.0f);
     }
 
-    if (m_spritesheetFrames > 0 && m_spritesheetCols > 0 && m_spritesheetRows > 0) {
-	float frameWidth = 1.0f / static_cast<float> (m_spritesheetCols);
-	float frameHeight = 1.0f / static_cast<float> (m_spritesheetRows);
-	float textureRatio = 1.0f;
-	if (const auto texture = getTexture ()) {
-	    // Use atlas dimensions (resolution vec4) rather than getRealWidth/Height, which
-	    // returns per-frame dimensions for animated textures - the shader needs the
-	    // per-frame pixel aspect ratio: (atlasH * frameHeight) / (atlasW * frameWidth).
-	    const glm::vec4* res = texture->getResolution ();
-	    float w = res->x;
-	    float h = res->y;
-	    if (w > 0.0f) {
-		textureRatio = (h * frameHeight) / (w * frameWidth);
-	    }
-	}
-	m_renderVar1 = glm::vec4 (frameWidth, frameHeight, static_cast<float> (m_spritesheetFrames), textureRatio);
+    if (m_spritesheetFrames > 0) {
+	const auto texture = getTexture ();
+	const auto& frame = *texture->getFrames ().front ();
+	const float frameWidth = frame.width1 / static_cast<float> (texture->getTextureWidth (frame.frameNumber));
+	const float frameHeight = frame.height1 / static_cast<float> (texture->getTextureHeight (frame.frameNumber));
+	const glm::vec4* res = texture->getResolution ();
+	m_renderVar1 = glm::vec4 (
+	    frameWidth, frameHeight, static_cast<float> (m_spritesheetFrames), res->y / res->x * (frameHeight / frameWidth)
+	);
     } else {
 	float textureRatio = 1.0f;
 	if (const auto texture = getTexture ()) {

+ 0 - 2
src/WallpaperEngine/Render/Objects/CParticle.h

@@ -308,8 +308,6 @@ private:
     glm::vec4 m_renderVar0 { 0.0f };
     glm::vec4 m_renderVar1 { 0.0f };
 
-    int m_spritesheetCols { 0 };
-    int m_spritesheetRows { 0 };
     int m_spritesheetFrames { 0 };
 
     float m_overbright { 1.0f };

+ 0 - 4
src/WallpaperEngine/Render/Objects/CText.cpp

@@ -117,10 +117,6 @@ public:
     [[nodiscard]] const std::vector<FrameSharedPtr>& getFrames () const override { return m_frames; }
     [[nodiscard]] const glm::vec4* getResolution () const override { return &m_resolution; }
     [[nodiscard]] bool isAnimated () const override { return false; }
-    [[nodiscard]] uint32_t getSpritesheetCols () const override { return 1; }
-    [[nodiscard]] uint32_t getSpritesheetRows () const override { return 1; }
-    [[nodiscard]] uint32_t getSpritesheetFrames () const override { return 1; }
-    [[nodiscard]] float getSpritesheetDuration () const override { return 0.0f; }
 
     void incrementUsageCount () const override { }
     void decrementUsageCount () const override { }

+ 1 - 6
src/WallpaperEngine/Render/TextureCache.cpp

@@ -317,12 +317,7 @@ std::shared_ptr<const TextureProvider> TextureCache::resolve (const std::string&
 	    const auto contents = project.assetLocator->texture (filename);
 	    auto stream = BinaryReader (contents);
 
-	    auto metadataLoader = [&project] (const std::string& metaFilename) -> std::string {
-		std::filesystem::path fullPath = std::filesystem::path ("materials") / metaFilename;
-		return project.assetLocator->readString (fullPath);
-	    };
-
-	    parsedTexture = TextureParser::parse (stream, filename, metadataLoader);
+	    parsedTexture = TextureParser::parse (stream);
 	} catch (AssetLoadException&) {
 	    const auto extension = lowerExtension (filename);
 

+ 0 - 7
src/WallpaperEngine/Render/TextureProvider.h

@@ -33,13 +33,6 @@ public:
     [[nodiscard]] virtual const std::vector<FrameSharedPtr>& getFrames () const = 0;
     [[nodiscard]] virtual const glm::vec4* getResolution () const = 0;
     [[nodiscard]] virtual bool isAnimated () const = 0;
-    /** 0 if not a spritesheet */
-    [[nodiscard]] virtual uint32_t getSpritesheetCols () const = 0;
-    /** 0 if not a spritesheet */
-    [[nodiscard]] virtual uint32_t getSpritesheetRows () const = 0;
-    /** 0 if not a spritesheet */
-    [[nodiscard]] virtual uint32_t getSpritesheetFrames () const = 0;
-    [[nodiscard]] virtual float getSpritesheetDuration () const = 0;
     virtual bool isReady () const = 0;
 
     /** For video CTextures, playback only starts once usage count goes above zero (initializes mpv if needed) */