Search Unity

Sample Skybox in Fragment Shader

Discussion in 'Shaders' started by edwar496, Apr 6, 2017.

  1. edwar496

    edwar496

    Joined:
    Jun 28, 2016
    Posts:
    18
    Hey guys, I've been working with shaders for a little bit now but I'm trying to do something a little odd. This talk (http://advances.realtimerendering.com/other/2016/naughty_dog/) from Naughty Dog mentioned something they did where they actually sampled the skybox to determine the color of their fog instead of just using a flat color on every object. I looked, and I couldn't find a macro that let me sample the skybox in the current unity scene in a fragment shader. Does anyone know how I might go about doing something like this, or maybe a clever workaround? Thanks!
     
  2. brokenm

    brokenm

    Joined:
    Aug 28, 2014
    Posts:
    22
    1) you can feed skybox in shader as cubemap
    2) you can setup reflection probe on camera and then pass it to shader for sampling (useful in case of procedural skybox)
     
  3. edwar496

    edwar496

    Joined:
    Jun 28, 2016
    Posts:
    18
    Hadn't considered the cubemap idea - that could definitely work! The question is, can I set cubemaps globally the same way I set textures globally? I'd hate to have to run a script to apply this fog cubemap for every material in my scene.
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
  5. edwar496

    edwar496

    Joined:
    Jun 28, 2016
    Posts:
    18
    Awesome, thanks guys!
     
  6. monotoan

    monotoan

    Joined:
    Feb 13, 2015
    Posts:
    11
    Using "SetGlobalTexture" in a script to dynamically set skybox shader "samplerCUBE" to a cubemap variable doesn't seem to be working for me. I've made sure to remove those variables from the properties section of the shader, but still can't get it to set.

    E.g. this does not work for me:

    Code (CSharp):
    1. public Cubemap skyboxCubemap;
    2.  
    3. void Start(){
    4. Shader.SetGlobalTexture("_SkyboxCustomTex1", skyboxCubemap);
    5. }
    Will post an update if I solve this.