블로그 이미지
Every unexpected event is a path to learning for you.

카테고리

분류 전체보기 (2738)
Unity3D (817)
Programming (475)
Server (33)
Unreal (4)
Gamebryo (56)
Tip & Tech (228)
협업 (58)
3DS Max (3)
Game (12)
Utility (136)
Etc (96)
Link (32)
Portfolio (19)
Subject (90)
iOS,OSX (53)
Android (14)
Linux (5)
잉여 프로젝트 (2)
게임이야기 (3)
Memories (20)
Interest (38)
Thinking (38)
한글 (30)
PaperCraft (5)
Animation (408)
Wallpaper (2)
재테크 (18)
Exercise (3)
나만의 맛집 (3)
냥이 (10)
육아 (16)
Total
Today
Yesterday
04-30 00:00

Unity Shader Reference

Unity3D/Shader / 2014. 6. 24. 22:32

Link : http://docs.unity3d.com/Manual/SL-Reference.html

반응형

'Unity3D > Shader' 카테고리의 다른 글

Shader Code  (0) 2014.07.16
유니티 셰이더의 기초  (0) 2014.06.28
Rendering Order - Queue tag  (0) 2014.06.24
UnityDiffuseLightmap.shader by jimfleming  (0) 2014.06.23
쉐이더 자료 많은 사이트..  (0) 2014.04.03
Posted by blueasa
, |

Rendering Order - Queue tag

You can determine in which order your objects are drawn using the Queue tag. A Shader decides which render queue its objects belong to, this way any Transparent shaders make sure they are drawn after all opaque objects and so on.

There are four pre-defined render queues, but there can be more queues in between the predefined ones. The predefined queues are:

  • Background - this render queue is rendered before any others. It is used for skyboxes and the like.
  • Geometry (default) - this is used for most objects. Opaque geometry uses this queue.
  • AlphaTest - alpha tested geometry uses this queue. It’s a separate queue from Geometry one since it’s more efficient to render alpha-tested objects after all solid ones are drawn.
  • Transparent - this render queue is rendered after Geometry and AlphaTest, in back-to-front order. Anything alpha-blended (i.e. shaders that don’t write to depth buffer) should go here (glass, particle effects).
  • Overlay - this render queue is meant for overlay effects. Anything rendered last should go here (e.g. lens flares).
Shader "Transparent Queue Example" {
     SubShader {
        Tags {"Queue" = "Transparent" }
        Pass {
            // rest of the shader body...
        }
    }
}

An example illustrating how to render something in the transparent queue

Geometry render queue optimizes the drawing order of the objects for best performance. All other render queues sort objects by distance, starting rendering from the furthest ones and ending with the closest ones.

For special uses in-between queues can be used. Internally each queue is represented by integer index;Background is 1000, Geometry is 2000, AlphaTest is 2450, Transparent is 3000 and Overlay is 4000. If a shader uses a queue like this:

Tags { "Queue" = "Geometry+1" }

This will make the object be rendered after all opaque objects, but before transparent objects, as render queue index will be 2001 (geometry plus one). This is useful in situations where you want some objects be always drawn between other sets of objects. For example, in most cases transparent water should be drawn after opaque objects but before transparent objects.

RenderType tag

RenderType tag categorizes shaders into several predefined groups, e.g. is is an opaque shader, or an alpha-tested shader etc. This is used by Shader Replacement and in some cases used to produce camera’s depth texture.

ForceNoShadowCasting tag

If ForceNoShadowCasting tag is given and has a value of “True”, then an object that is rendered using this subshader will never cast shadows. This is mostly useful when you are using shader replacement on transparent objects and you do not wont to inherit a shadow pass from another subshader.

IgnoreProjector tag

If IgnoreProjector tag is given and has a value of “True”, then an object that uses this shader will not be affected byProjectors. This is mostly useful on semitransparent objects, because there is no good way for Projectors to affect them.

See Also

Passes can be given Tags as well, see Pass Tags.



출처 : http://docs.unity3d.com/Manual/SL-SubshaderTags.html


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


ShaderLab syntax: SubShader Tags

서브 쉐이더는 그들이 렌더링 엔젠으로 렌더되어질 것이 어떻게 그리고 언제 기대될지를 말하는 태그를 사용합니다.

