TintFinalColor 셰이더.........

 

예제파일이 내 유니티 버전과 마지 않는건지 표면지시자가 없다고 나온다...그래서 걍 내식 대로? 고쳐서 넣었다..... 뭐하러 그리 어려게 작성 한걸까???

 

마찬가지로 버텍스에 포그 컬러 넣는 셰이더도 같은 이유로 작성이 안된다.. 패스...귀찮아 내일 부터는 서피스 라이팅이다~

 

 

Shader "DY/TintFinalColor" {
 Properties{
  _MainTex("Texture",2D)="white"{}
  _ColorTint("Tint",Color)=(1.0,1.0,1.0,1.0)
 }
 SubShader{
  Tags{"RenderType"="Opaque"}
  
  CGPROGRAM
  #pragma surface surf Lambert
  
  struct Input{
   float2 uv_MainTex;
  };
  
  fixed4 _ColorTint;
  sampler2D _MainTex;
  
  void surf (Input IN, inout SurfaceOutput o){
   o.Albedo = tex2D(_MainTex, IN.uv_MainTex).rgb*_ColorTint;
  }

//디퓨즈에 컬러속성을 곱해서 색을 입혀준다..방식은 멀티 플라이라고 보면됨.


  ENDCG
 }
 Fallback"Diffuse"
}

 

 

 

 

 

 

 

 

 

Posted by 프리랜서 디자이너

Normal Extrusion 추가....노멀값을 조절 해 메쉬를 뿔리는 셰이더??? 뿔린 메쉬를 뒤집어 툰셰이딩에 응용한다고도 한다....

 

 

Shader "DY/NormalExtrusion" {
 Properties{
  _MainTex("texture",2D)="white"{}
//  _Amount("Extrusion Amount",Range(-1,1))=0.0
  _Amount("Extrusion Amount",float)=0.0
 }

//슬라이드 조절바가 불편해서 수치 입력으로 바꿨다....


 SubShader{


  Tags{"RanderType"="Opaque"}
  CGPROGRAM
  #pragma surface surf Lambert vertex:vert
  
  struct Input{
   float2 uv_MainTex;
  };
  
  float _Amount;


  void vert (inout appdata_full v){
   v.vertex.xyz +=v.normal * _Amount;
  }

// cg구문에 옵션에 해당하는 구문

//cg에 정의 되있는 Apptata를 활용해 메쉬가 뿔어나 보이게 만들었다...
  
  sampler2D _MainTex;
  
  void surf (Input IN, inout SurfaceOutput o){
   o.Albedo = tex2D(_MainTex,IN.uv_MainTex).rgb;
  }
  ENDCG
 }
 FallBack"Diffuse"
}

 

 

 

 

 

 

 

Custom Vertex Color 추가 ..... 로컬좌표 버텍스에 노멀 컬러를 입혔다...... 어디다 쓰지 ???

 

 

Shader "DY/CustomVertex" {
 properties{
  _MainTex("Texture",2D)="white"{}
 }
 SubShader{
  Tags{"RenderType"="Opaque"}
  
  CGPROGRAM
  #pragma surface surf Lambert vertex:vert
  
  struct Input{
   float2 uv_MainTex;
   float3 customColor;
  };
  
  void vert (inout appdata_full v, out Input o){
   o.customColor = abs(v.normal);
  }

// cg구문에 옵션에 해당하는 구문

//cg에 정의 되있는 Apptata를 활용해 버텍스에 컬러를 입혔다...

//ui쪽엔 버텍스에 컬러 접근해 컬러 바꾸던데... 그런데서나 쓸수 있으려나?
  
  sampler2D _MainTex;
  
  void surf (Input IN, inout SurfaceOutput o){
   o.Albedo = tex2D(_MainTex, IN.uv_MainTex).rgb;
   o.Albedo *= IN.customColor;
  }
  
  ENDCG
 }
 FallBack"Diffuse"
}

 

 

 

 

 

 

 

 

 

 

Posted by 프리랜서 디자이너

Cubemap Reflection 넣기......

 

이번 예제파일을 살짝 변경했다 좀더 쎄게~ 강하게~찐하게~ ㅋㅋ

 

worldRefl 라는 내장 함수를 사용해 간단히 구현한다.... 정말 번거롭지 않게 만들어 놓은 서피스 셰이더....

 

 

