Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Microbes / Bacteria Shader?

Discussion in 'Shaders' started by ArmsFrost, Apr 20, 2014.

  1. ArmsFrost

    ArmsFrost

    Joined:
    Jul 26, 2012
    Posts:
    35
    Hi, I am still trying to figure out an artistic style for this, but looking at some screenshots..

    $bacterium.jpg
    $bacteria-energy-producers-future-1334920925.jpg


    Does anyone know of any shaders in the marketplace that could produce this kind of effect?
    or have any nice ideas for microbes / bacteria.

    I am still not sure a realistic approach is best, but its for an evolution simulator / game.
    I have had a play around with a subsurface scattering shader but so far have't been able to get the result I wanted.
    The base mesh for the microbes is just a sphere or capsule.

    This is what they currently look like, without a background...
    I already have depth of field on, not that you can tell from that screenshot.


    $microbes.png

    Any help, ideas or direction pointers would be appreciated.
     
  2. Hjeldnes

    Hjeldnes

    Joined:
    Jul 22, 2012
    Posts:
    116
    A look like that should be fairly easy to create with a fresnel rimlight shader, and some image filters like bloom and dof.
    Do a search on assetstore after rimlight/fresnel and you should be able to find something. Maybe also on the unity wiki, its a pretty easy shader to make.
     
  3. Hjeldnes

    Hjeldnes

    Joined:
    Jul 22, 2012
    Posts:
    116
    Ok, i just made something quick for you. I think you should be able to replicate the look in that reference you posted.

    Here's the shader, it is a bit more costly than it has to be. It has a fresnelmodified cubemap, if you want to test that instead of just using the basic rim color. Or you can combine both. Set color to Reflection to black if you dont want to use it.

    You need a normalmap for the bumpiness, and I would suggest adding some more detail to the meshes as well, not just having them as spheres.

    Code (csharp):
    1. Shader "Blink Studios/Microbe" {
    2. Properties
    3. {
    4.     _MainTex ("Base (RGB) RefStrGloss (A)", 2D) = "white" {}
    5.     _Color ("Main Color", Color) = (1,1,1,1)
    6.     _SpecColor ("Specular Color", Color) = (0.5,0.5,0.5,1)
    7.     _Shininess ("Shininess", Range (0.01, 1)) = 0.078125
    8.     _ReflectColor ("Reflection Color", Color) = (1,1,1,0.5)
    9.     _FresnelColor ("Fresnel Color", Color) = (1,1,1,0.5)
    10.     _Fresnel("Fresnel Exponent",Range(0.001,16)) = 1
    11.     _Cube ("Reflection Cubemap", Cube) = "" { TexGen CubeReflect }
    12.     _BumpMap ("Normalmap", 2D) = "bump" {}
    13.     _Boost("Fresnel Boost", Float) = 1
    14.    
    15. }
    16.  
    17. SubShader {
    18.     Tags { "RenderType"="Opaque" }
    19.     LOD 400
    20. CGPROGRAM
    21. #pragma surface surf BlinnPhong
    22. #pragma target 3.0
    23.  
    24. sampler2D _MainTex;
    25. sampler2D _BumpMap;
    26. samplerCUBE _Cube;
    27.  
    28.  
    29. fixed4 _Color;
    30. fixed4 _ReflectColor;
    31. half _Shininess;
    32. half _Fresnel;
    33. half _Boost;
    34. fixed4 _FresnelColor;
    35.  
    36. struct Input {
    37.     float2 uv_MainTex;
    38.     float2 uv_BumpMap;
    39.     float3 worldRefl;
    40.     float3 viewDir;
    41.     INTERNAL_DATA
    42. };
    43.  
    44. inline float Schlick2(float Rzero,float3 lightDir,float3 normal,float exponent)
    45. {
    46.     return Rzero + (1 - Rzero) * pow((1 - dot(lightDir,normal)), exponent);
    47. }
    48.  
    49. void surf (Input IN, inout SurfaceOutput o) {
    50.     fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
    51.     fixed4 c = tex * _Color;
    52.     o.Albedo = c.rgb;
    53.     o.Gloss = tex.a;
    54.     o.Specular = _Shininess;
    55.     o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
    56.    
    57.     half3 worldRefl = WorldReflectionVector (IN, o.Normal);
    58.     fixed4 reflcol = texCUBE (_Cube, worldRefl);
    59.     reflcol *= tex.a;
    60.     half fresnel = Schlick2(0,normalize(IN.viewDir),o.Normal,_Fresnel);
    61.     reflcol *= fresnel;
    62.     o.Emission = reflcol.rgb * _ReflectColor.rgb;
    63.     o.Emission +=fresnel * _Boost * _FresnelColor;
    64. }
    65. ENDCG
    66. }
    67.  
    68. FallBack "Reflective/Bumped Diffuse"
    69. }


    Here's a superquick test, but as I mentioned, with proper models textures, and maybe a blurry noisy green cubemap for the background you should get something that looks like your reference picture.

    I used bloom and dof, and a single directional light.

    $Screen Shot 2014-04-21 at 11.04.35.png


    ------
    Kjetil Hjeldnes
    TD
    www.blinkstudios.com
     
    Last edited: Apr 21, 2014
    ekuNNN likes this.
  4. shaderop

    shaderop

    Joined:
    Nov 24, 2010
    Posts:
    942
  5. ArmsFrost

    ArmsFrost

    Joined:
    Jul 26, 2012
    Posts:
    35
    Oh Wow that looks great, thank you, I will have to play around with this tonight.
    Yes one of the things I am working on is a really basic procedurally generated mesh that will be driven from the "DNA" code to change the shape, I did think about soft-body physics but that really limits the number of these I can simulate.
     
    Last edited: Apr 22, 2014
  6. Abnonymous

    Abnonymous

    Joined:
    Jul 19, 2016
    Posts:
    2
    Hi, I'm on a similar project, just want to ask if how do you make the environment?