Syntax

Tags { "TagName1" = "Value1" "TagName2" = "Value2}
Value1를 가지는 TagName1 그리고Value2를 가지는 TagName2 를 지정합니다. 사용자는 사용자가 좋아하는 만큼 많은 태그를 가질 수 있습니다.

Details

태그는 기본적으로 키-값 쌍입니다. SubShader 안에서 태그는 렌더링 순서와 서브 쉐이더의 다른 파라미터를 결정하기 위해서 사용됩니다.

Rendering Order - Queue tag

사용자는 사용자의 물체가 Queue 태그를 사용해서 그려지는 순서를 결정할 수 있습니다. 쉐이더는 어떠한 투명한 쉐이더라도 그들이 모든 불투명한 물체들 이후에 그려지는 것을 확실시하는 방법으로 어떤 렌더 큐로 물체가 속하는지를 결정합니다.

4개의 미리 정의된 렌더 큐가 있으나 미리 정의된 것들 사이에는 더 많은 큐가 있을 수 있습니다. 미리 정의된 큐는 다음과 같습니다:

  • Background - 이 렌더 큐는 다른 것들 전에 렌더됩니다. 스카이 박스와 비슷한 것들의 위해 사용됩니다.
  • Geometry (default) - 대부분의 물체를 위해서 사용됩니다. 불투명한 기하가 이 큐를 사용합니다.
  • Transparent - 이 렌더 큐는 기하 이후에 뒤에서 앞으로의 순서대로 그려집니다. 알파 블렌딩되는 어떠한 것(즉. 깊이 버퍼에 쓰여지지 않는 쉐이더)이라도 여기도 가야만 합니다 (유리, 입자 효과).
  • Overlay - 이 렌더 큐는 기하 이후에 뒤에서 앞으로의 순서대로 그려집니다. 알파 블렌딩되는 어떠한 것(즉. 깊이 버퍼에 쓰여지지 않는 쉐이더)이라도 여기도 가야만 합니다 (유리, 입자 효과).
Shader "Transparent Queue Example" {
     SubShader {
        Tags {"Queue" = "Transparent" }
        Pass {
            // rest of the shader body...
        }
    }
} 

투명한 큐에서 렌더하는 법을 설명하는 예

Geometry 렌더 큐는 최고의 성능을 위해서 물체의 그려지는 순서를 최적화 합니다. 모든 다른 렌더 큐는 물체를 거리에 따라 정렬합니다. 먼 것부터 시작해서 가까운 순으로 그려집니다.

특별한 사용을 위해서 큐들 사이에서 사용될 수 있습니다. 내부적으로 각각의 큐는 정수 인덱스에 의해 표현됩니다; Background 은 1000, Geometry 는 2000, Transparent 도는 3000 그리고 오버레이는 4000. 쉐이더가 이것과 같은 큐를 사용한다면:

Tags { "Queue" = "Geometry+1" }

이것은 물체를 모든 불투명 물체 이후에 그러나 투명한 물체를 이전에 렌더 큐 인덱스가 2001일 것처럼 그려지도록 만들 것입니다. 이것은 사용자가 어떠한 물체들을 항상 물체들의 다른 세트들 사이에서 그려지도록 원하는 상황에 유용합니다. 예를 들어, 대부분의 경우에 투명한 물은 불투명한 물체 이후에 그러나 투명한 물체 이전에 그려져야 합니다.

IgnoreProjector tag

IgnoreProjector 태그가 주어지고 "True" 값을 가진다면 그 때 이런 쉐이더를 사용하는 물체는 Projectors에 의해 영향을 받지 않을 것입니다. Projectors가 그들에게 영향을 주는 좋은 방법이 없기 때문에 이것은 주로 반투명한 물체들 위에서 유용합니다.

See Also

패스에 태그 역시 주어질 수 있습니다. Pass Tags를 살펴보시기 바랍니다.


출처 : http://unitykoreawiki.com/index.php?n=KrMain.SL-SubshaderTags

반응형

'Unity3D > Shader' 카테고리의 다른 글

유니티 셰이더의 기초  (0) 2014.06.28
Unity Shader Reference  (0) 2014.06.24
UnityDiffuseLightmap.shader by jimfleming  (0) 2014.06.23
쉐이더 자료 많은 사이트..  (0) 2014.04.03
Toon/Tf2Shader  (0) 2013.07.19
Posted by blueasa
, |

Link : https://gist.github.com/jimfleming/5937437#file-unitydiffuselightmap-shader



Shader "Diffuse Lightmap" {
 
Properties {
_MainTex ("Texture 1", 2D) = "white" {}
}
 
SubShader {
Tags { "RenderType" = "Opaque" }
 
Pass {
// Disable lighting, we're only using the lightmap
Lighting Off
 
CGPROGRAM
// Must be a vert/frag shader, not a surface shader: the necessary variables
// won't be defined yet for surface shaders.
#pragma vertex vert
#pragma fragment frag
 
#include "UnityCG.cginc"
 
struct v2f {
float4 pos : SV_POSITION;
float2 uv0 : TEXCOORD0;
float2 uv1 : TEXCOORD1;
};
 
struct appdata_lightmap {
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
float2 texcoord1 : TEXCOORD1;
};
 
// These are prepopulated by Unity
sampler2D unity_Lightmap;
float4 unity_LightmapST;
 
sampler2D _MainTex;
float4 _MainTex_ST; // Define this since its expected by TRANSFORM_TEX; it is also pre-populated by Unity.
 
v2f vert(appdata_lightmap i) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, i.vertex);
 
// UnityCG.cginc - Transforms 2D UV by scale/bias property
// #define TRANSFORM_TEX(tex,name) (tex.xy * name##_ST.xy + name##_ST.zw)
o.uv0 = TRANSFORM_TEX(i.texcoord, _MainTex);
 
// Use `unity_LightmapST` NOT `unity_Lightmap_ST`
o.uv1 = i.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw;
return o;
}
 
half4 frag(v2f i) : COLOR {
half4 main_color = tex2D(_MainTex, i.uv0);
 
// Decodes lightmaps:
// - doubleLDR encoded on GLES
// - RGBM encoded with range [0;8] on other platforms using surface shaders
// inline fixed3 DecodeLightmap(fixed4 color) {
// #if defined(SHADER_API_GLES) && defined(SHADER_API_MOBILE)
// return 2.0 * color.rgb;
// #else
// return (8.0 * color.a) * color.rgb;
// #endif
// }
 
main_color.rgb *= DecodeLightmap(tex2D(unity_Lightmap, i.uv1));
return main_color;
}
ENDCG
}
}
}



반응형

'Unity3D > Shader' 카테고리의 다른 글

Unity Shader Reference  (0) 2014.06.24
Rendering Order - Queue tag  (0) 2014.06.24
쉐이더 자료 많은 사이트..  (0) 2014.04.03
Toon/Tf2Shader  (0) 2013.07.19
Toon/Basic with Alpha  (0) 2013.07.19
Posted by blueasa
, |


Unity3D 에디터 커스터마이즈 (1)



반응형
Posted by blueasa
, |

ClipboardHelper

Unity3D/Script / 2014. 5. 15. 02:08

출처 : http://answers.unity3d.com/questions/266244/how-can-i-add-copypaste-clipboard-support-to-my-ga.html



  1. // C#
  2. // ClipboardHelper.cs
  3. using UnityEngine;
  4. using System;
  5. using System.Reflection;
  6.  
  7. public class ClipboardHelper
  8. {
  9. private static PropertyInfo m_systemCopyBufferProperty = null;
  10. private static PropertyInfo GetSystemCopyBufferProperty()
  11. {
  12. if (m_systemCopyBufferProperty == null)
  13. {
  14. Type T = typeof(GUIUtility);
  15. m_systemCopyBufferProperty = T.GetProperty("systemCopyBuffer", BindingFlags.Static | BindingFlags.NonPublic);
  16. if (m_systemCopyBufferProperty == null)
  17. throw new Exception("Can't access internal member 'GUIUtility.systemCopyBuffer' it may have been removed / renamed");
  18. }
  19. return m_systemCopyBufferProperty;
  20. }
  21. public static string clipBoard
  22. {
  23. get
  24. {
  25. PropertyInfo P = GetSystemCopyBufferProperty();
  26. return (string)P.GetValue(null,null);
  27. }
  28. set
  29. {
  30. PropertyInfo P = GetSystemCopyBufferProperty();
  31. P.SetValue(null,value,null);
  32. }
  33. }
  34. }


