Jump to content

Dissolve Effect / Material Transparency


Phodex Games
 Share

Recommended Posts

Hi,

I wonder how I would achieve a dissolve effect, or simply make an material disappear over time. I want to for smoothly making objects disappear before they get removed. 

I found this, but don't know how to use it: https://www.google.de/search?q=leadwerks+dissolve+shader&rlz=1C1GCEA_enDE754DE754&oq=leadwerks+dissolve+shader&aqs=chrome..69i57j69i60.7455j1j4&sourceid=chrome&ie=UTF-8

I tried to apply the shader to an material and called material:SetColor(1, 1, 1, x-0.05) on update. But nothing seems to happen. Also if I try to decrease the alpha value of an material nothing happens, only if it reaches a value below 0.5 then the model with the material appears. So how to set up an material where I can seamlessly adjust the transparency?

Thanks for your input!

Link to comment
Share on other sites

For a deferred renderer you want to discard one pixel at a time, rather than use transparency. This is what that shader does. Rick and TJHeldna also came up with something for their zombie survival game. (In the new forward renderer, transparency is fine).

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

  • 2 weeks later...

Hey

I test it, it works..Using the animation shader of Shadmar on the crawler material

And added same shader "diffuse+normal+specular+dissolve.shader" on the shadow shader of the material. 

just added this in the UpdatePhysics() of the MonsterAI.lua


local matos=self.entity:GetSurface(0):GetMaterial()
matos:SetColor(1,1,1,matos:GetColor().a-0.001)

For fun I tried this:

matos:SetColor(0,0,0,matos:GetColor().a-0.002)

Here to see:

 

 

  • Like 1
  • Thanks 1

 

 

Link to comment
Share on other sites

  • 1 month later...

Okay, here's how it is done.

First you need a random function. This takes a vec2 input as a seed and returns a pseudorandom number:

float rand(vec2 co)
{
    return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}

Then you just add this at the beginning of the main function of any shader. The input vColor is used to get the alpha value to compare:

//Dissolve effect
float refalpha = rand(gl_FragCoord.xy * float(1+gl_SampleID)) * 0.99;
if (vColor.a <= refalpha) discard;

Including the sample ID makes it a bit less grainy when MSAA is used.

  • Like 1
  • Thanks 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...