Ticket #3233: sprite_with_color_mul.patch

File sprite_with_color_mul.patch, 7.6 KB (added by Vladislav Belov, 9 years ago)

Add to function "AddSprite" color param, which multiply texture value

  • binaries/data/mods/public/shaders/arb/foreground_overlay.fp

     
    11!!ARBfp1.0
    22
    33TEX result.color, fragment.texcoord[0], texture[0], 2D;
     4MUL result.color, colorMul, result.color;
    45
    56END
  • binaries/data/mods/public/shaders/arb/foreground_overlay.xml

     
    33
    44    <vertex file="arb/foreground_overlay.vp">
    55        <stream name="pos"/>
    6     <stream name="uv0"/>
     6        <stream name="uv0"/>
    77    </vertex>
    88
    99    <fragment file="arb/foreground_overlay.fp">
    10     <uniform name="baseTex" loc="0" type="sampler2D"/>
     10        <uniform name="baseTex" loc="0" type="sampler2D"/>
     11        <uniform name="colorMul" loc="0" type="vec4"/>
    1112    </fragment>
    1213
    1314</program>
  • binaries/data/mods/public/shaders/glsl/foreground_overlay.fs

     
    11#version 110
    22
    33uniform sampler2D baseTex;
     4uniform vec4 colorMul;
    45varying vec2 v_tex;
    56
    67void main()
    78{
    8   gl_FragColor = texture2D(baseTex, v_tex);
     9  gl_FragColor = texture2D(baseTex, v_tex) * colorMul;
    910}
  • binaries/data/mods/public/simulation/components/StatusBars.js

     
    119119            icon,
    120120            { "x": xoffset - iconSize/2, "y": yoffset },
    121121            { "x": xoffset + iconSize/2, "y": yoffset + iconSize },
    122             offset
     122            offset,
     123            "255 255 255 255"
    123124        );
    124125        xoffset += iconSize * 1.2;
    125126    }
     
    142143            "art/textures/ui/session/icons/"+type+"_bg.png",
    143144            { "x": -width/2, "y":yoffset },
    144145            { "x": width/2, "y": height + yoffset },
    145             offset
     146            offset,
     147            "255 255 255 255"
    146148        );
    147149
    148150        cmpOverlayRenderer.AddSprite(
     
    149151            "art/textures/ui/session/icons/"+type+"_fg.png",
    150152            { "x": -width/2, "y": yoffset },
    151153            { "x": width*(amount - 0.5), "y": height + yoffset },
    152             offset
     154            offset,
     155            "255 255 255 255"
    153156        );
    154157
    155158        yoffset += height * 1.2;
     
    190193                icon,
    191194                { "x": -rankSize/2 + xoffset, "y": -rankSize/2 + yoffset },
    192195                { "x": rankSize/2 + xoffset, "y": rankSize/2 + yoffset },
    193                 offset
     196                offset,
     197                "255 255 255 255"
    194198            );
    195199        }
    196200    }
  • source/graphics/Overlay.h

     
    1 /* Copyright (C) 2012 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    136136struct SOverlaySprite
    137137{
    138138    CTexturePtr m_Texture;
     139    CColor m_Color;
    139140    CVector3D m_Position; // base position
    140141    float m_X0, m_Y0, m_X1, m_Y1; // billboard corner coordinates, relative to base position
    141142};
  • source/renderer/OverlayRenderer.cpp

     
    1 /* Copyright (C) 2014 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    622622            shader->BindTexture(str_baseTex, sprite->m_Texture);
    623623        else
    624624            sprite->m_Texture->Bind();
     625       
     626        shader->Uniform(str_colorMul, sprite->m_Color);
    625627
    626628        CVector3D pos[4] = {
    627629            sprite->m_Position + right*sprite->m_X0 + up*sprite->m_Y0,
  • source/simulation2/components/CCmpOverlayRenderer.cpp

     
    1 /* Copyright (C) 2012 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    2727#include "graphics/TextureManager.h"
    2828#include "renderer/Renderer.h"
    2929
     30#include "ps/CLogger.h"
     31
    3032class CCmpOverlayRenderer : public ICmpOverlayRenderer
    3133{
    3234public:
     
    112114        UpdateMessageSubscriptions();
    113115    }
    114116
    115     virtual void AddSprite(VfsPath textureName, CFixedVector2D corner0, CFixedVector2D corner1, CFixedVector3D position)
     117    virtual void AddSprite(VfsPath textureName, CFixedVector2D corner0, CFixedVector2D corner1, CFixedVector3D position, std::string color)
    116118    {
     119        CColor colorObj(1.0f, 1.0f, 1.0f, 1.0f);
     120        if (!colorObj.ParseString(color, 1))
     121            LOGERROR("OverlayRenderer: Error parsing '%s'", color);
     122
    117123        CTextureProperties textureProps(textureName);
    118124
    119125        SOverlaySprite sprite;
     
    122128        sprite.m_Y0 = corner0.Y.ToFloat();
    123129        sprite.m_X1 = corner1.X.ToFloat();
    124130        sprite.m_Y1 = corner1.Y.ToFloat();
     131        sprite.m_Color = colorObj;
    125132
    126133        m_Sprites.push_back(sprite);
    127134        m_SpriteOffsets.push_back(CVector3D(position));
  • source/simulation2/components/ICmpOverlayRenderer.cpp

     
    1 /* Copyright (C) 2010 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    2323
    2424BEGIN_INTERFACE_WRAPPER(OverlayRenderer)
    2525DEFINE_INTERFACE_METHOD_0("Reset", void, ICmpOverlayRenderer, Reset)
    26 DEFINE_INTERFACE_METHOD_4("AddSprite", void, ICmpOverlayRenderer, AddSprite, VfsPath, CFixedVector2D, CFixedVector2D, CFixedVector3D)
     26DEFINE_INTERFACE_METHOD_5("AddSprite", void, ICmpOverlayRenderer, AddSprite, VfsPath, CFixedVector2D, CFixedVector2D, CFixedVector3D, std::string)
    2727END_INTERFACE_WRAPPER(OverlayRenderer)
  • source/simulation2/components/ICmpOverlayRenderer.h

     
    1 /* Copyright (C) 2010 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    4848     * @param corner0,corner1 coordinates of sprite's corners, in world-space units oriented with the camera plane,
    4949     *        relative to the sprite position.
    5050     * @param offset world-space offset of sprite position from the entity's base position.
     51     * @param color multiply color of texture
    5152     */
    52     virtual void AddSprite(VfsPath textureName, CFixedVector2D corner0, CFixedVector2D corner1, CFixedVector3D offset) = 0;
     53    virtual void AddSprite(VfsPath textureName, CFixedVector2D corner0, CFixedVector2D corner1, CFixedVector3D offset, std::string color = "255 255 255 255") = 0;
    5354
    5455    DECLARE_INTERFACE_TYPE(OverlayRenderer)
    5556};