Бархат (Velvet)

Для экспериментальных разработок и тем "я нашел чужой исходник, почему он не работает?"

Бархат (Velvet)

Сообщение gnoblin 22 окт 2010, 07:33

типа бархатная поверхность (popcorn1)
Пока не разобрался какое значение задавать для _VelvetExponent, а еще как автоматом передать LightDir и _LightColor.
И наверное сам цвет бархата тоже нуно.

Синтаксис:
Используется glsl
Shader "Velvet" {
Properties
{
        _LightColor("LightColor", Color) = (1,1,1,1)
        _BumpMap ("Normalmap", 2D) = "bump" {} 
}
    SubShader {
      Tags { "RenderType" = "Opaque" }
      CGPROGRAM
      #pragma surface surf Lambert
         
      struct Input {
          float2 uv_MainTex;
          float3 viewDir;
      };
     
      sampler2D _MainTex;
      sampler2D _BumpMap;
      float4 _LightColor;
     
      void surf (Input IN, inout SurfaceOutput o)
      {
                        o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_MainTex));
                       
                        //какое значение писать сюда?
                        float _Velvet_Exponent = 1;
                       
                        //как нормально передать позицию источника света?
                        float3 LightDir = float3(0,1,1);
                       
                        // Compute both the light and eye angle about the surface
                        // normal for the surface
                        float l = pow( clamp(dot(o.Normal, LightDir), 0, 1), _Velvet_Exponent);
                        float e = pow( clamp(dot(o.Normal, normalize(IN.viewDir)),0,1), _Velvet_Exponent);
                       
                        // Compute final lighting. Which is defined as the product
                        // of the cosine of both the light and eye vectors.
                        o.Albedo = _LightColor * clamp(l*e,0,1);
          }      

      ENDCG
    }
    Fallback "Diffuse"
}
skypeid: madkust
Мои крайние проекты:
Убойный Хоккей
Cube Day Z (альфа)
Аватара пользователя
gnoblin
Адепт
 
Сообщения: 4633
Зарегистрирован: 08 окт 2008, 17:23
Откуда: Минск, Беларусь
Skype: madkust
  • Сайт

Re: Бархат (Velvet)

Сообщение tumanoid 19 май 2013, 01:57

Синтаксис:
Используется csharp
Shader "Custom/Velvet" {
Properties
{
        _MainColor("MainColor", Color) = (1,1,1,1)
        _BumpMap ("Normalmap", 2D) = "bump" {}
        _MainTex ("MainTex", 2D) = "bump" {}
        _ex ("Exponent", float) = 1
}
    SubShader {
      Tags { "RenderType" = "Opaque" }
      CGPROGRAM
      #pragma surface surf VelvetLambert
         
      struct Input {
          float2 uv_MainTex;
          float2 uv_BumpMap;
      };
     
      sampler2D _MainTex;
      sampler2D _BumpMap;
      float4 _MainColor;
      float  _ex;
           
      half4 LightingVelvetLambert (SurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
      {
                        //Lambert составляющая
                        //half NdotL = dot (s.Normal, lightDir);              
                       
                        //какое значение писать сюда?
                        float _Velvet_Exponent = s.Gloss;
                       
                        //как нормально передать позицию источника света?                      
                        half3 LightDir = lightDir;
                       
                        // Compute both the light and eye angle about the surface
                        // normal for the surface
                        float l = pow( clamp(dot(s.Normal, LightDir), 0, 1), _Velvet_Exponent);
                        float e = pow( clamp(dot(s.Normal, normalize(viewDir)),0,1), _Velvet_Exponent);

                        // Compute final lighting. Which is defined as the product
                        // of the cosine of both the light and eye vectors.
                        //o.Albedo = _LightColor * clamp(l*e,0,1);
                        half4 c = 0;
                        c.rgb = clamp(l*e,0,1) * s.Albedo.rgb * _LightColor0.rgb;// * NdotL * atten * 2;
                        c.a = 1;
                        return c;
          }      
     

      void surf (Input IN, inout SurfaceOutput o) {
          o.Albedo = _MainColor * tex2D (_MainTex, IN.uv_MainTex).rgb;
          o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
          o.Gloss = _ex;
      }


      ENDCG
    }
    Fallback "Diffuse"
}
 


Как-то так.
tumanoid
UNец
 
Сообщения: 34
Зарегистрирован: 20 авг 2011, 14:21

Re: Бархат (Velvet)

Сообщение NightFox 29 сен 2013, 00:33

Спасибо.
Только не
Код: Выделить всё
         _MainTex ("MainTex", 2D) = "bimp" {}
а
Код: Выделить всё
         _MainTex ("MainTex", 2D) = "white" {}
NightFox
UNITрон
 
Сообщения: 194
Зарегистрирован: 12 апр 2013, 12:46


Вернуться в Шейдерная кузня

Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 1