Unity设置环境的RenderSetting类的使用

Unity设置环境的RenderSetting类的使用

    • 手动设置
    • 源码
  • 重新补充用法
    • 实际使用
    • 注意的要点
    • 参考

手动设置

关于环境光的手动设置,熟练使用Unity的各位应该都知道:Window->Rendering->Lighting Setting
调出的窗口便可以用来设置环境光。
Unity设置环境的RenderSetting类的使用_第1张图片

源码

那么,在代码中动态修改这些值,又有什么方法呢?
Unity中的RenderSetting类就可以做到。(Unity版本:2018.3.14f1)

namespace UnityEngine
{
    //
    // 摘要:
    //     ///
    //     The Render Settings contain values for a range of visual elements in your Scene,
    //     like fog and ambient light.
    //     ///
    [NativeHeader("Runtime/Camera/RenderSettings.h")]
    [NativeHeader("Runtime/Graphics/GraphicsScriptBindings.h")]
    [NativeHeader("Runtime/Graphics/QualitySettingsTypes.h")]
    [StaticAccessor("GetRenderSettings()", StaticAccessorType.Dot)]
    public sealed class RenderSettings : Object
    {
        //
        // 摘要:
        //     ///
        //     Ambient lighting coming from the sides.
        //     ///
        public static Color ambientEquatorColor { get; set; }
        //
        // 摘要:
        //     ///
        //     Ambient lighting coming from below.
        //     ///
        public static Color ambientGroundColor { get; set; }
        //
        // 摘要:
        //     ///
        //     How much the light from the Ambient Source affects the Scene.
        //     ///
        public static float ambientIntensity { get; set; }
        //
        // 摘要:
        //     ///
        //     Flat ambient lighting color.
        //     ///
        [NativeProperty("AmbientSkyColor")]
        public static Color ambientLight { get; set; }
        //
        // 摘要:
        //     ///
        //     Ambient lighting mode.
        //     ///
        public static AmbientMode ambientMode { get; set; }
        //
        // 摘要:
        //     ///
        //     Custom or skybox ambient lighting data.
        //     ///
        public static SphericalHarmonicsL2 ambientProbe { get; set; }
        [Obsolete("Use RenderSettings.ambientIntensity instead (UnityUpgradable) -> ambientIntensity", false)]
        public static float ambientSkyboxAmount { get; set; }
        //
        // 摘要:
        //     ///
        //     Ambient lighting coming from above.
        //     ///
        public static Color ambientSkyColor { get; set; }
        //
        // 摘要:
        //     ///
        //     Custom specular reflection cubemap.
        //     ///
        public static Cubemap customReflection { get; set; }
        //
        // 摘要:
        //     ///
        //     Default reflection mode.
        //     ///
        public static DefaultReflectionMode defaultReflectionMode { get; set; }
        //
        // 摘要:
        //     ///
        //     Cubemap resolution for default reflection.
        //     ///
        public static int defaultReflectionResolution { get; set; }
        //
        // 摘要:
        //     ///
        //     The fade speed of all flares in the Scene.
        //     ///
        public static float flareFadeSpeed { get; set; }
        //
        // 摘要:
        //     ///
        //     The intensity of all flares in the Scene.
        //     ///
        public static float flareStrength { get; set; }
        //
        // 摘要:
        //     ///
        //     Is fog enabled?
        //     ///
        [NativeProperty("UseFog")]
        public static bool fog { get; set; }
        //
        // 摘要:
        //     ///
        //     The color of the fog.
        //     ///
        public static Color fogColor { get; set; }
        //
        // 摘要:
        //     ///
        //     The density of the exponential fog.
        //     ///
        public static float fogDensity { get; set; }
        //
        // 摘要:
        //     ///
        //     The ending distance of linear fog.
        //     ///
        [NativeProperty("LinearFogEnd")]
        public static float fogEndDistance { get; set; }
        //
        // 摘要:
        //     ///
        //     Fog mode to use.
        //     ///
        public static FogMode fogMode { get; set; }
        //
        // 摘要:
        //     ///
        //     The starting distance of linear fog.
        //     ///
        [NativeProperty("LinearFogStart")]
        public static float fogStartDistance { get; set; }
        //
        // 摘要:
        //     ///
        //     Size of the Light halos.
        //     ///
        public static float haloStrength { get; set; }
        //
        // 摘要:
        //     ///
        //     The number of times a reflection includes other reflections.
        //     ///
        public static int reflectionBounces { get; set; }
        //
        // 摘要:
        //     ///
        //     How much the skybox / custom cubemap reflection affects the Scene.
        //     ///
        public static float reflectionIntensity { get; set; }
        //
        // 摘要:
        //     ///
        //     The global skybox to use.
        //     ///
        [NativeProperty("SkyboxMaterial")]
        public static Material skybox { get; set; }
        //
        // 摘要:
        //     ///
        //     The color used for the sun shadows in the Subtractive lightmode.
        //     ///
        public static Color subtractiveShadowColor { get; set; }
        //
        // 摘要:
        //     ///
        //     The light used by the procedural skybox.
        //     ///
        public static Light sun { get; set; }
    }
}

