RenderSetColor tickbox to skip Alpha

If there is something important you think is missing in the current version of ZGameEditor then you can post a feature request here!

Moderator: Moderators

User avatar
rrTea
Posts: 319
Joined: Sat Feb 15, 2014 9:54 am

RenderSetColor tickbox to skip Alpha

Postby rrTea » Fri Oct 10, 2014 3:31 am

It would be very handy to have an option for RenderSetColor not to affect Alpha channel (maybe a tickbox or something simple like that).

Right now I have a few models all using the same Material. The Models should all be of different colors but keep the Alpha from the Material which is changed during runtime (for items that should blink: powerups etc). So as soon as I add a RenderSetColor to the OnRender event, it overwrites the Alpha too, not only the colors.

I am currently solving this by simply adding a

Code: Select all

RenderSetColor.Color.A = Material.Color.A;
after RenderSetColor and before defining which Mesh should be rendered, but it brings in a bit of a "sticky tape" atmosphere...

User avatar
Rado1
Posts: 770
Joined: Wed May 05, 2010 12:16 pm

Postby Rado1 » Fri Oct 10, 2014 6:37 pm

Hi rrTea,

does this example show what you wanted to achieve?
Attachments
example.zgeproj
(1.53 KiB) Downloaded 87 times

User avatar
rrTea
Posts: 319
Joined: Sat Feb 15, 2014 9:54 am

Postby rrTea » Sat Oct 11, 2014 3:17 am

Hi Rado1,

Attached is an example that will hopefully clarify the issue. It's a version of the example you posted.

Please look in the OnUpdate event. As you can see the Alpha is modified, but this has no effect on the original Model. I added a copy of the flower in the middle of the screen just so you can see that the Material is indeed "flashing".

Also in the FlowerModel.OnRender I added a ZExpression with the solution I'm currently using (commented out).

So I did manage to make it work, it's just that I think it'd be much more elegant to have RenderSetColor affect Alpha only optionally. It's more a question of interface / usability suggestion than anything else :)

Edit: Substituted a ZExpression with an AnimatorSimple for easier viewing.
Attachments
blink example2.zgeproj
(2.25 KiB) Downloaded 103 times
Last edited by rrTea on Sat Oct 11, 2014 7:39 am, edited 1 time in total.

User avatar
Rado1
Posts: 770
Joined: Wed May 05, 2010 12:16 pm

Postby Rado1 » Sat Oct 11, 2014 7:39 am

Hi rrTea,

now I see what you wanted to achieve. I think

Code: Select all

FlowerColor.Color.A = FlowerMaterial.Color.A;

solves the situation quite well... maybe it can rather be put to OnUpdate section of the FlowerModel. I agree, if it's possible to modify just RGB and not alpha (or maybe even modify just part of the RGBA independently), the solution would be little bit more robust.
Attachments
blink example3.zgeproj
(2.09 KiB) Downloaded 89 times

User avatar
rrTea
Posts: 319
Joined: Sat Feb 15, 2014 9:54 am

Postby rrTea » Sat Oct 11, 2014 7:54 am

Thanks for taking a look! (I just uploaded a new version with some cosmetic differences but the principle is the same as in the old version.)

Yes maybe putting the code in OnUpdate would be better but regardless it's still something that feels a bit like playing catching up.

I could also use some other solutions to this situation, it's not such a big problem but I'm just trying to say that it'd be more elegant if it could be solved before it even pops up.

User avatar
Kjell
Posts: 1644
Joined: Sat Feb 23, 2008 11:15 pm

Postby Kjell » Sat Oct 11, 2014 1:21 pm

Hi guys,

Another alternative would be the following approach ..

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application">
  <OnLoaded>
    <Repeat Count="32" WhileExp="//">
      <OnIteration>
        <ZExpression Expression="SpawnSprite.Position = vector2(random(0, 8), random(0, 4));"/>
        <SpawnModel Name="SpawnSprite" Model="Sprite" />
      </OnIteration>
    </Repeat>
  </OnLoaded>
  <OnUpdate>
    <ZExpression Expression="SpriteMaterial.Color.A = cos(App.Time) * 0.5 + 0.5;"/>
  </OnUpdate>
  <Content>
    <Model Name="Sprite">
      <Definitions>
        <Variable Name="SpriteColor" Type="7"/>
      </Definitions>
      <OnRender>
        <ZExpression Expression="SpriteMaterial.Color = SpriteColor;"/>
        <UseMaterial Material="SpriteMaterial"/>
        <RenderSprite/>
      </OnRender>
      <OnSpawn>
        <ZExpression Expression="SpriteColor = vector3(rnd(), rnd(), rnd());"/>
      </OnSpawn>
    </Model>
    <Material Name="SpriteMaterial" Blend="1"/>
  </Content>
</ZApplication>

Not particularly elegant as it basically "exploits" the way RenderSetColor is implemented .. but it works ;)

Anyway, keep in mind that the OpenGL API* only has functions that set all 4 color components at once. Although that doesn't mean you can't provide a Alpha checkbox on RenderSetColor and manage it at software level of course.

*Fixed-function at least, but since ZGE supports that as well it's the lowest-common denominator.

K

User avatar
rrTea
Posts: 319
Joined: Sat Feb 15, 2014 9:54 am

Postby rrTea » Sun Oct 12, 2014 6:34 am

This works too, but for comparison

(OnRender):
UseMaterial
SetColor
RenderSprite

(which would be possible if the SetColor had an option to inherit Alpha) to me immediately conveys what it does while variations of

(OnRender):
ZExpression (comment goes here)
UseMaterial
RenderSprite

(from Kjell's example, which is how it's done currently) requires a bit of pointless mental jogging in case somebody looks at it a week after it was set it up ("What was that ZExpression doing? Changing the position of ? ....or... " + then reading the comment... etc).


Return to “Feature requests”

Who is online

Users browsing this forum: No registered users and 1 guest