Shader "DY/WordRef1"{

 

 Properties{

  _MainTex("Texture",2D) = "white"{}

  _Cube("CubeMap",CUBE) = ""{}

 }

 

 SubShader{

  Tags{"RenderType"="Opaque"}

  CGPROGRAM

  #pragma surface surf Lambert

  

  struct Input{

   float2 uv_MainTex;

   float3 worldRefl;

  };

  //worldRef1 내장 함수 선언 reflect 내장함수와 같은 의미 인듯 하다...

 

  sampler2D _MainTex;

  samplerCUBE _Cube;

  float3 texcol;

  //심심해서 조금 바꿔보려고 변수하나 추가했다

 

  void surf(Input IN, inout SurfaceOutput o){

   texcol = tex2D(_MainTex,IN.uv_MainTex).rgb;

   texcol*=texcol;

//텍스쳐 끼리 곱해 멀티플라이 효과를 준당

 

   o.Albedo = texcol;

   o.Emission = texCUBE(_Cube,IN.worldRefl).rgb;

  }

//Emission 에 큐브를 적용한다 이 Emission을 넣으면 전체적으로 밝아지게됨 빛나보이게하려고 그런거 같다....

 

 

  ENDCG

 }

 Fallback"Diffuse"

}

 

 

 

 

 

Cubemap Reflection 에 Normal Map 추가 하기.....

 

이유는 잘 모르겟으나...(뒤져봐야겠지..)INTERNAL_DATA 는 입력 구조체가 필요하고, 픽셀당 반사벡터에 필요한 내장 함수인 WorldReflectionVector(,) 를 넣어야한다~

 

 

Shader "DY/WordRef1_bump" {

 Properties{
  _MainTex("Texture",2D) = "white"{}
  _Cube("CubeMap",CUBE) = ""{}
  _BumpMap ("Bumpmap", 2D) = "bump" {}
 }
 
 SubShader{
  Tags{"RenderType"="Opaque"}
  CGPROGRAM
  #pragma surface surf Lambert
  
  struct Input{
   float2 uv_MainTex;
   float3 worldRefl;
   float2 uv_BumpMap;
   INTERNAL_DATA

  };
  // INTERNAL_DATA 구조체 추가~ 뭐하는 넘일까...

 


  sampler2D _MainTex;
  samplerCUBE _Cube;
  sampler2D _BumpMap;
  float3 texcol;
  
  void surf(Input IN, inout SurfaceOutput o){
   texcol = tex2D(_MainTex,IN.uv_MainTex).rgb;
   texcol*=texcol;
   o.Albedo = texcol;
   o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));
   o.Emission = texCUBE (_Cube, WorldReflectionVector (IN, o.Normal)).rgb;

  }

//Emission에 WorldReflectionVector 내장 함수를 넣었다....

//이건 픽셀당 반사 백터를 구하기 위한이란다 그러니까 노멀이 들어가서 필요하게된 변수 라는거지


  ENDCG
 }
 Fallback"Diffuse"
}

 

 

 

 

 

 

 

Slices via World Space Position 구현하기....

 

딱히 쓸일이 있을진 모르겠다.....

clip() Cg/HLSL 함수를 사용해서 구현하고 월드 좌표는 내장 함수인 worldPos 변수를 사용한다......

 

Shader"DY/Slices"{

 Properties{

  _MainTex("Texture",2D)="white"{}

  _BumpMap("BumpMap",2D)="Bump"{}

 }

 

 SubShader{

 

  Tags{"RenderType"="Opaque"}

  

  Cull Off

  //메쉬의 뒷면을 살려라!!~~ 라는것

 

  CGPROGRAM

  #pragma surface surf Lambert

  

  struct Input{

   float2 uv_MainTex;

   float2 uv_BumpMap;

   float3 worldPos;

  };

  

  sampler2D _MainTex;

  sampler2D _BumpMap;

  

  void surf (Input IN, inout SurfaceOutput o){

   clip (frac((IN.worldPos.y+IN.worldPos.z*0.1)*5)-0.5);

//함수와 월드 좌표를 이용해 메쉬를 잘라진 것처럼 랜더링 걸어  버린다.

 

   o.Albedo = tex2D(_MainTex, IN.uv_MainTex).rgb;

   o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));

  }

 

  ENDCG

 }

 Fallback"Diffuse"

}

 

 

 

 

 

 

 

 

 

 

