Nicole Kennedy Design

Ideation, Creation & Everything In Between

Opacity Sequences – Editing Shaders

Basically I have been working on trying to get the Colin depth kit content to fade in and out of the scene so that I can match this timing with the animatic. However As the depth kit shader has no alpha channel and does not support transparency I am not able to edit the opacity up and down at present.

Yesterday Fiona had a suggestion of having an empty game object with a shader that supports transparency and then having the colin depth kit game object as a child of this object much like Maya parenting. I need to test this to see if Unity works in the same way and if the child will take on the properties of the parent.

I tried this test but unfortunately the shader from the parent did not effect the child and Colin remained completely opaque and within sight. I even tried directly applying this new ColinTransparencyTest material to colin and plugging in the PNG sequence (poster frame) into the material but this did not work.

On the note of plugging the poster frame into a different material as a texture was not something I knew I could do. It was originally thought that as this poster frame was made for the depth kit shader that this would be the only shader it would be compatible with but it is useful to know this in case a completely new shader needs to be created.

This slideshow requires JavaScript.

Code extracted from (2013) whydoidoit – http://answers.unity3d.com/questions/523059/fade-out-an-object-with-transparentdiffuse-shader.html (23/03/16)

I have extracted this code from the website above and have made a Javascript script for this function in Unity. Basically this script will fade in and out the colour channel of the game object it is placed on. However when I try to use this script I get the error that the material I am using which is using the depth kit shader has no colour property.

function Update()

{

if(Input.GetKeyDown(KeyCode.F))

{

Fade(2,0.0);

}

if(Input.GetKeyDown(KeyCode.G))

{

Fade(2,1.0);

}

}

  1. function Fade(time: float, targetAlpha: float)
  2. {
  3. var t = 0.0;
  4. var currentAlpha = renderer.material.color.a;
  5. while(t <= 1)
  6. {
  7. renderer.material.color.a = Mathf.Lerp(currentAlpha, targetAlpha, t);
  8. t += Time.deltaTime/time;
  9. yield;
  10. }
  11. renderer.material.color.a = targetAlpha;
  12. }

I am looking further into how shaders are made for unity so that I might better understand how to edit the depth kit shader that we have. My research has led to towards the definition of surface shaders and what they are used for as well as examples that I may reference from. However I am finding that the complexity of James script and the majority of the content is related to the media it is dealing with and I’m not 100% what Im allowed to edit so its a matter of trying things and breaking it to find out that change was not correct.

http://docs.unity3d.com/Manual/SL-SurfaceShaders.html (23/03/16)

http://docs.unity3d.com/Manual/SL-SurfaceShaderExamples.html (23/03/16)

Digging deeper into research I need to know how people are adding these alpha properties into their shaders so I have been looking for an answer to this so that I may experiment with the properties of the shader.

http://forum.unity3d.com/threads/self-illumin-shader-with-alpha-property.85457/#post-550113 (23/03/16)

Basically I am combining the following script with James Depth kit shader script to see what properties I can add and remove in order for our script to have an alpha that supports transparency.

Code extracted from –  (2012) Ravsters,  http://answers.unity3d.com/questions/355414/how-to-add-transparency-to-a-shader.html (23/03/16)

Shader "Planet" {

Properties {

_MainTex ("Diffuse(RGB) Spec(A)", 2D) = "white" {}

_BumpMap ("Bumpmap", 2D) = "bump" {}

_RimColor ("Rim Color", Color) = (0.26,0.19,0.16,0.0)

_RimPower ("Rim Power", Range(0.5,8.0)) = 3.0

_SpecColor ("Specular Color", Color) = (0.5,0.5,0.5,1)

_Shininess ("Shininess", Range (0.01, 1)) = 0.078125

}

SubShader {

Tags { "RenderType" = "Transparent" }

CGPROGRAM

  1. #pragma surface surf SimpleSpecular alpha
  2. float _Shininess;
  3. half4 LightingSimpleSpecular (SurfaceOutput s, half3 lightDir, half3 viewDir, half atten) {
  4. half3 h = normalize (lightDir + viewDir);
  5. half diff = max (0, dot (s.Normal, lightDir));
  6. float nh = max (0, dot (s.Normal, h));
  7. float spec = pow (nh, 48.0);
  8. half4 c;
  9. c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * spec * s.Alpha * _Shininess * _SpecColor) * (atten * 2);
  10. c.a = s.Alpha;
  11. return c;
  12. }
  13. struct Input {
  14. float2 uv_MainTex;
  15. float2 uv_BumpMap;
  16. float3 viewDir;
  17. };
  18. sampler2D _MainTex;
  19. sampler2D _BumpMap;
  20. float4 _RimColor;
  21. float _RimPower;
  22. void surf (Input IN, inout SurfaceOutput o) {
  23. fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
  24. o.Albedo = c.rgb;
  25. o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));
  26. half rim = 1.0 - saturate(dot (normalize(IN.viewDir), o.Normal));
  27. o.Emission = _RimColor.rgb * pow (rim, _RimPower);
  28. o.Alpha = c.a;
  29. }
  30. ENDCG
  31. }
  32. Fallback "Diffuse"
  33. }

I have been successful in adding an alpha property into the shader that James has provided us however when I drag the alpha to zero there is no effect on the opacity of the gameobject which in this case is Colin.

Further experimentation led to adding shininess and specular color properties to the shader but these were also having no effect on the game object which has this material attached to it. Within this material the connection to the shader is made.

This slideshow requires JavaScript.

In the image below are some examples of the code that I have edited in order to make some of these changes to add to the properties of a shader.

This slideshow requires JavaScript.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Information

This entry was posted on March 23, 2016 by in Final Year - Major Project and tagged .
%d bloggers like this: