- Home /
dissolving shader help
OK I'm trying to create a cool death effect for my "Alien Zombie". I'm using the Dissolve shader from the Wiki:
// simple "dissolving" shader by genericuser (radware.wordpress.com)
// clips materials, using an image as guidance.
// use clouds or random noise as the slice guide for best results.
Shader "Custom Shaders/Dissolving" {
Properties {
_MainTex ("Texture (RGB)", 2D) = "white" {}
_SliceGuide ("Slice Guide (RGB)", 2D) = "white" {}
_SliceAmount ("Slice Amount", Range(0.0, 1.0)) = 0.5
}
SubShader {
Tags { "RenderType" = "Opaque" }
Cull Off
CGPROGRAM
//if you're not planning on using shadows, remove "addshadow" for better performance
#pragma surface surf Lambert addshadow
struct Input {
float2 uv_MainTex;
float2 uv_SliceGuide;
float _SliceAmount;
};
sampler2D _MainTex;
sampler2D _SliceGuide;
float _SliceAmount;
void surf (Input IN, inout SurfaceOutput o) {
clip(tex2D (_SliceGuide, IN.uv_SliceGuide).rgb - _SliceAmount);
o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
}
ENDCG
}
Fallback "Diffuse"
}
I have it as a material on my "Alien Zombie" dead replacement... but it dissolves too quickly! Is there a way to slow the dissolve and delay it so it only dissolves a certain amount of time after the body has dropped to the ground?
And secondly how can I make it look sort of like the old TV series "The Invaders" when those alien died? And then destroy my dead alien body a short time after that?
I think on the destroy my dead alien I can just use a wait for seconds, but the rest I've got no clue how to do... has anyone done a cool effect like this and if so how did you do it?
EDIT here is where I keep trying to make my adjustment to slow the effect down but nothing happens?
Shader "Custom Shaders/Dissolving" {
Properties {
_MainTex ("Texture (RGB)", 2D) = "white" {}
_SliceGuide ("Slice Guide (RGB)", 2D) = "white" {}
_SliceAmount ("Slice Amount", Range(0.0, 1.0)) = 0.5
}
There is clearly some part to this I'm missing... Is there not a DETAILED tutorial on this stuff anywhere??
EDIT 03
I see sort of where I'm going wrong. I added a new script to my "Dead Replacement Alien Zombie":
function Start () { // Use the Glossy shader on the material renderer.material.shader = Shader.Find(" ZombieAlienDissolveMaterial"); }
function Update () { // Dissolve renderer.material.SetFloat( "_SliceAmount", 0.5 + Mathf.Sin(Time.time)*12 ); yield WaitForSeconds(12); Destroy(gameObject);
}
But it STILL is doing Jack!?!
EDIT 04
Ok let's try again... I'm trying this and it's STILL NOT WORKING!!
function Start () { // Use the Glossy shader on the material renderer.material.shader = Shader.Find(" ZombieAlienDissolveMaterial"); }
function Update () { // Dissolve renderer.material.SetFloat( "_SliceAmount", 0.0 + Mathf.Sin(Time.time)*1 );
}
function KillSelf () { yield WaitForSeconds(12); Destroy(gameObject);
}
Like I say is there not a DETAILED tutorial on this anywhere, something step by step!
EDIT 05
I set up a new Zombie Alien Ragdoll prefab and gave it this script:
function Start () { // Use the Glossy shader on the material renderer.material.shader = Shader.Find("ZombieAlienDissolveMaterial"); }
function Update () { // Dissolve renderer.material.SetFloat( "_SliceAmount", 0.9 + Mathf.Sin(Time.time)*1 );
}
The Dissolve shader is attached to the "Body" of my Ragdoll (dead replacement) What hapens when I shoot my Alien Zombie is that his dead replacement shows up Bright Pink and the Dissolve material is NOT working.
I conducted a test where I just dragged into my scene a ragdoll with the Dissolve shader and the above attached script and when I play the game (test) in the inspector I can select my custom Dissolve Shader and it works, it dissolves in and out, I only want it to dissolve out but it also says it's a "Shader Instance??"
How do I fix this so that when I shoot my alien Zombies they're Dead Replacements/ragdolls Dissolve out?
-
$$anonymous$$athf.Sin(Time.time)*12 <-- This will produce values in the range -11.5 to 12.5.. you want 0 to 1.
Also, you don't want to set the value once, wait 12 seconds, and then destroy the object. You won't see anything change that way. Why on Earth would you use 'yield' here?
From the docs "Note that you can't use yield from within Update"
http://unity3d.com/support/documentation/ScriptReference/index.Coroutines_26_Yield.html
I'm trying to use Yield because after it's done desolving I naturally want to remove my dead alien zombie from the scene. So how do I do that with what I have here?
Shader.Find(" ZombieAlienDissolve$$anonymous$$aterial"); The leading space before "Zombie" might be an issue. If the compiler complaining? Are you getting any error messages? Have you chosen a good _SliceGuide?
Your yield+Destroy would make more sense it it was at the end of your Start function.
Answer by flaviusxvii · Apr 26, 2011 at 02:25 PM
You control the rate of Di*ss*olve with the _SliceAmount parameter in the shader. Slow that down and you'll slow the effect.
http://unity3d.com/support/documentation/ScriptReference/Material.SetFloat.html
You've been setting a hard-coded value in your shader that gets compiled in and never changes.
You'll need to do something LIKE: renderer.material.SetFloat( "_SliceAmount", amount );
I tried adjusting those numbers and it just starts the material off at whatever those setting are, there does NOT seem to be a nice slow disolve effect???
_SliceAmount must CHANGE OVER TI$$anonymous$$$$anonymous$$ Over the course of N seconds it should traverse a series of values to render the object increasingly more dissolved.
And since my hint was too subtle. Dissolve is spelled with two 's'sss. DisSolve.
Thanks for the grammer lesson but I'm clearly missing something else because it's still not working no matter how much I adjust that slider or change the values in the shader intself!?!
Post the snipped of code where you adjust the _SliceAmount.
Answer by Rispat-Momit · Dec 03, 2020 at 08:06 PM
Hi mate!
I got into the same trouble. The solution is even more simple. Here is an example code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DissolveMyMaterial: MonoBehaviour {
public bool Disolve;
public Renderer MyRend;
void Start(){
MyRend.material.shader = Shader.Find ("MyShader");
}
void Update(){
if (Disolve == true) {
DisolveSpeed += 1f*Time.deltaTime;
MyRend.material.SetFloat("_Dis", DisolveSpeed);
}
}
}
Your answer
Follow this Question
Related Questions
Cooldown effect in GUI 0 Answers
Tracing in Unity3D 2 Answers
How to blend colors from two texture maps in VFX graph 1 Answer
How to achieve Assasins Creed fragmented shader effect? 0 Answers
A brush stroke shader 0 Answers