Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / [SOLVED] How to fade out texture?

Author
Message
psychoanima
6
Years of Service
User Offline
Joined: 19th Jun 2018
Location:
Posted: 29th Dec 2018 00:55
I have an image/texture for my 3D model that I want to fade gradually after certain actions.

Unfortunately I can see that only SetSpriteColorAlpha can achieve this result. Since I can't use sprite as a texture for my 3D model, how can I achieve this dissolving/fading texture effect? (I hope that answer is not in shaders)

The author of this post has marked a post as an answer.

Go to answer

blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 29th Dec 2018 01:08 Edited at: 29th Dec 2018 01:08
Maybe try setspritecolor over a number of frames going from 255 to 0 (Which would fade it to black)
so something like
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 29th Dec 2018 01:44 Edited at: 29th Dec 2018 01:59
here is 3 methods you may find handy
you may need to add a delay in the first two methods and you willl need to SetObjectTransparency( objID, mode ) beforehand


fubar
Golelorn
8
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 29th Dec 2018 03:03 Edited at: 29th Dec 2018 03:05
I know one way would be to set a shader to do this.

Add a uniform for your start fade out timer.

As the timer comes closer to 100% the color will fade out from one color to another.

Some psuedo-code:


I think the other solutions are better if you just want to make it transparent, though.
psychoanima
6
Years of Service
User Offline
Joined: 19th Jun 2018
Location:
Posted: 29th Dec 2018 09:39 Edited at: 29th Dec 2018 09:40
I should mention that I have 5 textures applied to the model. First one is the main one that is visible all the time, other 4 needs to fade in/fade out at certain point. They are all connected with mix shader.
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 29th Dec 2018 09:47 Edited at: 29th Dec 2018 09:48
you need a shader to fade out individual textures
an example of how it can be done using texture0
is as follows but you should be able to make one
that fades the textures you desire.

fubar
psychoanima
6
Years of Service
User Offline
Joined: 19th Jun 2018
Location:
Posted: 29th Dec 2018 10:26 Edited at: 29th Dec 2018 10:50
Thanks,

huh, I suck so badly with shaders.... so this is shader code I am using and that is working but without fade texture ability.

MIX.ps




MIX.vs



TomToad
6
Years of Service
User Offline
Joined: 6th Jan 2018
Location:
Posted: 29th Dec 2018 13:11
This post has been marked by the post author as the answer.
I'm not at my computer right now, but I'll try and explain what you can change the best I can.

First set up a uniform constant called fade in the pixel shader.
uniform vec4 fade;

Then, in main(), after the vec4 colorResult# = lines, put
colorResult1.a *= fade.x;
colorResult2.a *= fade.y;
colorResult3.a *= fade.z;
colorResult4.a *= fade.w;

Now to set the transparency of the texture, just put this on your AppGameKit code.
SetShadetConstantByName(shader,"fade",x,y,z,w)
Where x,y,z,w are from 0.0 (fully transparent) to 1.0(fully opaque).

Now this only changes textures 1-4, if you also need texture 0 to fade, then you need to set up an extra constant.
puzzler2018
User Banned
Posted: 29th Dec 2018 14:00 Edited at: 29th Dec 2018 14:00
Nice little tricks here, very much suitable for levelup pre-post information screens between each levels - hee hee
psychoanima
6
Years of Service
User Offline
Joined: 19th Jun 2018
Location:
Posted: 29th Dec 2018 14:44
Thanks TomToad, works beautifully!!!


I envy all of you that know how to use shaders ! <3

Login to post a reply

Server time is: 2024-11-23 09:08:34
Your offset time is: 2024-11-23 09:08:34