详解:

  • ambientEquatorColor:环境照明颜色–从周围。
  • ambientGroundColor: 环境照明颜色–从下面。
  • ambientIntensity:环境光的强度。
  • ambientLight: 平面环境照明颜色。
  • ambientMode:环境照明模式。
  • ambientProbe:自定义或天空盒环境照明的数据。
  • ambientSkyboxAmount:环境光的强度。(已废除,使用RenderSetting.ambientIntensity)
  • ambientSkyColor:环境照明颜色–从上面。
  • customReflection:自定义镜面反射图。
  • defaultReflectionMode:默认反射模式。
  • defaultReflectionResolution:默认反射的Cubemap分辨率。
  • flareFadeSpeed:场景中所有火焰的褪色速度。
  • flareStrength:现场所有火焰的强度。
  • fog: 有雾吗?
  • fogColor:雾的颜色。
  • fogDensity:指数雾的密度。
  • fogEndDistance:线性雾的结束距离。
  • fogMode:要使用的雾模式。
  • fogStartDistance:线性雾的起始距离。
  • haloStrength:光晕的大小。
  • reflectionBounces:反射次数(包括其他反射)。
  • reflectionIntensity:反射强度。
  • skybox:天空盒。
  • subtractiveShadowColor:减光模式中太阳阴影所用的颜色。
  • sun:程序天空所用的光线。

重新补充用法

实际使用

虽然知道的代码接口,但在实际使用时又出了一些问题,首先就是窗口中手动设置的显示值和代码中定义的值并不一样;而且窗口中显示的设置和代码中的属性之间存在数量上的差距。所以只能费时间查找资料和测试。
这里我只用到2个数值:环境光的类型强度

代码中的设置:

RenderSettings.ambientMode = AmbientMode.Skybox;
RenderSettings.reflectionIntensity = 0.96f;

其中,reflectionIntensity就不必多说;主要在ambientMode的设置和对应上。

注意的要点

代码中,ambientMode是有4个类型的,分别是:SkyboxTrilightFlatCustom;而窗口的手动设置中的Source,则是有3个选项,是:SkyboxGradientColor。我乍一看上去,都认为两者之间是没有关系的,毕竟名称不同,选项也不尽相同。但经过资料查找和项目测试,证明了,两者是同一个属性,至少在表现上来看是这样的。其中,各选项的对应关系是:

  • Skybox:Skybox
  • Trilight:Gradient
  • Flat:Color
  • Custom自定义的cubemap

在使用时,前三个都是一对一的对应关系;而最后一个则是,结合其他的代码属性使用的自定义cubemap,例如,ambientEquatorColorambientGroundColorambientSkyColor等。

参考

https://blog.csdn.net/linjf520/article/details/90051301?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.nonecase

你可能感兴趣的:(基础)