반응형

'Unity3D > Script' 카테고리의 다른 글

Unity Serializer  (0) 2014.09.25
Simple C# Unity Serializer  (0) 2014.09.25
유니티 코루틴 깊이 알고 재미있게 쓰기.  (0) 2014.05.09
ScreenWipe CrossFade with C#  (0) 2014.04.22
A simple cross fade shader for Unity  (0) 2014.04.22
Posted by blueasa
, |


링크 : http://www.slideshare.net/MrDustinLee/ss-33346625

반응형

'Unity3D > Script' 카테고리의 다른 글

Simple C# Unity Serializer  (0) 2014.09.25
ClipboardHelper  (0) 2014.05.15
ScreenWipe CrossFade with C#  (0) 2014.04.22
A simple cross fade shader for Unity  (0) 2014.04.22
어플을 내렸을때, 어플을 종료할때의 처리  (3) 2014.04.04
Posted by blueasa
, |




ScreenWipe_For_CSharp.zip





참조 : http://wiki.unity3d.com/index.php?title=CrossFade


출처 : http://answers.unity3d.com/questions/166898/screenwipe-crossfade-with-c.html

반응형

'Unity3D > Script' 카테고리의 다른 글

ClipboardHelper  (0) 2014.05.15
유니티 코루틴 깊이 알고 재미있게 쓰기.  (0) 2014.05.09
A simple cross fade shader for Unity  (0) 2014.04.22
어플을 내렸을때, 어플을 종료할때의 처리  (3) 2014.04.04
Unity Singleton  (0) 2014.03.24
Posted by blueasa
, |

The other day I was putting some polish to Deathfire‘s character generation and we wanted to fade character portraits from one to another when the player makes his selections. Unlike hard cuts, cross fades simply add a bit of elegance to the program that we did not want to miss.

I went through Unity’s documentation and very quickly came across its Material.Lerp function. Just what I needed, I thought, but after a quick implementation it turned out it didn’t do what I had had in mind. I had not read the function description properly, because what it does, is blend between the parameters of two materials and not the actual image the material creates. Since I am working with a texture atlas, this gave me a cool scrolling effect as my material lerped from one end of the atlas to the other but not the kind of cross fade I had had in mind.

It turns out that Unity doesn’t really have the functionality, so I dug a bit deeper and found Ellen’s approach to blending textures. A quick check of her sources showed me that it still did not do what I wanted, but it gave me a good basis to start from as I began writing my own implement of a simple cross fader.

It all starts with the shader itself, which takes two textures without a normal map and renders them on top of another. A variable tells the shader how transparent the top texture should be so we can adjust it on the fly and gradually blend from the first texture to the second. The key feature for my approach was that the shader uses UV coordinates for each of the textures to allow me to use the shader with a texture atlas.

Shader "CrossFade"
{
  Properties
  {
    _Blend ( "Blend", Range ( 0, 1 ) ) = 0.5
    _Color ( "Main Color", Color ) = ( 1, 1, 1, 1 )
    _MainTex ( "Texture 1", 2D ) = "white" {}
    _Texture2 ( "Texture 2", 2D ) = ""
  }

  SubShader
  {
    Tags { "RenderType"="Opaque" }
    LOD 300
    Pass
    {
      SetTexture[_MainTex]
      SetTexture[_Texture2]
      {
        ConstantColor ( 0, 0, 0, [_Blend] )
        Combine texture Lerp( constant ) previous
      }    
    }
  
    CGPROGRAM
    #pragma surface surf Lambert
    
    sampler2D _MainTex;
    sampler2D _Texture2;
    fixed4 _Color;
    float _Blend;
    
    struct Input
    {
      float2 uv_MainTex;
      float2 uv_Texture2;
    };
    
    void surf ( Input IN, inout SurfaceOutput o )
    {
      fixed4 t1  = tex2D( _MainTex, IN.uv_MainTex ) * _Color;
      fixed4 t2  = tex2D ( _Texture2, IN.uv_Texture2 ) * _Color;
      o.Albedo  = lerp( t1, t2, _Blend );
    }
    ENDCG
  }
  FallBack "Diffuse"
}

