About Store Forum Documentation Contact
Donations:
309$/mo



Post Reply 
Palette colour
Author Message
mystara Offline
Member

Post: #1
Palette colour
Is there a way to get the specific colour of a particle rendered in palette mode? Obviously particle.color on its own is not sufficient.
04-07-2013 03:05 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: Palette colour
Colors are taken from Renderer.color_palette texture (name is from my head, may be different a bit), this is a 2D texture. You can look it up or change it.
04-08-2013 09:43 AM
Find all posts by this user Quote this message in a reply
mystara Offline
Member

Post: #3
RE: Palette colour
I got that bit smile

But what algorithm is used to determine the exact colour for a particular particle? I guess the particle's lifetime is part of the algorithm? Similarly, I would guess that the particle.color applies too?

Alternatively, can we please have a function to return a specific particle's color?

I want particles to emit a light corresponding with their colour.
04-08-2013 09:48 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
RE: Palette colour
next release will feature following functions:

Code:
// manually calculate color of palette based particle (particles with 'palette' set to true)
Flt   ParticleOpacity(Flt particle_life, Flt particle_life_max, Bool particles_smooth_fade);   // calculate opacity of a single particle by specifying its current life 'Particle.life', maximum life 'Particle.life_max' and if smooth fade 'Particles.smooth_fade' is enabled, this opacity can be used for function below 'ParticleColor'
Color ParticleColor  (Flt particle_opacity, C Color &particles_color, C Image &palette_image); // calculate color   of a single particle by specifying its opacity (can be obtained using 'ParticleOpacity' function), color of particles 'Particles.color' and palette image used by the particles (depending on 'Particles.paletteIndex' it can be 'Renderer.color_palette' or 'Renderer.color_palette1'), this 'ParticleColor' function requires locking for reading the palette image and accessing its pixels, since 'Renderer.color_palette' images are 2D textures, locking them for every function call may not be efficient, it is suggested to copy those images to other image in IMAGE_SOFT mode at application startup, and then pass the software versions of the images to this function (locking and accessing software images has no performance penalty)
04-08-2013 11:12 AM
Find all posts by this user Quote this message in a reply
mystara Offline
Member

Post: #5
RE: Palette colour
Awesome.

Will need to wait for next mac release to use this though smile
04-08-2013 07:31 PM
Find all posts by this user Quote this message in a reply
mystara Offline
Member

Post: #6
RE: Palette colour
I've tried having a go using this function, as shown below:

Code:
if (Renderer.color_palette != NULL)
        {
            Flt opacity = ParticleOpacity(particles.p[i].life, particles.p[i].life_max, 1);
        
            Renderer.color_palette->lock();
            Color colour = ParticleColor(opacity, particles.color, *Renderer.color_palette);
            Renderer.color_palette->unlock();

            LightSqr(opacity, particles.p[i].pos, colour.asVec(), 0).add(false, this);
        }

The code is executing. However, nothing happens.
Opacity and particles.p[i].pos are correct.

However, colour.asVec() is continually (0, 0, 0).

If I remove the lock() and unlock() calls, a light is created, but it's almost entirely white. See the image below.

My guess is that particles.color is being ignored in ParticleColor().


Attached File(s) Image(s)
   
05-12-2013 04:48 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #7
RE: Palette colour
Hello,

please don't call lock/unlock

the functions work ok, see here:
Code:
void Draw()
{
   Renderer(Render);
   D.text(0,0.9,S+"FPS: "+Time.fps());
   SetMatrix();
   if(Kb.shift())
   REPA(particle)
   {
      Particles &ps=particle[i];
      if(ps.renderMode()==RM_PALETTE)REPA(ps)
      {
         Particle &p=ps.p[i];
         p.pos.draw(ParticleColor(ParticleOpacity(p.life, p.life_max, ps.smooth_fade), ps.color, *Renderer.color_palette), 0.02);
      }
   }
}


Attached File(s) Image(s)
   
05-12-2013 04:58 PM
Find all posts by this user Quote this message in a reply
mystara Offline
Member

Post: #8
RE: Palette colour
Hrm, the documentation in the header mentioned that I had to call lock() and unlock()?

Anyhow, I shall give that code a go and see what happens, thanks.
05-12-2013 05:01 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #9
RE: Palette colour
Quote:'ParticleColor' function requires locking for reading the palette image and accessing its pixels
sorry, I'll adjust the comments, it means that it requires locking, however that's performed inside the function.
05-12-2013 05:10 PM
Find all posts by this user Quote this message in a reply
mystara Offline
Member

Post: #10
RE: Palette colour
Cool.

I'm still having some difficulty though. I'm editing the EditObjectParticles function in the editor. Using the code above gives me the following function:

Code:
void EditObjParticles::drawPalette () {
    particles.draw();
    
    if(particles.renderMode()==RM_PALETTE)
        REPA(particles)
        {
            Particle &p=particles.p[i];
            p.pos.draw(ParticleColor(ParticleOpacity(p.life, p.life_max, particles.smooth_fade), particles.color, *Renderer.color_palette), 0.02);
        }
}

And produces the attached image.
The locations of the particles are correct, and the transition appears to occur correctly. However, the colour is still wrong. In particular, the particles start white and change to yellow. I don't believe that any palette does that.

Colour is (137, 0, 0, 0)

I'm at a bit of a loose end here. I have absolutely no idea why it isn't working and I've been fiddling with it for hours :(


Attached File(s) Image(s)
   
(This post was last modified: 05-12-2013 07:19 PM by mystara.)
05-12-2013 07:16 PM
Find all posts by this user Quote this message in a reply
mystara Offline
Member

Post: #11
RE: Palette colour
Okay....

I've tried replacing the code with the code from the Particles tutorial (number 15).
I've also tried replacing *Renderer.color_palette with:

Code:
Image img;
img.Import("Gfx/fx/color palette.gfx");

And using that inside the ParticleColor() function. This produces exactly the same effect as above.

I've tried varying both the ParticleOpacity() and Color values, but I still don't get the right output.

It seems that if the above code is executed inside a drawPalette() function, it produces the above effect. But if the above code is executed inside the Draw() function, it works correctly....?
(This post was last modified: 05-13-2013 10:21 PM by mystara.)
05-13-2013 09:23 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #12
RE: Palette colour
Hello,

Everything what you render inside RM_PALETTE will be adjusted by the color palette automatically.

You should use ParticleColor only if you're rendering outside of RM_PALETTE
05-14-2013 01:44 PM
Find all posts by this user Quote this message in a reply
mystara Offline
Member

Post: #13
RE: Palette colour
So which method of ObjClass should I override, rather than using the Draw() function?
Or do I need to code my Draw() function to specifically call a method inside my extended ObjClass object?

I still haven't really got the hang of the different functions and when they're called :/
05-14-2013 01:51 PM
Find all posts by this user Quote this message in a reply
mystara Offline
Member

Post: #14
RE: Palette colour
Okay,

It turns out that it was working correctly. It's just that the white light produced by a small number of particles was washing out the other coloured particles.
05-15-2013 12:44 PM
Find all posts by this user Quote this message in a reply
Post Reply