Posted by 프리랜서 디자이너

4. Rim Lighting 추가....

 

Shader"DY/surf_ex_004"{

 Properties{

 _MainTex("Texture",2D)="white"{}

 _BumpMap("Bump Map",2D)="bump"{}

 _RimColor("Rim Color",Color)=(0.5,0.5,0.5,0.5)

 _RimPower("Rim Power",Range(0.5,8.0))=3.0

 }

//프로퍼티에 림컬러와 림파워 추가

 

 

 SubShader{

 Tags{"RanderType"="Opaque"}

 

 CGPROGRAM

 #pragma surface surf Lambert

 

 

  struct Input{

   float2 uv_MainTex;

   float2 uv_BumpMap;

   float3 viewDir;

  };

  //인풋에 뷰다이렉션 추가

  

  sampler2D _MainTex;

  sampler2D _BumpMap;

  float4 _RimColor;

  float _RimPower;

//아웃풋에 림컬러와 파워를 전달하기위해 변수 선언

 

  void surf(Input IN, inout SurfaceOutput o){

   o.Albedo = tex2D(_MainTex, IN.uv_MainTex).rgb;

   o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));

   half rim = 1.0 - saturate(dot(normalize(IN.viewDir), o.Normal));

//정규화한 뷰다이렉션과 노멀의 내적을 구하고 1을 넘지한게 세추레이트 함수를 적용 후 뒤집는다.

//림과 림파와를 파워 함수를 적용하고 림컬러와 합성한다.

   o.Emission = _RimColor.rgb*pow(rim,_RimPower);

  }

 ENDCG

 }

 Fallback"Diffuse"

}

 

 

 

5.Detail Texture 추가.....

 

Shader"DY/surf_005"{

 

Properties {
      _MainTex ("Texture", 2D) = "white" {}
      _BumpMap ("Bumpmap", 2D) = "bump" {}
      _Detail ("Detail", 2D) = "gray" {}
    }


    SubShader {
      Tags { "RenderType" = "Opaque" }


      CGPROGRAM
      #pragma surface surf Lambert


      struct Input {
          float2 uv_MainTex;
          float2 uv_BumpMap;
          float2 uv_Detail;
      };


      sampler2D _MainTex;
      sampler2D _BumpMap;
      sampler2D _Detail;


      void surf (Input IN, inout SurfaceOutput o) {
          o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
          o.Albedo *= tex2D (_Detail, IN.uv_Detail).rgb * 2;

          //Albedo를 추가 해 텍스쳐를 멀티플라이형식으로 합성한다. 
          o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));
      }


      ENDCG
    }
    Fallback "Diffuse"
  }

 

 

 


 

 

6. DetailMap screen space...변경 적용

 

Shader"DY/surf_ex_006"{

 

Properties {

      _MainTex ("Texture", 2D) = "white" {}

      _Detail ("Detail", 2D) = "gray" {}

    }

 

    SubShader {

      Tags { "RenderType" = "Opaque" }

 

      CGPROGRAM

      #pragma surface surf Lambert

 

      struct Input {

          float2 uv_MainTex;

          float4 screenPos;

      };

 

      sampler2D _MainTex;

      sampler2D _Detail;

 

      void surf (Input IN, inout SurfaceOutput o) {

          o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;

          float2 screenUV = IN.screenPos.xy / IN.screenPos.w;

          screenUV *= float2(8,6);

    //float2에 스크린XY좌표와 W스케일 받아오기

   //각각 성분에 8,6 을 곱한값이 screenUV 이다.

          o.Albedo *= tex2D (_Detail, screenUV).rgb * 2;

      }

      ENDCG

    }

    Fallback "Diffuse"

  }

 

 

 

 

Posted by 프리랜서 디자이너

서피스 셰이더 공부 시작.....예전에 문서 다 읽어 봤지만 마치 처음 읽어 보는 것 같은 이 이상한 기분..;;;;

 

이번은 서피스 셰이더 예제 따라하기~

 

1. 램버트 라이트 에 색상만 출력하는 초 간단 셰이더

 

Shader "DY/surf_ex_001" {
 SubShader{
  Tags{"RenderType"="Opaque"}
  
  CGPROGRAM
  #pragma surface surf Lambert

//기본으로 지정되있는 램버트 라이트 사용
  
   struct Input {
    float4 color : COLOR;
   };

//인풋은 달랑 색상만 받는다


   void surf (Input IN, inout SurfaceOutput o){
    o.Albedo = 0.5;
   }

//Albedo는 색상(Diffuse) 정하는 구문이고 0.5 는 컬러값 (회색)을 준다.
  ENDCG
  }
  //SubShader
}
//Shader

 

 

 

 

 

==========================================================================================

 

 

2. 텍스쳐 추가...디퓨즈 셰이더

 

Shader "DY/surf_ex_002" {
 Properties{
  _MainTex("Texture",2D)="White"{}
 }
 SubShader{
  Tags{"RanderType"="Opaque"}
  CGPROGRAM
  #pragma surface surf Lambert
  
  struct Input{
   float2 uv_MainTex;
  };
  //인풋에 메인 텍스쳐의 uv정보를 받아온다.


  sampler2D _MainTex;
  //2D텍스쳐를 사용하기 위한 참조.


  void surf(Input IN, inout SurfaceOutput o){
   o.Albedo = tex2D(_MainTex, IN.uv_MainTex).rgb;
  }

//디퓨즈에 해당하는Albedo에 메인 텍스쳐와 인풋의 uv정보를 적용.
  
  ENDCG
 }
 Fallback "Diffuse"

//그래픽카드가 안맞거나 오류가 생기면 디뷰즈 셰이더로 대체.
}

 

 

 

 

 

 

==========================================================================================

 

 

3. 범프맵 추가 ......(사칙연산이 되는구나......좋다! 서피스!!)

 

Shader "DY/surf_ex_003" {
 Properties{
  _MainTex("Texture",2D)="white"{}
  _BumpMap("Bumpmap",2D)="bump"{}
 }
 SubShader{
  Tags{"RanderType"="Opaque"}
  
  CGPROGRAM
  #pragma surface surf Lambert
  
  struct Input{
   float2 uv_MainTex;
   float2 uv_BumpMap;
  };
  //인풋에 범프맵 uv추가.


  sampler2D _MainTex;
  sampler2D _BumpMap;

//범프맵도 2D텍스쳐니까 참조 추가.
  
  void surf(Input IN, inout SurfaceOutput o){
   o.Albedo = tex2D(_MainTex, IN.uv_MainTex).rgb;
   o.Normal = UnpackNormal (tex2D(_BumpMap, IN.uv_BumpMap));
  }

//유니티의 노말압축을 풀어주고(UnpackNormal) 범프맵과 uv정보 적용


  ENDCG
 }
 Fallback"Diffuse"
}


 

 

==========================================================================================

 

 

Posted by 프리랜서 디자이너

이제 뭘 만들어 볼까 하다가 얼마전 회사 셰이더에 플레그먼트로 짜 넣었던 염색 셰이더가 생각이나서

고정함수 셰이더로 만들었다.. 고민고민하다... 알파 테스팅에 패스를 두번그리는걸로 만들었다..

제대로만든건지 몰겠네;; 잘되긴 하는데;;ㅋㅋㅋ

아이퐁에선 투패스가 안그려진다는 말도있던데...뭐 연습이니까..

 

Shader "DY/charTest" {
 Properties {
  _MainTex ("Base", 2D) = "white" {}
  _Color("Color",Color) = (1,1,1,1)
  _TeamColor("TeamColor",Color) = (1,1,1,1)
  _Emission("Emisive Color",Color)=(0,0,0,0)
     _SpecColor("Spec Color",Color)=(1,1,1,1)
     _Shininess("Shininess",Range(0.01,1))= 0.5
 }
 SubShader {

//기본적인 텍스쳐와 라이트를 합성해주는 패스
  pass{
   Material{
    Diffuse[_Color]
    Ambient[_Color]
    Specular[_SpecColor]
    Shininess[_Shininess]
          Emission[_Emission]
   }
   
   Lighting On
   SeparateSpecular On
   
   SetTexture[_MainTex]{
   constantColor[_ConsColor]
    Combine Texture * Primary DOUBLE
    
   }
  }

//알파테스팅을 활용해 염색을 구현해주는 패스
  pass{
   Material{
    Diffuse[_Color]
    Ambient[_Color]
    Specular[_SpecColor]
    Shininess[_Shininess]
          Emission[_Emission]
   }
   
   Lighting On
   SeparateSpecular On
   AlphaTest Greater 0.5
   
   SetTexture[_MainTex]{
   constantColor[_TeamColor]
    Combine Texture * constant
   }
    //알파 테스팅에 라이트 적용을 위한 SetTexture
   SetTexture[_MainTex]{
    Combine previous * primary DOUBLE
   }
  }
  //pass    
 }
 //subShader
}
//Shader

 

 

 

 

Posted by 프리랜서 디자이너

유니티 기반의 라이트맵 모바일 셰이더분석?

 

유니티라이트맵 기번 모바일 셰이더는 유니티에서 만들어 주는 라이트 맵 시스템을 따른다.

그래서 인지 솅;더에 라이트 맵을 따로 넣은  프로퍼티가 없다.

대신 셰이더 코드에서 texcoord를 추가하고 매트릭스를 유니티 라이트 맵으로 지정해준다.

패스는 총 3번을 그려서 적용한다.

 

 

 

// Unlit shader. Simplest possible textured shader.
// - SUPPORTS lightmap
// - no lighting
// - no per-material color

 

Shader "Mobile/Unlit (Supports Lightmap)" {


Properties {
 _MainTex ("Base (RGB)", 2D) = "white" {}
}

 

SubShader {


 Tags { "RenderType"="Opaque" }
 LOD 100
 
 // Non-lightmapped 첫번째 패스는 라이트를 받지않은 기본 텍스쳐만 그리는 패스.
 Pass {
  Tags { "LightMode" = "Vertex" }
  Lighting Off
  SetTexture [_MainTex] { combine texture }
 }
 //pass
 
 // Lightmapped, encoded as dLDR 두번째 패스 라이트맵이 들어 갈수 있는 texcoord를 추가하고 유니티 라이트맵 매트릭스를 적용한다.

//VertexLM: 물체가 조명에 매핑되지 않을 때 Vertex Lit rendering 에서 사용됩니다; lightmap이double-LDR으로 인코딩되는

//플랫폼 (일반적으로 모바일 플랫폼 & 오래된 데스크탑 GPUs).
 Pass {
  Tags { "LightMode" = "VertexLM" }

  Lighting Off
  BindChannels {
   Bind "Vertex", vertex
   Bind "texcoord1", texcoord0 // lightmap uses 2nd uv
   Bind "texcoord", texcoord1 // main uses 1st uv
  }
  
  SetTexture [unity_Lightmap] {
   matrix [unity_LightmapMatrix]
   combine texture
  }
  SetTexture [_MainTex] {
   combine texture * previous DOUBLE, texture * primary
  }
 }
 //pass
 
 // Lightmapped, encoded as RGBM 세번째 패스는 테그에 VertexLMRGBM를 적용하고

//유니티 라이트 맵에 알파를 적용하고, 최종 결과물에 Quad로 어두어진 맵을 밝게 해준다?(테스트를 안해봐서 ㅎㅎ)
 Pass {
  Tags { "LightMode" = "VertexLMRGBM" }
  
  Lighting Off
  BindChannels {
   Bind "Vertex", vertex
   Bind "texcoord1", texcoord0 // lightmap uses 2nd uv
   Bind "texcoord", texcoord1 // main uses 1st uv
  }
  
  SetTexture [unity_Lightmap] {
   matrix [unity_LightmapMatrix]
   combine texture * texture alpha DOUBLE
  }
  SetTexture [_MainTex] {
   combine texture * previous QUAD, texture * primary
  }
 }
 //pass
 

}
//subshader
}
//shader

 

 

 

Posted by 프리랜서 디자이너

blend Test
 
Blend Off
블렌딩 기능 취소
Blend SrcFactor DstFactor
블렌딩을 구성 & 활성화. 생성된 색상은 SrcFactor를 곱합니다. 스크린에 이미 있던 색상은 DstFactor 에 의해 곱해지고 두 개는 함께 더해집니다

Properties

모든 다음의 속성들은SrcFactor와DstFactor 둘 다를 위해서 유효합니다. Source 는 계산되어지는 색상을 의미하고 Destination 는 이미 스크린에 있는 색상을 의미합니다.

One 1의 값 – 소스 또는 데스티네이션 색상이 온전히 오게 합니다.
Zero 0의 값 – 소스 또는데스티네이션 값을 삭제하게 합니다.
SrcColor 이 스테이지의 값은 소스 색상 값에 의해 곱해집니다.
SrcAlpha 이 스테이지의 값은 소스 알파 값에 의해 곱해집니다.
DstColor 이 스테이지의 값은 프레임 버퍼 소스 색상 값에 의해 곱해집니다.
DstAlpha 이 스테이지의 값은 프레임 버퍼 소스 알파 값에 의해 곱해집니다.
OneMinusSrcColor 이 스테이지의 값은 (1 – 소스 색상)에 의해 곱해집니다.
OneMinusSrcAlpha 이 스테이지의 값은 (1 – 소스 알파)에 의해 곱해집니다.
OneMinusDstColor 이 스테이지의 값은 (1 – 데스티네이션 색상)에 의해 곱해집니다.
OneMinusDstAlpha 이 스테이지의 값은 (1 – 데스티네이션 알파)에 의해 곱해집니다.

 

 

오늘은 블랜드모드가 어떻게 적용 되는지 기본적인 모드만 테스트 해 보자 .

 

Blend SrcAlpha OneMinusSrcAlpha     // Alpha blending

 

 

 

 


Blend One One                       // Additive

 

 

 

 


Blend One OneMinusDstColor          // Soft Additive

 

 

 

 


Blend DstColor Zero                 // Multiplicative

 

 

 

 


Blend DstColor SrcColor             // 2x Multiplicative

 

 

 

 

 

--전체 코드--

Shader "Dy/blendTest" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
Tags { "Queue"="Transparent" }

pass{

// Blend SrcAlpha OneMinusSrcAlpha //AlphaBlend
// Blend One One//Additive
// Blend One OneMinusDstColor//Soft Additive
// Blend DstColor Zero//Multiplicative
Blend DstColor SrcColor//2X Multiplicative

Material{
Diffuse[_Color]
}

SetTexture[_MainTex] {
combine texture
}
}
//pass
}
//subshader
}
//shader

**보통 알파블랜드,스크린,멀티 이정도가 가장 많이 쓴이다... 다른걸 궂이 테스트 해볼 필욘 없는건가?**

**버텍스 알파는 어케 되는거지?**

-------------------------------------------------------------------------------------------

 

 

 

 

 

 

알파 블레드가 된 윈도우위에 반사cubemap을 표현

 

에헤~ 지난번  리플렉션에 큐브를 엏었어야 하는구나 에헹~ 그렇구낭

Shader "Dy/blendTest" {
 Properties {
  _Color ("Color",Color) = (1,1,1,1)
  _MainTex ("Base (RGB)", 2D) = "white" {}
  _Reflection ("Base(RGB)Gloss(A)",Cube) = "skybox"{TexGen CubeReflect}
  
 }
 SubShader {
  Tags { "Queue"="Transparent" }
  
  pass{
  
  Lighting On
  Blend SrcAlpha OneMinusSrcAlpha //AlphaBlend
  
   Material{
    Diffuse[_Color]
   }
   
   SetTexture[_MainTex] {
    combine texture * primary DOUBLE , texture *primary
   }
  }
  //pass
  
  pass{
  
  Lighting On
  Blend One One
  
   SetTexture[_Reflection]{
    combine texture
    Matrix[_Reflection]
   }
   
  }
  //pass
 }
 //subshader
}
//shader

 

하! matrix[] 나왔다... 리플렉션, 프로젝션 두군데서 봤는데.. 이거말고 뭐가 더있는지 안 나와있다...

두번째 페스의 라이트를 꺼도 결과는 같다....왜있는거야 ㅡㅡ;;


 

Posted by 프리랜서 디자이너

모바일에 대응 할수있는 가벼운 vertex 셰이더인 유니티 고정 함수 셰이더 이고......

SetTexture 는 이미 적용된 텍스쳐와 빛 기타 결과물을 합성해주는 구문이라고 생각하면 된다.

몇가지 방법을 레퍼런스에서 제시 해 두었는데 어떤 결과인지 예상은 되지만 눈으로 보고 기록을 해두면 더 좋겠지...

 

빛 계산은 별 의미가 없을것 같고 텍스쳐 위주로 합성을 해보자.

모든 material 사용

주광(흰색), 역광(푸른색) 사용

 

////   -------test Set Texture--------

//  combine src1 * src2
  SetTexture[_MainTex]{
   combine Texture * Texture
  }

src1과src2를 함께 곱합니다. 결과는 입력값보다 더 어두울 것입니다.

 

 

 

 


//  combine src1 + src2
  SetTexture[_MainTex]{
   combine Texture + Texture
  }

src1과src2를 함께 더합니다. 결과는 입력값보다 더 밝을 것입니다.

 

 

 

 


//  combine src1 - src2
  SetTexture[_MainTex]{
   combine Texture - Texture
  }

src1에서 src2를 뺍니다.

 

 

 

 


//  combine src1 +- src2
  SetTexture[_MainTex]{
   combine Texture +- Texture
  }

src1과src2를 함께 더하고나서 0.5를 뺍니다 (부호가 적용되는 덧셈).

 

 

 

 


//  combine src1 lerp (src2) src3
  SetTexture[_MainTex]{
   combine Texture * primary
  }
  SetTexture[_Blend]{
   combine Texture lerp (Texture)previous
  }

src2의 알파를 사용해서 src3와src1 사이에서 보간합니다. 보간은 반대 방향임을 주의하시기 바랍니다: 알파가 1일 때src1가 사용되고 알파가 0일 때src3에서 사용됩니다.

 

 

 

 


//  combine src1 * src2 + src3
  SetTexture[_MainTex]{
   combine Texture * Texture + Texture
  }

src1을src2의 알파 컴포넌트에 곱하고 나서 src3을 더합니다.

 

 

 

 


//  combine src1 * src2 +- src3
  SetTexture[_MainTex]{
   combine Texture *Texture +- Texture
  }

 src1을src2의 알파 컴포넌트에 곱하고 나서src3과 함께 부호를 적용하는 덧셈을 합니다.

 

 

 

 


//  combine src1 * src2 - src3
  SetTexture[_MainTex]{
   combine Texture * Texture - Texture
  }

src1을src2의 알파 컴포넌트에 곱하고 나서src3을 뺍니다.

 

 

 

 

 

-결론-

다들 차이가있네... 눈으로 보니까 확실하다 대비, 블랜딩 보간, 발광 기타등등 알파 블랜딩 넣어주면 이팩트 셰이더넹....열라 편하다...ㅎ

 

 

 

-전체 테스트 셰이더 코드-

Shader "FF/SetTest" {
 Properties {
  _Color("Color",Color)=(1,1,1,0)
  _MainTex ("Base (RGB)", 2D) = "white" {}
  _Blend("Blend(RGBA)",2D) = "White"{}
  _SpecColor("SpecColor",Color)=(1,1,1,1)
  _Shininess("Shininess",Range(0.01,1))=0.5
  _Emission("Emission",Color)=(0,0,0,0)
 }
 SubShader {
 
  pass{
  Lighting On
  SeparateSpecular On
  
  Material{
   Diffuse[_Color]
   Ambient[_Color]
   Specular[_SpecColor]
   Shininess[_Shininess]
   Emission[_Emission]
  }
////   -------test Set Texture--------

////  combine src1 * src2
//  SetTexture[_MainTex]{
//   combine Texture * Texture
//  }
////  combine src1 + src2
//  SetTexture[_MainTex]{
//   combine Texture + Texture
//  }
////  combine src1 - src2
//  SetTexture[_MainTex]{
//   combine Texture - Texture
//  }
////  combine src1 +- src2
//  SetTexture[_MainTex]{
//   combine Texture +- Texture
//  }
////  combine src1 lerp (src2) src3
//  SetTexture[_MainTex]{
//   combine Texture * primary
//  }
//  SetTexture[_Blend]{
//   combine Texture lerp (Texture)previous
//  }
////  combine src1 * src2 + src3
//  SetTexture[_MainTex]{
//   combine Texture * Texture + Texture
//  }
////  combine src1 * src2 +- src3
//  SetTexture[_MainTex]{
//   combine Texture *Texture +- Texture
//  }
////  combine src1 * src2 - src3
  SetTexture[_MainTex]{
   combine Texture * Texture - Texture
  }
//
  }//pass
 }//subshader
}//shader

 

 

 

 

 

 

 

 

 

Posted by 프리랜서 디자이너

헐.... 레퍼런스 뒤져보고 리플렉션을 알파값을 넣었다.....이제 뭘하지?????

레퍼런스에 나와인는 메트리얼도 저게 다고 검색해도 안나오네;;;; 셰이더 1.1 대응이라 할수있는게 없나보네...

