如何在unity3d CGprogram着色器中设置布尔属性?

时间:2013-09-24 17:47:50

标签: opengl unity3d shader cg

我正在为unity3d编写一个着色器,我想指定着色器的属性,例如 -

Shader "GraphicsQuality/MediumScan" {
Properties {
    _Color ("Main Color", Color) = (1,1,1,1)
    _SpecColor ("Specular Color", Color) = (0.5,0.5,0.5,1)
    _Shininess ("Shininess", Range (0.01, 1)) = 0.078125
    _MainTex ("Base (RGB) RefStrGloss (A)", 2D) = "white" {}
    _BumpMap ("Normalmap", 2D) = "bump" {}
    _RimColor ("Rim Color", Color) = (0.48,0.78,1.0,0.0)
    _RimPower ("Rim Power", Range(0,8.0)) = 3.0
}

但是这些属性是用于颜色,范围,浮点等但我想输入一个布尔值我该怎么做呢我试过像 -

Properties{
    _MainTex ("Particle Texture", 2D) = "white" {
    _isBending("is Bending",bool) = true
}
SubShader{
        Pass{
            CGPROGRAM

                #pragma vertex vert
                #pragma fragment frag

                sampler2D _MainTex;
                bool _isBending;
.......continuing

但这不起作用我无法获得布尔属性“_isBending”而我在行中得到错误

  _isBending("is Bending",bool) = true

2 个答案:

答案 0 :(得分:12)

[MaterialToggle] _isBending("is Bending", Float) = 0

[Toggle] _isBending("is Bending", Float) = 0

至少你会有一个视觉切换按钮。

答案 1 :(得分:2)

Unity着色器属性不支持布尔值。要解决此问题,请尝试使用浮点数。 有关详细信息,请参阅此页面: http://docs.unity3d.com/Documentation/Components/SL-Properties.html