Search Unity

SEGI (Fully Dynamic Global Illumination)

Discussion in 'Assets and Asset Store' started by sonicether, Jun 10, 2016.

  1. Lex4art

    Lex4art

    Joined:
    Nov 17, 2012
    Posts:
    445
    Oh, good find - got this problem too but did not find cause ...
     
    RB_lashman and punk like this.
  2. rainisto

    rainisto

    Joined:
    Jul 19, 2015
    Posts:
    35
    Thanks for the help. For a fresh scene yes it works, for the low poly demo scene. I guess it had to do with my Uber shaders I was using in that scene - something in those didn't play nicely with SEGI.

    Still @sonicether for maximum VR compatibility it would be great if you could see if there's a way to make it work when there's two VR camera gameobjects, one for camera eye left and one for camera eye right. There's a number of rather important use cases where one unfortunately needs to do that to get some stuff working.

    (Plus it would make something like the rather nifty CTAA plugin work - now with SEGI if there's some very thin lines the aliasing effects are pretty bad looking right now...)
     
    RB_lashman and SteveB like this.
  3. sonicether

    sonicether

    Joined:
    Jan 12, 2013
    Posts:
    265
    There's a simple fix for that. Assign a unique layer to your particle effects (like "Billboard Particles"). Then, omit this layer from the GI Culling Mask, ensuring that any objects in this layer don't get voxelized.

    I'll make sure I include this in the User Guide when I next update it.
     
    ZJP, amasinton, Lex4art and 3 others like this.
  4. punk

    punk

    Joined:
    Jun 28, 2013
    Posts:
    408
    sorted, can't believe I didn't think of that ;)
     
    RB_lashman likes this.
  5. ksam2

    ksam2

    Joined:
    Apr 28, 2012
    Posts:
    1,079
    How you make your models low poly? I have a big town how can I use this method?
     
    RB_lashman likes this.
  6. Shinyclef

    Shinyclef

    Joined:
    Nov 20, 2013
    Posts:
    505
    @sonicether Hello. For the last couple of weeks of been reworking my mesh generation and shader to prepare for segi. I will become a customer soon! Before I do, another question if I may.

    If I can cast shadows I'm good? Does segi use other parts of the mesh (eg uvs) to work (eg for determining light bounce colour). If I have 'standard' verts, tris and normals am I good to go, or does segi care about any of the other vertex data points?

    Thanks :)
     
    RB_lashman likes this.
  7. sonicether

    sonicether

    Joined:
    Jan 12, 2013
    Posts:
    265
    Yep, if unity's default shadows can cast fine with your geometry, that means that it persists enough to be accessible in other rendering passes (voxelization). SEGI uses the base material color and base color texture with UVs to determine the color of the voxels. You don't need to do anything special to your geometry for SEGI to be able to voxelize it and pick up on these things.
     
    Baldinoboy, Shinyclef and RB_lashman like this.
  8. Shinyclef

    Shinyclef

    Joined:
    Nov 20, 2013
    Posts:
    505
    Ah I see. Unfortunately this means my non-standard use of UVs might mess up the colours segi sees... I think I can fix this by storing standard UVs in the UV1 channel and finding another place for my unusual UV data.

    Thanks for the info. I think this is enough to get started on integrating segi with my game. I'm looking forward to contributing screenshots :).
     
    RB_lashman likes this.
  9. scheichs

    scheichs

    Joined:
    Sep 7, 2013
    Posts:
    77
    SEGI on PS4 standard (with slightly modified shaders). No lightmaps, reflection probes, image effects. Just SEGI (reflections on, high preset) with a directional light. Runs with 17 FPS.
    192.168.0.103-20170118-0045.png
    and same scene with SEGI turned off
    192.168.0.103-20170118-0046.png
     
    Last edited: Jan 18, 2017
  10. SteveB

    SteveB

    Joined:
    Jan 17, 2009
    Posts:
    1,451
    @scheichs is every object in your scene voxelized(contributing to GI)? It appears so but just to make certain...

    That sounds slow to me for that scene, so with a bit more info maybe we can get that speed up.

    Also as a general note for people looking for performance help, it might not be the worst thing in the world to also upload a screenshot of the voxels and of course the SEGI parameters you have.

    Cheers
     
    ftejada and RB_lashman like this.
  11. scheichs

    scheichs

    Joined:
    Sep 7, 2013
    Posts:
    77
    @SteveB: The main reason to post the screenshot was that I got SEGI modified to run on PS4. In order to make some speed tests I just took an Asset that I bought some time ago, removed all lightmaps and everything else precalculated, attached SEGI to the main camera, added a blocker at the ceiling and let the magic happen. For sure one could optimize it even further but since it's not part of my current project I didn't want to dig to deep into the whole thing. I just thought that the screen is a nice addition to the SEGI gallery and that SEGI runs on PS4.
     
    Martin_H, RB_lashman and SteveB like this.
  12. SteveB

    SteveB

    Joined:
    Jan 17, 2009
    Posts:
    1,451
    Oh I gotcha okay, I misunderstood! :D
     
    RB_lashman and scheichs like this.
  13. Shinyclef

    Shinyclef

    Joined:
    Nov 20, 2013
    Posts:
    505
    Hello,

    So I finally finished re-writing my code and shader. It's now a deferred shader, writing to the G-Buffer. It seems to be working except one little thing...

    Specular highlights do not align with the light direction.
    When using SEGI, a similar problem exists when using emissive materials. The reflections are just, well, the wrong way!

    Here's an example of what I'm talking about.

    Reflections Bug.jpg

    Notice how the relection is not positioned underneath the object as you would expect, but it goes off to the side.
    The same behaviour is happening with the directional light and specular highlights.

    At first I thought it must be the world normals that are written into the g-buffer, but I had a look at them by outputting them to the diffuse buffer and they looked correct...

    It seems the relationship between the object and the camera is not correct or something.
    Can anyone help me troubleshoot? I'm not sure what to check next, but am pretty sure it's shader related due to the fact that the spec highlights don't work property when segi is turned off as well...
     
    RB_lashman likes this.
  14. scheichs

    scheichs

    Joined:
    Sep 7, 2013
    Posts:
    77
    Looks like tangents are not set up correctly... just guessing.
     
    RB_lashman likes this.
  15. Shinyclef

    Shinyclef

    Joined:
    Nov 20, 2013
    Posts:
    505
    I must be misunderstanding how deferred rendering works still...

    I was under the impression that the lighting calculations only rely on what's in the g-buffer... Indeed I haven't actually set tangents on the mesh, but even if I did, tangents don't end up in the g-buffer. At what stage are they referenced and how?

    I hope you're right though cause that's something I can fix!
     
    RB_lashman likes this.
  16. scheichs

    scheichs

    Joined:
    Sep 7, 2013
    Posts:
    77
    To be honest I don't actually know right now in-depth how deferred shading pipeline works. Maybe my guess was not correct. It just reminded me of a problem I had in the past that was solved by setting mesh tangents.
     
    RB_lashman likes this.
  17. cerrec

    cerrec

    Joined:
    Jan 19, 2017
    Posts:
    41
    How do you do anti-aliasing when using SEGI? I'm new to Unity and would appreciate any help.
     
    Last edited: Jan 19, 2017
    RB_lashman likes this.
  18. sonicether

    sonicether

    Joined:
    Jan 12, 2013
    Posts:
    265
    This looks like a problem with your normals. Normals in the gbuffer need to be in world-space, are your normals in world-space? Do your normals look correct for diffuse lighting (like with a directional light or point light)?

    Also, are you using a tangent-binormal-normal (tbn) matrix to apply your normal maps? Does this wrong behavior stop when you don't use normal maps? This is where you'll need tangent vertex data (you can calculate the binormal by doing a cross multiplication of normal and tangent). Let me know if you need an example of constructing a tbn matrix and using it to transform your normal maps from tangent space to world space.

    You also might want to try inverting the z component in your normals. I know Unity's normals used to demand this.

    The reason I think it's a problem with the normals is that SEGI calculates a reflection vector using the gbuffer normals. That really seems to be the only possibility for why the reflection vector is off.

    You can use any anti-aliasing post effect with SEGI (make sure to have it below SEGI on the camera).
     
    Shinyclef and RB_lashman like this.
  19. Shinyclef

    Shinyclef

    Joined:
    Nov 20, 2013
    Posts:
    505
    Thanks for your reply.
    What you said makes sense, so I went hard at investigating my normals.
    I ended up creating a ForwardBase pass and a Deferred pass of my shader to compare the two.
    The results are hard to interpret!

    I started by comparing the normals of forward (left) vs deferred (right).
    World Normals Forward.jpg World Normals Deferred.jpg
    They all appear to be in world space and the output is identical.
    You can tell the right is deferred because of the much reduced framerate.

    I then compared the final results, again forward (left) and deferred (right).
    Final Forward.jpg Final Deferred 1.jpg
    This is what is so interesting. My relationship with the light source (represented by the flashlight) is completely different!

    Then I rotated the light source.
    Final Deferred 2.jpg
    Definitely a weird relationship with the light.

    SEGI was turned off the whole time.

    My shader code is as follows.
    Code (CSharp):
    1. Shader "Custom/PlxsysVoxel"
    2. {
    3.     Properties
    4.     {
    5.         _MainTex ("Texture Image", 2D) = "white" {}
    6.         _MainTex2 ("Texture Image 2", 2D) = "white" {}
    7.         _Size ("Size", float) = 1
    8.         [PerRendererData]_Scale ("Scale", float) = 1
    9.     }
    10.  
    11.     SubShader
    12.     {
    13.         Pass
    14.         {
    15.             Tags {"LightMode" = "Deferred" "Queue" = "Geometry" "RenderType" = "Opaque" }
    16.      
    17.             CGPROGRAM
    18.                 #pragma target 3.0
    19.                 #pragma vertex Vert
    20.                 #pragma fragment Frag
    21.                 #include "UnityCG.cginc"
    22.  
    23.                 // --------- //
    24.                 // Variables //
    25.                 // --------- //
    26.                 uniform float _Size;
    27.                 uniform float _Scale;
    28.                 uniform float4x4 _VP;
    29.                 uniform sampler2D _MainTex;
    30.                 uniform sampler2D _MainTex2;
    31.  
    32.                 // unity variables
    33.                 uniform half4 _LightColor0;
    34.  
    35.  
    36.                 /* --------------- */
    37.                 /* Data structures */
    38.                 /* --------------- */
    39.                 struct VSData
    40.                 {
    41.                     half4 Pos            : POSITION;
    42.                     half4 UV            : TEXCOORD0; // uv1 start xy (packed), uv1 Size xy (packed), uv2 start xy (packed), uv2 Size xy (packed)
    43.                     half4 LenOrCorner    : TEXCOORD1; // Len: face tile length x/y
    44.                                                      // Corner: a value from 0,0 to 1,1 to indicate which corner of the tile the vertex is in. Will be lerped.
    45.                     float3 Normal    : NORMAL;     // normal
    46.                     float4 Tangent    : TANGENT;     // tangent/right
    47.  
    48.                     //half4 Empty    : TEXCOORD2; // AVAILABLE
    49.                     //half4 Empty    : TEXCOORD3; // AVAILABLE
    50.                     //float4 Empty    : COLOR;     // AVAILABLE
    51.                 };
    52.  
    53.                 struct FSData
    54.                 {
    55.                     half4 Pos            : POSITION;
    56.                     half4 UV1            : TEXCOORD0; // uv1 start.xy + uv1 size.xy
    57.                     half4 UV2            : TEXCOORD1; // uv2 start.xy + uv2 size.xy
    58.                     half4 LenOrCorner    : TEXCOORD2; // blocks len + Corner
    59.                     half3 TangentWorld    : TEXCOORD4;
    60.                     half3 NormalWorld    : TEXCOORD5;
    61.                     half3 BinormalWorld : TEXCOORD6;
    62.                 };
    63.  
    64.                 // ------------- //
    65.                 // Vertex Shader //
    66.                 // ------------- //
    67.                 FSData Vert(VSData v)
    68.                 {
    69.                     FSData o;
    70.                     o.Pos = mul(UNITY_MATRIX_VP, mul(unity_ObjectToWorld, v.Pos));
    71.  
    72.                     // unpack UVs
    73.                     o.UV1 = half4(floor(v.UV.x / 4096), fmod(v.UV.x, 4096),
    74.                         floor(v.UV.y / 4096), fmod(v.UV.y, 4096)) / 4095;
    75.                     o.UV2 = half4(floor(v.UV.z / 4096), fmod(v.UV.z, 4096),
    76.                         floor(v.UV.w / 4096), fmod(v.UV.w, 4096)) / 4095;
    77.  
    78.                     o.LenOrCorner = v.LenOrCorner;
    79.                     o.NormalWorld = normalize(mul(unity_ObjectToWorld, v.Normal));
    80.                     o.TangentWorld = normalize(mul(unity_ObjectToWorld, v.Tangent.xyz));
    81.                     //o.TangentWorld = v.Tangent;
    82.                     o.BinormalWorld = normalize(cross(o.TangentWorld, o.NormalWorld));
    83.                     return o;
    84.                 }
    85.  
    86.                 // --------------- //
    87.                 // Fragment Shader //
    88.                 // --------------- //
    89.                 void Frag(
    90.                     FSData i,
    91.                     out half4 outDiffuse : SV_Target0,       // RT0: diffuse color (rgb), occlusion (a)
    92.                     out half4 outSpecRoughness : SV_Target1, // RT1: spec color (rgb), roughness (a)
    93.                     out half4 outNormal : SV_Target2,        // RT2: world normal (rgb), --unused, very low precision-- (a)
    94.                     out half4 outEmission : SV_Target3       // RT3: emission (rgb), --unused-- (a)
    95.                 )
    96.                 {
    97.                     //                start   +      pos(0-1) %       1 / blocksLen        * blocksLen       * size
    98.                     half2 uv1 = half2(i.UV1.x + fmod(i.LenOrCorner.z, 1 / i.LenOrCorner.x) * i.LenOrCorner.x * i.UV1.z,
    99.                                       i.UV1.y + fmod(i.LenOrCorner.w, 1 / i.LenOrCorner.y) * i.LenOrCorner.y * i.UV1.w);
    100.  
    101.                     //                 pos(0-1)        * blocksLen       * size
    102.                     half2 uv1d = half2(i.LenOrCorner.z * i.LenOrCorner.x * i.UV1.z,
    103.                                        i.LenOrCorner.w * i.LenOrCorner.y * i.UV1.w);
    104.  
    105.  
    106.                     //                start   +      pos(0-1) %       1 / blocksLen        * blocksLen       * size
    107.                     half2 uv2 = half2(i.UV2.x + fmod(i.LenOrCorner.z, 1 / i.LenOrCorner.x) * i.LenOrCorner.x * i.UV2.z,
    108.                                       i.UV2.y + fmod(i.LenOrCorner.w, 1 / i.LenOrCorner.y) * i.LenOrCorner.y * i.UV2.w);
    109.  
    110.                     //                 pos(0-1)        * blocksLen       * size
    111.                     half2 uv2d = half2(i.LenOrCorner.z * i.LenOrCorner.x * i.UV2.z,
    112.                                        i.LenOrCorner.w * i.LenOrCorner.y * i.UV2.w);
    113.  
    114.                     // texture2 - normal (rg) and specular maps (a)
    115.                     half4 tex2 = tex2D(_MainTex2, uv2, ddx(uv2d), ddy(uv2d));
    116.                     half specStrength = tex2.a * 5;
    117.                     half3 localNorm = float3(tex2.rg * 2 - 1, 0.0);
    118.                     localNorm.z = 1.0 - 0.5 * dot(localNorm, localNorm);
    119.  
    120.                     // normal transpose matrix
    121.                     half3x3 local2WorldTranspose = float3x3(i.TangentWorld, i.BinormalWorld, i.NormalWorld);
    122.  
    123.                     // lighting
    124.                     half3 normalDirection = normalize(mul(localNorm, local2WorldTranspose));
    125.                     outDiffuse.rgb = tex2D(_MainTex, uv1, ddx(uv1d), ddy(uv1d));
    126.                     outSpecRoughness = half4(specStrength, specStrength, specStrength, 0.8);
    127.                     outNormal.rgb = normalDirection;
    128.  
    129.                     //outNormal.rgb = i.NormalWorld; // TEST
    130.                     //outEmission.rgb = outDiffuse.rgb; // TEST
    131.                     //outEmission.rgb = outNormal.rgb; // TEST
    132.                     //outEmission.rgb = i.NormalWorld.rgb; // TEST
    133.                 }
    134.  
    135.             ENDCG
    136.         }
    137.  
    138.      
    139.         Pass
    140.         {
    141.             Tags{ "LightMode" = "ForwardBase" "Queue" = "Geometry" "RenderType" = "Opaque" }
    142.  
    143.             CGPROGRAM
    144.             #pragma target 3.0
    145.             #pragma vertex Vert
    146.             #pragma fragment Frag
    147.             #include "UnityCG.cginc"
    148.  
    149.             // --------- //
    150.             // Variables //
    151.             // --------- //
    152.             uniform float _Size;
    153.             uniform float _Scale;
    154.             uniform float4x4 _VP;
    155.             uniform sampler2D _MainTex;
    156.             uniform sampler2D _MainTex2;
    157.  
    158.             // unity variables
    159.             uniform half4 _LightColor0;
    160.  
    161.  
    162.             // --------------- //
    163.             // Data structures //
    164.             // --------------- //
    165.             struct VSData
    166.             {
    167.                 half4 Pos            : POSITION;
    168.                 half4 UV            : TEXCOORD0; // uv1 start xy (packed), uv1 Size xy (packed), uv2 start xy (packed), uv2 Size xy (packed)
    169.                 half4 LenOrCorner    : TEXCOORD1; // Len: face tile length x/y
    170.                                                  // Corner: a value from 0,0 to 1,1 to indicate which corner of the tile the vertex is in. Will be lerped.
    171.                 float3 Normal    : NORMAL;     // normal
    172.                 float4 Tangent    : TANGENT;     // tangent/right
    173.             };
    174.  
    175.             struct FSData
    176.             {
    177.                 half4 Pos            : POSITION;
    178.                 half4 UV1            : TEXCOORD0; // uv1 start.xy + uv1 size.xy
    179.                 half4 UV2            : TEXCOORD1; // uv2 start.xy + uv2 size.xy
    180.                 half4 LenOrCorner    : TEXCOORD2; // blocks len + Corner
    181.                 half3 PosWorld        : TEXCOORD3;
    182.                 half3 TangentWorld    : TEXCOORD4;
    183.                 half3 NormalWorld    : TEXCOORD5;
    184.                 half3 BinormalWorld : TEXCOORD6;
    185.             };
    186.  
    187.             // ------------- //
    188.             // Vertex Shader //
    189.             // ------------- //
    190.             FSData Vert(VSData v)
    191.             {
    192.                 FSData o;
    193.                 o.Pos = mul(UNITY_MATRIX_VP, mul(unity_ObjectToWorld, v.Pos));
    194.  
    195.                 // unpack UVs
    196.                 o.UV1 = half4(floor(v.UV.x / 4096), fmod(v.UV.x, 4096),
    197.                     floor(v.UV.y / 4096), fmod(v.UV.y, 4096)) / 4095;
    198.                 o.UV2 = half4(floor(v.UV.z / 4096), fmod(v.UV.z, 4096),
    199.                     floor(v.UV.w / 4096), fmod(v.UV.w, 4096)) / 4095;
    200.  
    201.                 o.LenOrCorner = v.LenOrCorner;
    202.                 o.PosWorld = mul(unity_ObjectToWorld, v.Pos);
    203.                 o.NormalWorld = normalize(mul(unity_ObjectToWorld, v.Normal));
    204.                 o.TangentWorld = normalize(mul(unity_ObjectToWorld, v.Tangent.xyz));
    205.                 o.BinormalWorld = normalize(cross(o.TangentWorld, o.NormalWorld));
    206.                 return o;
    207.             }
    208.  
    209.             // --------------- //
    210.             // Fragment Shader //
    211.             // --------------- //
    212.             float4 Frag(FSData i) : COLOR
    213.             {
    214.                 //                start   +      pos(0-1) %       1 / blocksLen        * blocksLen       * size
    215.                 half2 uv1 = half2(i.UV1.x + fmod(i.LenOrCorner.z, 1 / i.LenOrCorner.x) * i.LenOrCorner.x * i.UV1.z,
    216.                     i.UV1.y + fmod(i.LenOrCorner.w, 1 / i.LenOrCorner.y) * i.LenOrCorner.y * i.UV1.w);
    217.  
    218.                 //                 pos(0-1)        * blocksLen       * size
    219.                 half2 uv1d = half2(i.LenOrCorner.z * i.LenOrCorner.x * i.UV1.z,
    220.                     i.LenOrCorner.w * i.LenOrCorner.y * i.UV1.w);
    221.  
    222.  
    223.                 //                start   +      pos(0-1) %       1 / blocksLen        * blocksLen       * size
    224.                 half2 uv2 = half2(i.UV2.x + fmod(i.LenOrCorner.z, 1 / i.LenOrCorner.x) * i.LenOrCorner.x * i.UV2.z,
    225.                     i.UV2.y + fmod(i.LenOrCorner.w, 1 / i.LenOrCorner.y) * i.LenOrCorner.y * i.UV2.w);
    226.  
    227.                 //                 pos(0-1)        * blocksLen       * size
    228.                 half2 uv2d = half2(i.LenOrCorner.z * i.LenOrCorner.x * i.UV2.z,
    229.                     i.LenOrCorner.w * i.LenOrCorner.y * i.UV2.w);
    230.  
    231.                 half3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.PosWorld.xyz);
    232.                 half3 fragmentToLightSource = _WorldSpaceLightPos0.xyz - i.PosWorld.xyz;
    233.                 float distance = length(fragmentToLightSource);
    234.                 float atten = lerp(1.0, 1.0 / distance, _WorldSpaceLightPos0.w);
    235.                 half3 lightDirection = lerp(normalize(_WorldSpaceLightPos0.xyz), normalize(fragmentToLightSource), _WorldSpaceLightPos0.w);
    236.  
    237.                 // texture2 - normal (rg) and specular maps (a)
    238.                 half4 tex2 = tex2D(_MainTex2, uv2, ddx(uv2d), ddy(uv2d));
    239.                 half specStrength = tex2.a * 500;
    240.                 half3 localNorm = float3(tex2.rg * 2 - 1, 0.0);
    241.                 localNorm.z = 1.0 - 0.5 * dot(localNorm, localNorm);
    242.  
    243.                 // normal transpose matrixs
    244.                 half3x3 local2WorldTranspose = float3x3(i.TangentWorld, i.BinormalWorld, i.NormalWorld);
    245.  
    246.                 // lighting
    247.                 half3 normalDirection = normalize(mul(localNorm, local2WorldTranspose));
    248.                 half3 diffuseReflection = atten * _LightColor0.xyz * saturate(dot(normalDirection, lightDirection));
    249.                 half3 specularReflection;
    250.                 if (dot(normalDirection, lightDirection) < 0.0)
    251.                 {
    252.                     specularReflection = half3(0.0, 0.0, 0.0);
    253.                 }
    254.                 else
    255.                 {
    256.                     specularReflection = atten * _LightColor0.xyz * specStrength * pow(saturate(dot(reflect(-lightDirection, normalDirection), viewDirection)), 128);
    257.                 }
    258.              
    259.                 half3 lightFinal = UNITY_LIGHTMODEL_AMBIENT + diffuseReflection + specularReflection;
    260.                 return float4(tex2D(_MainTex, uv1, ddx(uv1d), ddy(uv1d)) * lightFinal, 1.0);
    261.                 return float4(tex2D(_MainTex, uv1, ddx(uv1d), ddy(uv1d)));
    262.                 return half4(normalDirection.xyz, 1);
    263.             }
    264.  
    265.             ENDCG
    266.         }
    267.     }
    268. }
    Please let me know if there's something obviously stupid I'm doing.
    I understand this is technically out of support scope of SEGI, so don't spend too much time helping if it's not something obvious to you. I'll go and post in other parts of the forums in that case.

    Thanks.

    Update:
    I've just noticed that turning on shadows on the directional light has no impact on my scene...
    This makes me wonder if I have implemented deferred shading correctly...
     
    Last edited: Jan 20, 2017
    RB_lashman likes this.
  20. Shinyclef

    Shinyclef

    Joined:
    Nov 20, 2013
    Posts:
    505
    Here are another couple of examples of weirdness, also pointing to a lack in deferred understanding for my shader lol.
    I activated SEGI, low preset, with (left) and without (right) reflections.
    SEGI Low - WIth Reflections.jpg SEGI Low - No Reflections.jpg
    Reflections makes my geometry very dark. Is this related to the mechanics of shadows?
    I honestly just can't find a simple deferred shader example to copy from :(.
     
    RB_lashman likes this.
  21. Shinyclef

    Shinyclef

    Joined:
    Nov 20, 2013
    Posts:
    505
    Ok wow, it took me ages to find this information!
    Wow. WHERE IS THE DOCUMENTATION lol.
    Literally hours looking for posts and tutorials.
    Reflections from SEGI and Specular highlights are now the right way.
    But turning on SEGI reflections still causes the scene to become dark.

    I have a hunch this may be because I have to support shadows by introducing a shadowcaster pass based on something @sonicether said earlier about if unity shadows just work, then so should SEGI.

    I will look into how shadow casting works next!
     
    RB_lashman likes this.
  22. Shinyclef

    Shinyclef

    Joined:
    Nov 20, 2013
    Posts:
    505
    Well, I added shadows, but that didn't fix the problem.
    So I still have the "Activating SEGI reflections makes the scene dark" problem.
    And come to think of it, I'm not sure that activating SEGI 'without' reflections is doing much at all, although I'd have to compare more carefully to decide that.

    In any case, I'm getting pretty pumped with those dark scene reflections haha.
     
    RB_lashman likes this.
  23. sonicether

    sonicether

    Joined:
    Jan 12, 2013
    Posts:
    265
    Glad to see you got it working! I can't believe I had also forgotten that the normals needed to be unsigned!

    Make sure to enable the debug option "Visualize Voxels" in SEGI to make sure your geometry is being voxelized properly.

    Your materials might be getting dark with reflections because they are metallic (from the screenshots you've shown). Also, I'm sure you've set a sky color in SEGI, right?
     
    Shinyclef and RB_lashman like this.
  24. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,342
    BTW, that is not the correct way to calculate world normals. You should use the built in function:
    UnityObjectToWorldNormal(v.Normal);

    Using unity_ObjectToWorld will work for un-scaled meshes, but will look wrong on anything with non-uniform scaling.
     
  25. Shinyclef

    Shinyclef

    Joined:
    Nov 20, 2013
    Posts:
    505
    Thanks for you input guys, I've updated my shader to user UnityObjectToWorldNormal and UnityObjectToWorldDir (for tangent).

    Also playing around with sky light setting and trying to understand what specular colour and shininess/roughness values make sense.
    for now I've set the specular colour to equal the diffuse colour.
    That seems like maybe a bad idea but I need to read more about appropriate use of these values ahha.

    I'll post some more screenshots when things start looking sweet :).
     
    RB_lashman likes this.
  26. DigitalAdam

    DigitalAdam

    Joined:
    Jul 18, 2007
    Posts:
    1,204
    In Unity 5.5, can you see GI in the Scene view? It use to work with SceneFX in earlier versions of Unity, but it no longer does. Thanks.
     
    RB_lashman likes this.
  27. SteveB

    SteveB

    Joined:
    Jan 17, 2009
    Posts:
    1,451
    Bam
     
  28. ronjart

    ronjart

    Joined:
    May 16, 2013
    Posts:
    101
    yohami, daville, Malbers and 22 others like this.
  29. Shinyclef

    Shinyclef

    Joined:
    Nov 20, 2013
    Posts:
    505
    So, I think I've messed around with SEGI long enough to understand how it works and what I need to do to make my project compatible. I am now able to provide some feedback!

    First of all, it's taken the visual quality of my game up like, several levels haha. Beautiful light has always been one of the most important factors for me. In the visuals, it looks simply amazing.

    In terms of the learning curve, I can see that for people using a standard deferred pipeline with nothing weird going on, easy to drag onto camera and hit play, so well done there.
    For me however, it wasn't that simple. I was learning about the deferred pipeline and re-writing shaders just to be compatible. I ended up modifying the voxelization shader a little so that it would recognize when the incoming verts were blocks from my game and handle the UVs a bit differently. The shader was easy enough to understand, and I took advantage of the fact that only my blocks use the UV z and w channels to identify when to do the different UV logic. The other thing I had to do was get that shader to read the emissive values from my custom voxel texture which had normals, spec, and emissive packed in. In the end, I made some changes and got it to work.

    Performance is in line with what everyone is reporting. It's a heavy hit, but I'm still in the green.
    With segi turned off I'm sitting about 170 FPS for me scene. With SEGI on, I lands at about 75 or so. I'm running a GTX 970. With voxelization turned off, I climb to about 90. This is with the 'high' voxel resolution and the 'bright' preset. (Edit:) Additionally, setting each level of Inner Occlusion Layers causes flickering. You can see it when visualizing the voxels, and goes away when commenting out the two 'interlockedAddFloat4b' lines at the end of the voxelization shader. I'm unsure if I caused this problem with my modifications.


    My game is a voxel sandbox, so large open scenes AND small enclosed areas are possible, depending on what the player builds, so looking forward to cascades.

    I would prefer performance improvements over visual fidelity. Visually it's already amazing, but I start to question my target audience with SEGI on, as they'll need beefy GPUs. This is understandable and still an amazing achievement for beta.

    So I said I'd get some screenshots in when ready. I've been playing around a bit (maybe playing around TOO much!).
    All textures are user-defined content. When you join a 'world', you first download the textures required for that world.
    The textures in the screenshots are a minecraft texture pack I've been using for development purposes. Except for that giant art block!
    Credit where credit's due:
    Most textures: http://www.planetminecraft.com/texture_pack/embossed-texture-pack/
    Art block: http://wen-jr.deviantart.com/art/INSIDE-379472926
    Ironically, I think some of the screenshots the texture pack artist is using may be using your minecraft shaders... haha.

    From top to bottom:
    - Skybox on. Lights on.
    - Skybox off. Lights on.
    - Skybox off. Lights off. (except for that one spot light. The rest is SEGI.)


    Plxsys 2017-01-24_12-34-36.jpg Plxsys 2017-01-24_12-34-48.jpg Plxsys 2017-01-24_12-35-05.jpg
     
    Last edited: Jan 24, 2017
    RB_lashman and DMeville like this.
  30. DigitalAdam

    DigitalAdam

    Joined:
    Jul 18, 2007
    Posts:
    1,204
    It seems when I add this code I get 999+ errors in the console after I Play the scene. When I comment out the code the errors stop. I'm running Unity 5.5.Thoughts? Thanks!
     
    RB_lashman likes this.
  31. SteveB

    SteveB

    Joined:
    Jan 17, 2009
    Posts:
    1,451
    Well you do realize that telling us the errors would be a path towards figuring out what could be wrong, right? :D

    Also show the start of your script where you added the lines so we can also see what you did. Could be a typo or whatnot...
     
    RB_lashman likes this.
  32. DigitalAdam

    DigitalAdam

    Joined:
    Jul 18, 2007
    Posts:
    1,204
    You're right, that would be helpful! Here is what I added:

    [AddComponentMenu("ImageEffects/SonicEther/SEGI")]
    #ifUNITY_5_4_OR_NEWER
    [ImageEffectAllowedInSceneView]
    #endif

    publicclassSEGI:MonoBehaviour

    It compiles and runs, SEGI works in the editor. But the warning I get 999+ times is:
    MissingReferenceException: The object of type 'Camera' has been destroyed but you are still trying to access it.
    Your script should either check if it is null or you should not destroy the object.
    SEGI.OnPreRender () (at Assets/SEGI/SEGI.cs:930)


    When I double-click on the warning, it takes me to line 930:
    voxelCamera.targetTexture = dummyVoxelTexture2;

    Hope that helps! I'm running Unity 5.5.0f3 and SEGI 8.3.
     
    Last edited: Jan 26, 2017
    RB_lashman likes this.
  33. SteveB

    SteveB

    Joined:
    Jan 17, 2009
    Posts:
    1,451
    Hmmm that is so weird! Okay this might need Sonic then as it appears you only added the three lines and did it correctly.
     
    RB_lashman likes this.
  34. DigitalAdam

    DigitalAdam

    Joined:
    Jul 18, 2007
    Posts:
    1,204
    Is there a way to add a second Directional Light for the moon? I'm creating a time-of-day system, and when it's night SEGI doesn't work.
     
    RB_lashman likes this.
  35. SteveB

    SteveB

    Joined:
    Jan 17, 2009
    Posts:
    1,451
    Not sure this would work so you should attempt it, but why not plug in the directional light into SEGI at runtime with another script? So when you reach moonlight, swap it out, again in script at run-time.

    If not, since they're both the same damn gameObject, just change the Directional Light settings from Sun to Moon?
     
    RB_lashman likes this.
  36. DigitalAdam

    DigitalAdam

    Joined:
    Jul 18, 2007
    Posts:
    1,204
    Great idea. I parented another Direction Light for the moon to the Sun Direction Light, and swapped them out at runtime. That worked fine, just needs some minor tweaking... so thanks!
     
    RB_lashman and SteveB like this.
  37. Lex4art

    Lex4art

    Joined:
    Nov 17, 2012
    Posts:
    445
    +1 to error, related to user-made modification for Scene view (still present on Unity 5.1.1):
    Code (CSharp):
    1. MissingReferenceException: The object of type 'Camera' has been destroyed but you are still trying to access it.
    2. Your script should either check if it is null or you should not destroy the object.
    3. SEGI.OnPreRender () (at Assets/SEGI/SEGI.cs:831)
     
    RB_lashman likes this.
  38. NERVAGON

    NERVAGON

    Joined:
    Oct 27, 2009
    Posts:
    73
    It would really be appreciated if SEGI didn't turn metals black.
     
  39. Shinyclef

    Shinyclef

    Joined:
    Nov 20, 2013
    Posts:
    505
    I don't think it turns metals black.
    It would be black if it is reflecting black, or very dark, and there is no light shining directly on it.

    Is this not the case for you?
     
    RB_lashman likes this.
  40. NERVAGON

    NERVAGON

    Joined:
    Oct 27, 2009
    Posts:
    73
    Generally, yes, from what I've experienced, metals turn black in interior shots where cube maps and ssr work fine. I've been compensating by adding some emissive, but that is not ideal.
     
  41. sonicether

    sonicether

    Joined:
    Jan 12, 2013
    Posts:
    265
    The way that SEGI blends metallic reflections is less than ideal at the moment, and could only really be improved with the use of command buffers which would require Unity 5.4 and up. I will definitely put more work into this though.

    I'll also take a look at improving compatibility with the [ImageEffectAllowedInSceneView] tag.
     
    vonpixel, ksam2, hopeful and 4 others like this.
  42. vonpixel

    vonpixel

    Joined:
    Oct 2, 2012
    Posts:
    31
    Thought I would share a little work in progess capture from a project im working on. Its a real time sound visualization thing, and honestly segi makes it possible in a way I thought wasnt going to be!



    We've been adapting our current main project to use SEGI too and pretty happy with the results so far (i mean other than some wonky interior lighting). Im sure ill share some of that eventually.

    Love this lighting engine! Cant wait to see where it goes.
     
    Shinyclef, Baldinoboy and RB_lashman like this.
  43. Shinyclef

    Shinyclef

    Joined:
    Nov 20, 2013
    Posts:
    505
    Holy crap I think I just got hypnotised....
     
    RB_lashman likes this.
  44. sonicether

    sonicether

    Joined:
    Jan 12, 2013
    Posts:
    265
    Hey everyone, I just wanted to give a few updates on how cascades are going.

    I've been recently doing some testing of how cascades are at the moment, and I wanted to share the results.

    So, here's a few comparisons of cascades vs no cascades in the Viking Village scene. In the comparisons below, the first image is with cascades, and the second image is without cascades.




    And here's no GI for reference:












    And to demonstrate the draw distance of GI with cascades at the settings in the images above:



    So there are a couple interesting performance-related things about cascades in their current state. First of all, the VRAM usage is actually drastically lower with cascades, only 128 MB (vs 490 MB). Also, since only one cascade is being updated at a time and the cascade resolution is lower than the GI voxel volume resolution without cascades, the amount of work needed to update each cascade is reduced.

    Here's the profiler with cascades:


    and without:


    The little spikes are from the Unity editor GUI updating.

    Since the cascades are updated currently in a sequential order, you can see that the cascades that cover a larger area of the scene are more expensive to calculate since there's more geometry to voxelize. Do keep in mind that, in the Viking Village, there are a lot of needlessly high poly objects being voxelized, since I haven't bothered to setup low poly proxy GI objects yet.

    Here's how performance is when I disable the "props" in the Viking Village (so only the buildings are voxelized, and little detail objects are omitted). Still, the buildings in the Viking Village are what I'd consider needlessly high poly for GI voxelization.




    Having cascades does increase the render time of cone tracing, but this will be offset by the addition of blue noise which will allow for tracing fewer cones per pixel for approximately the same image quality. Check out this post in case you missed the comparison of white noise vs blue noise: https://forum.unity3d.com/threads/segi-fully-dynamic-global-illumination.410310/page-18#post-2913359

    Since reflection tracing can't benefit from blue noise, tracing reflections will cost more. I'll see what I can do to optimize reflection tracing to help with this.

    There's still a lot more work to be done, but it's getting there!
     
  45. SteveB

    SteveB

    Joined:
    Jan 17, 2009
    Posts:
    1,451
    Holy crap and the ambient occlusion looks more precise with cascades. Going by the very first comparison shot, you can see this on the distant objects (straight down the main path)...very F***ing cool!

    So happy!

    -Steven
     
    RB_lashman, Arganth and chiapet1021 like this.
  46. Vagabond_

    Vagabond_

    Joined:
    Aug 26, 2014
    Posts:
    1,148
    I only notice that without cascades, the distant objects are looking a bit more cleaner but with cascades the close objects are looking much better - so i guess cascades are doing well and are great addition (optimization) to SEGI... can't wait to test it :)
     
    SteveB and RB_lashman like this.
  47. SteveB

    SteveB

    Joined:
    Jan 17, 2009
    Posts:
    1,451
    The only thing I care about is lighting consistency. Broad, efficient strokes of general bounce and sky lighting and we're golden.
     
    DMeville, RB_lashman and chiapet1021 like this.
  48. chiapet1021

    chiapet1021

    Joined:
    Jun 5, 2013
    Posts:
    605
    Yup, predictable, performant indirect lighting that works with runtime-generated scene geometry would earn :heart_eyes: spam from me all day long. :)
     
  49. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    Is there asset for poly reduction to automate proxy to optimize voxelization? We need to start establishing the workflow for optimal testing!
     
    RB_lashman and SteveB like this.
  50. chiapet1021

    chiapet1021

    Joined:
    Jun 5, 2013
    Posts:
    605
    There are a few LOD assets on the store. I'm hoping something like that would work for this purpose.
     
    RB_lashman and SteveB like this.