Thread: Glow behind items

Page 2 of 4 FirstFirst 1234 LastLast
Results 11 to 20 of 35
  1. #11  
    Respected Member


    George's Avatar
    Join Date
    Mar 2009
    Posts
    7,099
    Thanks given
    2,226
    Thanks received
    3,146
    Rep Power
    5000
    cool as fuck soooic.
    Attached image

    Spoiler for Spoilers!:
    Attached image
    Attached image
    Attached image
    Attached image
    Reply With Quote  
     

  2. Thankful user:


  3. #12  
    Donator

    .css's Avatar
    Join Date
    Dec 2018
    Age
    29
    Posts
    579
    Thanks given
    89
    Thanks received
    270
    Rep Power
    351
    This is pretty sick ngl, useful for things like quests or tutorial systems for a server or something; nice concept!
    Reply With Quote  
     

  4. Thankful user:


  5. #13  
    nice


    Join Date
    Jul 2014
    Posts
    740
    Thanks given
    382
    Thanks received
    562
    Rep Power
    4239
    didn't expect this many comments lol, ty tho
    Attached image
    Reply With Quote  
     

  6. #14  
    Registered Member
    King Zeus's Avatar
    Join Date
    Jan 2018
    Posts
    205
    Thanks given
    40
    Thanks received
    82
    Rep Power
    178
    It seems this has inspired many ideas. Very nice share Suic!
    ---------------------------------------------
    My Contributions:
    [317]
    Run Regeneration
    [OSRS]
    Prifddinas Agility Course
    Priffdinnas NPC Spawns
    ---------------------------------------------
    Reply With Quote  
     

  7. #15  
    Registered Member jdakiller2's Avatar
    Join Date
    Dec 2013
    Posts
    433
    Thanks given
    13
    Thanks received
    7
    Rep Power
    19
    Quote Originally Posted by Suic View Post
    The following method will render circular glow behind an item (there are a few other possibilities which I'll mention below)
    I got the idea to do this from a pk server a while ago (iirc it was spawnpk) which had glow behind certain items(altho im p sure it was just a 'glow sprite' drawn before the item, the method i wrote actually generates the glow programmatically, the color, intensity, radius etc are adjustable)

    Code:
    Code:
        public static void renderGlow(int drawX, int drawY, int glowColor, int r) {
            // center
            drawX += r / 2;
            drawY += r / 2;
            
            int startX = drawX - r;
            int endX = drawX + r;
            int startY = drawY - r;
            int endY = drawY + r;
    
            // clipping
            if (startX < clipLeft) {
                startX = clipLeft;
            }
    
            if (endX > clipRight) {
                endX = clipRight;
            }
    
            if (startY < clipTop) {
                startY = clipTop;
            }
    
            if (endY > clipBottom) {
                endY = clipBottom;
            }
    
            float edge0 = -(r / 2f);
            for (int x = startX; x < endX; x++) {
                for (int y = startY; y < endY; y++) {
                    int index = x + y * width;
                    float d = MathUtils.dist(x, y, drawX, drawY);
                    float dist = MathUtils.smoothstep(edge0, r, d);
                    int oldColor = raster[index];
                    int newColor = blend(oldColor, glowColor, 1f - dist);
                    raster[index] = newColor;
                }
            }
        }
    dist defines the euclidean distance
    smoothstep:
    Code:
        public static float smoothstep(float edge0, float edge1, float x) {
            // Scale, bias and saturate x to 0..1 range
            x = constrain((x - edge0) / (edge1 - edge0), 0.0f, 1.0f);
            // Evaluate polynomial
            return x * x * (3 - 2 * x);
        }
    blend just implements linear interpolation between 2 colors
    Another way to generate glow without using smoothstep would be to use norm(d, 0, r) for dist, altho smoothstep is definitely more flexible

    You can also render glow on top of the item, which would give you a bloomy effect(looks nice in some cases)
    Another way would be to render the item to a seperate buffer, then apply glow to that buffer, render the glow and then render the item on top of it.

    Glow can also be applied to text (you wouldn't apply circular glow tho) instead you would use bloom, which works like this:
    1) Draw text
    2) Blur text
    3) Draw text on top of it

    Perfect gaussian blur (for example) would be very expensive to do on the cpu however you can approximate blur(average error rate per pixel is only 0.04%) in O (linear time)
    Feel free to read more about it here

    Note: if you want this to use the average color of the sprite(excluding transparent pixels) u should either put this in the sprite class and cache the calculated color or take a sprite as param (should also cache the result)
    Average color can be calculated in the following way:
    Code:
        private int averageColor() {
            long redSum = 0;
            long greenSum = 0;
            long blueSum = 0;
            int count = 0;
            for (int x = 0; x < myWidth; x++) {
                for (int y = 0; y < myHeight; y++) {
                    int color = myPixels[x + y * myWidth];
                    if (color == 0) {
                        continue; // 0 is considered transparent
                    }
                    redSum += (color >> 16) & 0xFF;
                    greenSum += (color >> 8) & 0xFF;
                    blueSum += color & 0xFF;
                    count++;
                }
            }
            long r = redSum / count;
            long g = greenSum / count;
            long b = blueSum / count;
            return (int) (r << 16 | g << 8 | b);
        }
    This is also what i did for the examples below

    Pic & Gifs:
    Attached image
    Attached image
    Attached image
    Rendering the glow after the item was rendered with varying intensity for the original(non transparent) pixels of the sprite
    Attached image

    for a radius of 32 (Which is what i used for items in interfaces) it took about 0.025 ms to generate the glow, this can be optimized further but shouldn't really be necessary if you cache the result and only re-generate if needed.

    Note: if ur gonna use a different radius than 32 but always want the glow to be centered around the item and not the glow itself then to center just add 16 instead of r / 2
    Can someone release a tutorial on how to do this?
    Reply With Quote  
     

  8. #16  
    Registered Member
    rebecca's Avatar
    Join Date
    Aug 2017
    Posts
    1,071
    Thanks given
    862
    Thanks received
    915
    Rep Power
    5000
    Quote Originally Posted by jdakiller2 View Post
    Can someone release a tutorial on how to do this?
    this is a tutorial
    Reply With Quote  
     

  9. Thankful user:


  10. #17  
    Registered Member jdakiller2's Avatar
    Join Date
    Dec 2013
    Posts
    433
    Thanks given
    13
    Thanks received
    7
    Rep Power
    19
    Quote Originally Posted by rebecca View Post
    this is a tutorial

    Deff not a tutorial add it with that code and tell me the errors you get thats half the code
    Reply With Quote  
     

  11. #18  
    Registered Member
    rebecca's Avatar
    Join Date
    Aug 2017
    Posts
    1,071
    Thanks given
    862
    Thanks received
    915
    Rep Power
    5000
    Quote Originally Posted by jdakiller2 View Post
    Deff not a tutorial add it with that code and tell me the errors you get thats half the code
    obviously your client is gonna be refactored different........ you want a tutorial on how to refactor your client?
    Reply With Quote  
     

  12. #19  
    Registered Member jdakiller2's Avatar
    Join Date
    Dec 2013
    Posts
    433
    Thanks given
    13
    Thanks received
    7
    Rep Power
    19
    Quote Originally Posted by rebecca View Post
    obviously your client is gonna be refactored different........ you want a tutorial on how to refactor your client?
    Its deff refactored i tried copying from another client but theres is the same code as the one provided :/
    Reply With Quote  
     

  13. #20  
    Registered Member
    rebecca's Avatar
    Join Date
    Aug 2017
    Posts
    1,071
    Thanks given
    862
    Thanks received
    915
    Rep Power
    5000
    Quote Originally Posted by jdakiller2 View Post
    Its deff refactored i tried copying from another client but theres is the same code as the one provided :/
    you don't know what refactored means
    Reply With Quote  
     

  14. Thankful user:


Page 2 of 4 FirstFirst 1234 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Item glow
    By Hiken jr in forum Help
    Replies: 6
    Last Post: 05-29-2013, 10:52 PM
  2. Replies: 3
    Last Post: 09-21-2011, 06:43 PM
  3. All Lists - item, object and NPC
    By purepkownage in forum Tools
    Replies: 2
    Last Post: 05-11-2007, 09:46 AM
  4. [TuT] Adding Personal Glowing to your Server
    By Zamorak Zxt in forum Tutorials
    Replies: 0
    Last Post: 05-10-2007, 05:02 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •