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

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

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

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

 

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 프리랜서 디자이너