Двухсторонний транспарент материал

Шейдеры и все-все-все.

Двухсторонний транспарент материал

Сообщение fox 22 май 2009, 11:27

Уважаемые шейдер гуру, помогите с двусторонним транспарент шейдером, плз. ^:)^
Добавить foxumkov в Skype
Мои проекты:
Turbodrive
Изображение

Изображение
Аватара пользователя
fox
UNITрон
 
Сообщения: 255
Зарегистрирован: 07 ноя 2008, 13:02
Откуда: Питер
  • ICQ

Re: Двухсторонний транспарент материал

Сообщение Neodrop 22 май 2009, 11:31

Nature шейдеры чем вам плохи?
Добавить neodrop в Skype
Изображение
"Спасибо!" нашему порталу, вы сможете сказать ЗДЕСЬ.
Если проблема не решается честно, нужно её обмануть! || Per stupiditas at Astra!
Страх порождает слабость. Бесстрашных поражают пули.
Протратившись на блядях байтах, на битах не экономят.
Аватара пользователя
Neodrop
Админ
 
Сообщения: 8480
Зарегистрирован: 08 окт 2008, 15:42
Откуда: Питер
Skype: neodrop
  • Сайт

Re: Двухсторонний транспарент материал

Сообщение fox 22 май 2009, 12:00

а не слишком ли они прожорливы?
Добавить foxumkov в Skype
Мои проекты:
Turbodrive
Изображение

Изображение
Аватара пользователя
fox
UNITрон
 
Сообщения: 255
Зарегистрирован: 07 ноя 2008, 13:02
Откуда: Питер
  • ICQ

Re: Двухсторонний транспарент материал

Сообщение Neodrop 22 май 2009, 12:03

С чего это вдруг? :-?

А проверить сложно?
Добавить neodrop в Skype
Изображение
"Спасибо!" нашему порталу, вы сможете сказать ЗДЕСЬ.
Если проблема не решается честно, нужно её обмануть! || Per stupiditas at Astra!
Страх порождает слабость. Бесстрашных поражают пули.
Протратившись на блядях байтах, на битах не экономят.
Аватара пользователя
Neodrop
Админ
 
Сообщения: 8480
Зарегистрирован: 08 окт 2008, 15:42
Откуда: Питер
Skype: neodrop
  • Сайт

Re: Двухсторонний транспарент материал

Сообщение fox 22 май 2009, 13:29

:-? хм, а ведь и вправду разница копеечная....единственное шейдеры Nature не реагируют на направление света!
Добавить foxumkov в Skype
Мои проекты:
Turbodrive
Изображение

Изображение
Аватара пользователя
fox
UNITрон
 
Сообщения: 255
Зарегистрирован: 07 ноя 2008, 13:02
Откуда: Питер
  • ICQ

Re: Двухсторонний транспарент материал

Сообщение Const_47 22 май 2009, 14:50

В смысле? Direct Light вам прикрутить?
Const_47
Герой Форума
 
Сообщения: 271
Зарегистрирован: 23 мар 2009, 19:24
Откуда: Украина. Львов\Новояворовск

Re: Двухсторонний транспарент материал

Сообщение fox 22 май 2009, 16:55

Const_47 писал(а):В смысле? Direct Light вам прикрутить?

угу
Добавить foxumkov в Skype
Мои проекты:
Turbodrive
Изображение

Изображение
Аватара пользователя
fox
UNITрон
 
Сообщения: 255
Зарегистрирован: 07 ноя 2008, 13:02
Откуда: Питер
  • ICQ

Re: Двухсторонний транспарент материал

Сообщение Const_47 23 май 2009, 04:55

Аську мне в личные.
Const_47
Герой Форума
 
Сообщения: 271
Зарегистрирован: 23 мар 2009, 19:24
Откуда: Украина. Львов\Новояворовск

Re: Двухсторонний транспарент материал

Сообщение fox 25 май 2009, 16:54

Спасибо, Const_47, что указал мне где находятся исходники базовых шейдеров.
Я налабал свой, по базовому. Что скажите?

Код: Выделить всё
Shader "Transparent/Diffuse2Sided" {
Properties {
   _Color ("Main Color", Color) = (1,1,1,1)
   _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
}

Category {
   Tags {Queue=Transparent}
   Alphatest Greater 0
   ZWrite Off
   ColorMask RGB
   //Cull Off
   // ------------------------------------------------------------------
   // ARB fragment program
   
   SubShader {
      // Ambient pass
      Pass {
         Name "BASE"
         Cull Off
         Tags {"LightMode" = "PixelOrNone"}
         Fog { Color [_AddFog] }
         Blend SrcAlpha OneMinusSrcAlpha
         Color [_PPLAmbient]
         SetTexture [_MainTex] {constantColor [_Color] Combine texture * primary DOUBLE, texture * primary}
      }
      // Vertex lights
      Pass {
         Name "BASE"
         Cull Off
         Tags {"LightMode" = "Vertex"}
         Fog { Color [_AddFog] }
         Blend SrcAlpha OneMinusSrcAlpha
         Lighting On
         Material {
            Diffuse [_Color]
            Emission [_PPLAmbient]
         }
         SetTexture [_MainTex] {combine texture * primary DOUBLE, texture * primary}
      }
      // Pixel lights
      Pass {   
         Name "PPL"
         Tags { "LightMode" = "Pixel" }
         Blend SrcAlpha One
         Fog { Color [_AddFog] }

CGPROGRAM
#pragma fragment frag
#pragma vertex vert
#pragma multi_compile_builtin_noshadows
#pragma fragmentoption ARB_fog_exp2
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
#include "AutoLight.cginc"

struct v2f {
   V2F_POS_FOG;
   LIGHTING_COORDS
   float2   uv;
   float3   normal;
   float3   lightDir;
};

uniform float4 _MainTex_ST;

v2f vert (appdata_base v)
{
   v2f o;
   PositionFog( v.vertex, o.pos, o.fog );
   o.normal = v.normal;
   o.uv = TRANSFORM_TEX(v.texcoord,_MainTex);
   o.lightDir = ObjSpaceLightDir( v.vertex );
   TRANSFER_VERTEX_TO_FRAGMENT(o);
   return o;
}

uniform sampler2D _MainTex;
uniform float4 _Color;

float4 frag (v2f i) : COLOR
{
   half4 texcol = tex2D( _MainTex, i.uv );   
   half4 c = DiffuseLight( i.lightDir, i.normal, texcol, LIGHT_ATTENUATION(i) );
   c.a = texcol.a * _Color.a;
   return c;
}
ENDCG

         SetTexture [_MainTex] {combine texture}
         SetTexture [_LightTexture0] {combine texture}
         SetTexture [_LightTextureB0] {combine texture}
      }
      //Pixel light back
      Pass {   
         Name "PPL"
         Cull Front
         Tags { "LightMode" = "Pixel" }
         Blend SrcAlpha One
         Fog { Color [_AddFog] }

CGPROGRAM
#pragma fragment frag
#pragma vertex vert
#pragma multi_compile_builtin_noshadows
#pragma fragmentoption ARB_fog_exp2
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
#include "AutoLight.cginc"

struct v2f {
   V2F_POS_FOG;
   LIGHTING_COORDS
   float2   uv;
   float3   normal;
   float3   lightDir;
};

uniform float4 _MainTex_ST;

v2f vert (appdata_base v)
{
   v2f o;
   PositionFog( v.vertex, o.pos, o.fog );
   o.normal = -v.normal;
   o.uv = TRANSFORM_TEX(v.texcoord,_MainTex);
   o.lightDir = ObjSpaceLightDir( v.vertex );
   TRANSFER_VERTEX_TO_FRAGMENT(o);
   return o;
}

uniform sampler2D _MainTex;
uniform float4 _Color;

float4 frag (v2f i) : COLOR
{
   half4 texcol = tex2D( _MainTex, i.uv );   
   half4 c = DiffuseLight( i.lightDir, i.normal, texcol, LIGHT_ATTENUATION(i) );
   c.a = texcol.a * _Color.a;
   return c;
}
ENDCG

         SetTexture [_MainTex] {combine texture}
         SetTexture [_LightTexture0] {combine texture}
         SetTexture [_LightTextureB0] {combine texture}
      }
   }
   
   // ------------------------------------------------------------------
   // Radeon 9000

   SubShader {
      // Ambient pass
      Pass {
         Blend SrcAlpha OneMinusSrcAlpha
         Name "BASE"
         Cull Off
         Tags {"LightMode" = "PixelOrNone"}
         Color [_PPLAmbient]
         SetTexture [_MainTex] {constantColor [_Color] Combine texture * primary DOUBLE, texture * constant}
      }
      // Vertex lights
      Pass {
         Blend SrcAlpha OneMinusSrcAlpha
         Name "BASE"
         Cull Off
         Tags {"LightMode" = "Vertex"}
         Lighting On
         Material {
            Diffuse [_Color]
            Emission [_PPLAmbient]
         }
         SetTexture [_MainTex] {Combine texture * primary DOUBLE, texture * primary}
      }
      
      // Pixel lights with 0 light textures
      Pass {
         Blend SrcAlpha One
         Name "PPL"
         Tags {
            "LightMode" = "Pixel"
            "LightTexCount" = "0"
         }

CGPROGRAM
#pragma vertex vert
#include "UnityCG.cginc"

struct v2f {
   V2F_POS_FOG;
   float2 uv      : TEXCOORD0;
   float3 normal   : TEXCOORD1;
   float3 lightDir   : TEXCOORD2;
};

uniform float4 _MainTex_ST;

v2f vert(appdata_base v)
{
   v2f o;
   PositionFog( v.vertex, o.pos, o.fog );
   o.normal = v.normal;
   o.uv = TRANSFORM_TEX(v.texcoord,_MainTex);
   o.lightDir = ObjSpaceLightDir( v.vertex );
   return o;
}
ENDCG
         Program "" {
            SubProgram {
               Local 0, [_ModelLightColor0]
               Local 1, [_Color]

"!!ATIfs1.0
StartConstants;
   CONSTANT c0 = program.local[0];
   CONSTANT c1 = program.local[1];
EndConstants;

StartOutputPass;
   SampleMap r0, t0.str;         # main texture
   SampleMap r1, t2.str;         # normalized light dir
   PassTexCoord r2, t1.str;      # normal
   
   DOT3 r5.sat, r2, r1.2x.bias;   # R5 = diffuse (N.L)
   
   MUL r0.rgb, r0, r5;
   MUL r0.rgb.2x, r0, c0;
   MUL r0.a, r0, c1;
EndPass;
"
            }
         }
         SetTexture[_MainTex] {combine texture}
         SetTexture[_CubeNormalize] {combine texture}
      }
      // Back pixel lights with 0 light textures
      Pass {
         Blend SrcAlpha One
         Name "PPL"
         Cull Front
         Tags {
            "LightMode" = "Pixel"
            "LightTexCount" = "0"
         }

CGPROGRAM
#pragma vertex vert
#include "UnityCG.cginc"

struct v2f {
   V2F_POS_FOG;
   float2 uv      : TEXCOORD0;
   float3 normal   : TEXCOORD1;
   float3 lightDir   : TEXCOORD2;
};

uniform float4 _MainTex_ST;

v2f vert(appdata_base v)
{
   v2f o;
   PositionFog( v.vertex, o.pos, o.fog );
   o.normal = -v.normal;
   o.uv = TRANSFORM_TEX(v.texcoord,_MainTex);
   o.lightDir = ObjSpaceLightDir( v.vertex );
   return o;
}
ENDCG
         Program "" {
            SubProgram {
               Local 0, [_ModelLightColor0]
               Local 1, [_Color]

"!!ATIfs1.0
StartConstants;
   CONSTANT c0 = program.local[0];
   CONSTANT c1 = program.local[1];
EndConstants;

StartOutputPass;
   SampleMap r0, t0.str;         # main texture
   SampleMap r1, t2.str;         # normalized light dir
   PassTexCoord r2, t1.str;      # normal
   
   DOT3 r5.sat, r2, r1.2x.bias;   # R5 = diffuse (N.L)
   
   MUL r0.rgb, r0, r5;
   MUL r0.rgb.2x, r0, c0;
   MUL r0.a, r0, c1;
EndPass;
"
            }
         }
         SetTexture[_MainTex] {combine texture}
         SetTexture[_CubeNormalize] {combine texture}
      }
      
      // Pixel lights with 1 light texture
      Pass {
         Blend SrcAlpha One
         Name "PPL"
         Tags {
            "LightMode" = "Pixel"
            "LightTexCount" = "1"
         }

CGPROGRAM
#pragma vertex vert
#include "UnityCG.cginc"

uniform float4 _MainTex_ST;
uniform float4x4 _SpotlightProjectionMatrix0;

struct v2f {
   V2F_POS_FOG;
   float2 uv      : TEXCOORD0;
   float3 normal   : TEXCOORD1;
   float3 lightDir   : TEXCOORD2;
   float4 LightCoord0 : TEXCOORD3;
};

v2f vert(appdata_tan v)
{
   v2f o;
   PositionFog( v.vertex, o.pos, o.fog );
   o.normal = v.normal;
   o.uv = TRANSFORM_TEX(v.texcoord,_MainTex);
   o.lightDir = ObjSpaceLightDir( v.vertex );
   
   o.LightCoord0 = mul(_SpotlightProjectionMatrix0, v.vertex);
   
   return o;
}
ENDCG
         Program "" {
            SubProgram {
               Local 0, [_ModelLightColor0]
               Local 1, [_Color]

"!!ATIfs1.0
StartConstants;
   CONSTANT c0 = program.local[0];
   CONSTANT c1 = program.local[1];
EndConstants;

StartOutputPass;
   SampleMap r0, t0.str;         # main texture
   SampleMap r1, t2.str;         # normalized light dir
   PassTexCoord r4, t1.str;      # normal
   SampleMap r2, t3.str;         # a = attenuation
   
   DOT3 r5.sat, r4, r1.2x.bias;   # R5 = diffuse (N.L)
   
   MUL r0.rgb, r0, r5;
   MUL r0.rgb.2x, r0, c0;
   MUL r0.rgb, r0, r2.a;         # attenuate
   MUL r0.a, r0, c1;
EndPass;
"
            }
         }
         SetTexture[_MainTex] {combine texture}
         SetTexture[_CubeNormalize] {combine texture}
         SetTexture[_LightTexture0] {combine texture}
      }
      // Back pixel lights with 1 light texture
      Pass {
         Blend SrcAlpha One
         Name "PPL"
         Cull Front
         Tags {
            "LightMode" = "Pixel"
            "LightTexCount" = "1"
         }

CGPROGRAM
#pragma vertex vert
#include "UnityCG.cginc"

uniform float4 _MainTex_ST;
uniform float4x4 _SpotlightProjectionMatrix0;

struct v2f {
   V2F_POS_FOG;
   float2 uv      : TEXCOORD0;
   float3 normal   : TEXCOORD1;
   float3 lightDir   : TEXCOORD2;
   float4 LightCoord0 : TEXCOORD3;
};

v2f vert(appdata_tan v)
{
   v2f o;
   PositionFog( v.vertex, o.pos, o.fog );
   o.normal = -v.normal;
   o.uv = TRANSFORM_TEX(v.texcoord,_MainTex);
   o.lightDir = ObjSpaceLightDir( v.vertex );
   
   o.LightCoord0 = mul(_SpotlightProjectionMatrix0, v.vertex);
   
   return o;
}
ENDCG
         Program "" {
            SubProgram {
               Local 0, [_ModelLightColor0]
               Local 1, [_Color]

"!!ATIfs1.0
StartConstants;
   CONSTANT c0 = program.local[0];
   CONSTANT c1 = program.local[1];
EndConstants;

StartOutputPass;
   SampleMap r0, t0.str;         # main texture
   SampleMap r1, t2.str;         # normalized light dir
   PassTexCoord r4, t1.str;      # normal
   SampleMap r2, t3.str;         # a = attenuation
   
   DOT3 r5.sat, r4, r1.2x.bias;   # R5 = diffuse (N.L)
   
   MUL r0.rgb, r0, r5;
   MUL r0.rgb.2x, r0, c0;
   MUL r0.rgb, r0, r2.a;         # attenuate
   MUL r0.a, r0, c1;
EndPass;
"
            }
         }
         SetTexture[_MainTex] {combine texture}
         SetTexture[_CubeNormalize] {combine texture}
         SetTexture[_LightTexture0] {combine texture}
      }
      
      // Pixel lights with 2 light textures
      Pass {
         Blend SrcAlpha One
         Name "PPL"
         Tags {
            "LightMode" = "Pixel"
            "LightTexCount" = "2"
         }
CGPROGRAM
#pragma vertex vert
#include "UnityCG.cginc"

uniform float4 _MainTex_ST;
uniform float4x4 _SpotlightProjectionMatrix0;
uniform float4x4 _SpotlightProjectionMatrixB0;

struct v2f {
   V2F_POS_FOG;
   float2 uv      : TEXCOORD0;
   float3 normal   : TEXCOORD1;
   float3 lightDir   : TEXCOORD2;
   float4 LightCoord0 : TEXCOORD3;
   float4 LightCoordB0 : TEXCOORD4;
};

v2f vert(appdata_tan v)
{
   v2f o;
   PositionFog( v.vertex, o.pos, o.fog );
   o.normal = v.normal;
   o.uv = TRANSFORM_TEX(v.texcoord,_MainTex);
   o.lightDir = ObjSpaceLightDir( v.vertex );
   
   o.LightCoord0 = mul(_SpotlightProjectionMatrix0, v.vertex);
   o.LightCoordB0 = mul(_SpotlightProjectionMatrixB0, v.vertex);
   
   return o;
}
ENDCG
         Program "" {
            SubProgram {
               Local 0, [_ModelLightColor0]
               Local 1, [_Color]

"!!ATIfs1.0
StartConstants;
   CONSTANT c0 = program.local[0];
   CONSTANT c1 = program.local[1];
EndConstants;

StartOutputPass;
   SampleMap r0, t0.str;         # main texture
   SampleMap r1, t2.str;         # normalized light dir
   PassTexCoord r4, t1.str;      # normal
   SampleMap r2, t3.stq_dq;      # a = attenuation 1
   SampleMap r3, t4.stq_dq;      # a = attenuation 2
   
   DOT3 r5.sat, r4, r1.2x.bias;   # R5 = diffuse (N.L)
   
   MUL r0.rgb, r0, r5;
   MUL r0.rgb.2x, r0, c0;
   MUL r0.rgb, r0, r2.a;         # attenuate
   MUL r0.rgb, r0, r3.a;
   MUL r0.a, r0, c1;
EndPass;
"
            }
         }
         SetTexture[_MainTex] {combine texture}
         SetTexture[_CubeNormalize] {combine texture}
         SetTexture[_LightTexture0] {combine texture}
         SetTexture[_LightTextureB0] {combine texture}
      }
      // Back pixel lights with 2 light textures
      Pass {
         Blend SrcAlpha One
         Name "PPL"
         Cull Front
         Tags {
            "LightMode" = "Pixel"
            "LightTexCount" = "2"
         }
CGPROGRAM
#pragma vertex vert
#include "UnityCG.cginc"

uniform float4 _MainTex_ST;
uniform float4x4 _SpotlightProjectionMatrix0;
uniform float4x4 _SpotlightProjectionMatrixB0;

struct v2f {
   V2F_POS_FOG;
   float2 uv      : TEXCOORD0;
   float3 normal   : TEXCOORD1;
   float3 lightDir   : TEXCOORD2;
   float4 LightCoord0 : TEXCOORD3;
   float4 LightCoordB0 : TEXCOORD4;
};

v2f vert(appdata_tan v)
{
   v2f o;
   PositionFog( v.vertex, o.pos, o.fog );
   o.normal = -v.normal;
   o.uv = TRANSFORM_TEX(v.texcoord,_MainTex);
   o.lightDir = ObjSpaceLightDir( v.vertex );
   
   o.LightCoord0 = mul(_SpotlightProjectionMatrix0, v.vertex);
   o.LightCoordB0 = mul(_SpotlightProjectionMatrixB0, v.vertex);
   
   return o;
}
ENDCG
         Program "" {
            SubProgram {
               Local 0, [_ModelLightColor0]
               Local 1, [_Color]

"!!ATIfs1.0
StartConstants;
   CONSTANT c0 = program.local[0];
   CONSTANT c1 = program.local[1];
EndConstants;

StartOutputPass;
   SampleMap r0, t0.str;         # main texture
   SampleMap r1, t2.str;         # normalized light dir
   PassTexCoord r4, t1.str;      # normal
   SampleMap r2, t3.stq_dq;      # a = attenuation 1
   SampleMap r3, t4.stq_dq;      # a = attenuation 2
   
   DOT3 r5.sat, r4, r1.2x.bias;   # R5 = diffuse (N.L)
   
   MUL r0.rgb, r0, r5;
   MUL r0.rgb.2x, r0, c0;
   MUL r0.rgb, r0, r2.a;         # attenuate
   MUL r0.rgb, r0, r3.a;
   MUL r0.a, r0, c1;
EndPass;
"
            }
         }
         SetTexture[_MainTex] {combine texture}
         SetTexture[_CubeNormalize] {combine texture}
         SetTexture[_LightTexture0] {combine texture}
         SetTexture[_LightTextureB0] {combine texture}
      }
   }
   
   // ------------------------------------------------------------------
   // Radeon 7000
   
   Category {
      Material {
         Diffuse [_Color]
         Emission [_PPLAmbient]
      }
      Lighting On
      Fog { Color [_AddFog] }
      SubShader {
         Pass {
            Blend SrcAlpha OneMinusSrcAlpha
            Name "BASE"
            Cull Off
            Tags {"LightMode" = "PixelOrNone"}
            Color [_PPLAmbient]
            Lighting Off
            SetTexture [_MainTex] {Combine texture * primary DOUBLE}
            SetTexture [_MainTex] {Combine texture * primary DOUBLE}
            SetTexture [_MainTex] {Combine texture * primary DOUBLE, primary * texture}
         }
         Pass {    
            Blend SrcAlpha OneMinusSrcAlpha
            Name "BASE"
            Cull Off
            Tags {"LightMode" = "Vertex"}
            SetTexture [_MainTex] {Combine texture * primary DOUBLE, primary * texture}
         }
         Pass {
            Blend SrcAlpha One
            Name "PPL"
            Cull Off
            Tags {
               "LightMode" = "Pixel"
               "LightTexCount" = "2"
            }
            SetTexture [_LightTexture0]    { combine previous * texture alpha, previous }
            SetTexture [_LightTextureB0]   {
               combine previous * texture alpha + constant, previous
               constantColor [_PPLAmbient]
            }
            SetTexture [_MainTex]    { combine previous * texture DOUBLE, primary * texture}
         }
         Pass {
            Blend SrcAlpha One
            Name "PPL"
            Cull Off
            Tags {
               "LightMode" = "Pixel"
               "LightTexCount"  = "1"
            }
            SetTexture [_LightTexture0] {
               combine previous * texture alpha + constant, previous
               constantColor [_PPLAmbient]
            }
            SetTexture [_MainTex]    { combine previous * texture DOUBLE, primary * texture}
         }
         Pass {
            Blend SrcAlpha One
            Name "PPL"
            Cull Off
            Tags {
               "LightMode" = "Pixel"
               "LightTexCount"  = "0"
            }
            SetTexture [_MainTex]    { combine previous * texture DOUBLE, primary * texture}
         }
      }
      // cull back
      //
   }
}

// Fallback to Alpha Vertex Lit
Fallback "Transparent/VertexLit", 2

}
Добавить foxumkov в Skype
Мои проекты:
Turbodrive
Изображение

Изображение
Аватара пользователя
fox
UNITрон
 
Сообщения: 255
Зарегистрирован: 07 ноя 2008, 13:02
Откуда: Питер
  • ICQ


Вернуться в Shader Lab

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

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