use pass 쓸거면 서피스로 해도되니 안쓸거고...

좀더 검색해보고 없음 이팩트 셰이더나 몇개 해보고 서피스로 넘어가야겠네...... 정말 이게 다양?? ㅜㅜ

 

 

 

Shader "dy_shader/fixed_char_01" {

    Properties {
     _Color("Main Color",Color)= (1,1,1,0)
     _MainTex("Main Tex",2D)="White"{}
     _Emission("Emisive Color",Color)=(0,0,0,0)
     _SpecColor("Spec Color",Color)=(1,1,1,1)
     _Shininess("Shininess",Range(0.01,1))= 0.5
     _Reflect("ReflectTex",2D)="White"{}
    }
   
    SubShader {
        Pass {
       
         Lighting On
         SeparateSpecular On
         
         Material{
          Diffuse[_Color]
          Ambient[_Color]
          Shininess[_Shininess]
          Specular[_SpecColor]
          Emission[_Emission]
         }
         
         SetTexture [_MainTex] {
            combine texture * primary, texture * primary
            }
           
         SetTexture[_Reflect]{
          Combine texture + previous
         }
        }
        //End Pass
 }
    //SubShader
}
//Shader

 

 

 

 

Posted by 프리랜서 디자이너

유니티 고정 함수로 셰이더 만드는 공부..... 이 녀석을 베이스로  이런 저런 fixed shader를 만들어갈 계획... 부디 자료가 많기를...오늘은 시간이 없어서 여기까지...

 

Shader "dy_shader/fixed_char_01" {

    Properties {
     _Color("Main Color",Color)= (1,1,1,0)
     _MainTex("Main Tex",2D)="White"{}
     _Emission("Emisive Color",Color)=(0,0,0,0)
     _SpecColor("Spec Color",Color)=(1,1,1,1)
     _Shininess("Shininess",Range(0.01,1))= 0.5
    }
   
    SubShader {
  //----------vertex Light base shader START--------------
        Pass {
       
         Lighting On
         SeparateSpecular On
         
         Material{
          Diffuse[_Color]
          Ambient[_Color]
          Shininess[_Shininess]
          Specular[_SpecColor]
          Emission[_Emission]
         }
         
         SetTexture[_MainTex]{
          Combine texture * primary DOUBLE, texture * primary
         }
       
        }
        //Pass
        //----------vertex Light base shader END--------------
    }
    //SubShader
}
//Shader

 

 

Posted by 프리랜서 디자이너
  1. 2012/07/09ShaderFX를 이용한, 그래픽 디자이너를 위한 기초 쉐이더 강좌 13강
  2. 2012/05/21ShaderFX를 이용한, 그래픽 디자이너를 위한 기초 쉐이더 강좌 12강(2)
  3. 2012/05/15ShaderFX를 이용한, 그래픽 디자이너를 위한 기초 쉐이더 강좌 11강
  4. 2012/05/03ShaderFX를 이용한, 그래픽 디자이너를 위한 기초 쉐이더 강좌 10강(4)
  5. 2012/03/31ShaderFX를 이용한, 그래픽 디자이너를 위한 기초 쉐이더 강좌 9강
  6. 2012/03/14ShaderFX를 이용한, 그래픽 디자이너를 위한 기초 쉐이더 강좌 8강
  7. 2012/03/03ShaderFX를 이용한, 그래픽 디자이너를 위한 기초 쉐이더 강좌 7강(2)
  8. 2012/02/18ShaderFX를 이용한, 그래픽 디자이너를 위한 기초 쉐이더 강좌 6강(2)
  9. 2012/02/03ShaderFX를 이용한, 그래픽 디자이너를 위한 기초 쉐이더 강좌 5강(2)
  10. 2012/01/31ShaderFX를 이용한, 그래픽 디자이너를 위한 기초 쉐이더 강좌 4강(2)
  11. ShaderFX를 이용한, 그래픽 디자이너를 위한 기초 쉐이더 강좌 3강 (4)
  12. ShaderFX를 이용한, 그래픽 디자이너를 위한 기초 쉐이더 강좌 2강 (2)
  13. ShaderFX를 이용한, 그래픽 디자이너를 위한 기초 쉐이더 강좌 1강 (6)

 

Posted by 프리랜서 디자이너