The second part of the implementation is the C# script that will drive the actual cross fade. It is pretty straight-forward and consists of an initialization function Start(), an Update() function that is called periodically and adjusts the blend factor for the second texture until the fade is complete. And then, of course, there is a function CrossFadeTo() that you call to set up the respective cross fade.

using UnityEngine;
using System.Collections;

public class CrossFade : MonoBehaviour
{
  private Texture    newTexture;
  private Vector2    newOffset;
  private Vector2    newTiling;
  
  public  float    BlendSpeed = 3.0f;
  
  private bool    trigger = false;
  private float    fader = 0f;
  
  void Start ()
  {
    renderer.material.SetFloat( "_Blend", 0f );
  }
  
  void Update ()
  {
    if ( true == trigger )
    {
      fader += Time.deltaTime * BlendSpeed;
      
      renderer.material.SetFloat( "_Blend", fader );
      
      if ( fader >= 1.0f )
      {
        trigger = false;
        fader = 0f;
        
        renderer.material.SetTexture ("_MainTex", newTexture );
        renderer.material.SetTextureOffset ( "_MainTex", newOffset );
        renderer.material.SetTextureScale ( "_MainTex", newTiling );
        renderer.material.SetFloat( "_Blend", 0f );
      }
    }
  }
  
  public void CrossFadeTo( Texture curTexture, Vector2 offset, Vector2 tiling )
  {
    newOffset = offset;
    newTiling = tiling;
    newTexture = curTexture;
    renderer.material.SetTexture( "_Texture2", curTexture );
    renderer.material.SetTextureOffset ( "_Texture2", newOffset );
    renderer.material.SetTextureScale ( "_Texture2", newTiling );
    trigger = true;
  }
}

The script also contains a public variable called BlendSpeed, which is used to determine how quickly the fade will occur. Smaller numbers will result in slower fades, while larger numbers create more rapid cross fades.

In order to use these scripts, all you have to do is add the shader and the script to your Unity project. Attach the C# script to the object you want to perform the cross fade and then from your application simply call CrossFadeTo() with proper texture parameters to make it happen. That is all there really is to it.


  CrossFade bt = gameObject.GetComponent();
  bt.CrossFadeTo( myTexture, myUVOffset, myScale );

I hope some of you may find this little script useful.

- See more at: http://guidohenkel.com/2013/04/a-simple-cross-fade-shader-for-unity/#comment-125802



출처 : http://networkedblogs.com/Kx9ce

반응형
Posted by blueasa
, |

ObjectPool

Unity3D/Extensions / 2014. 4. 22. 18:02

[File] Unity 5.6.3 기준

ObjectPool_withNGUI.unitypackage



[추가] by blueasa

- NGUI에 쓰기 위해 NGUI 맞게 수정 및 추가(NGUI 3.11.4 기준)

- PreLoad 기능 추가




출처 : http://unitypatterns.com/resource/objectpool/

반응형

'Unity3D > Extensions' 카테고리의 다른 글

Extension Methods  (0) 2014.08.18
Nullable Types  (0) 2014.08.18
인스펙터 상의 GUI를 비활성화 시키고 싶을 때..  (0) 2014.04.02
Save Scene while on play mode  (0) 2014.01.12
Auto-Save Scene on Run  (0) 2014.01.12
Posted by blueasa
, |

static bool BuildAssetBundle(Object mainAsset, Object[] assets, string pathName, uint crcBuildAssetBundleOptionsassetBundleOptions = BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets,BuildTarget targetPlatform = BuildTarget.WebPlayer);

 이 함수를 사용해서 애셋번들을 생성하면 crc값을 얻을 수 있는데요 애셋번들에 포함되어있는 애셋들의 변경 사항이 있는 경우에 저 값이 변하더라고요. 이전에 만든 번들과 crc값이 다르면 수정된거라고 보고 패치를 진행하는 방식으로 구현했습니다.



반응형
Posted by blueasa
, |