본문 바로가기
Shader

Shader.PropertyToID

by 대마왕J 2021. 2. 9.

docs.unity3d.com/kr/530/ScriptReference/Shader.PropertyToID.html

 

Unity - 스크립팅 API: Shader.PropertyToID

프로퍼티 식별자들을 사용하것은 모든 메터리얼 프로퍼티 함수에 문자열을 전달하는 것보다 더 효율적입니다. 예를들어 Material.SetColor를 자주 호출하거나, MaterialPropertyBlock 사용하는 경우, 다음

docs.unity3d.com

프로퍼티 이름에서 고유 ID를 가져옵니다.

프로퍼티 식별자들을 사용하것은 모든 메터리얼 프로퍼티 함수에 문자열을 전달하는 것보다 더 효율적입니다. 예를들어 Material.SetColor를 자주 호출하거나, MaterialPropertyBlock 사용하는 경우, 다음은 한 번에 필요로 하는 프로퍼티 식별자를 얻도록하는 것이 더 좋습니다.

프로퍼티 이름은, 게임 전체에서 동일한 독특한 정수값이 할당되어 있습니다. (예를 들면, _MainTex  _Color)

 

public static int PropertyToID(string name);

Parameters

name Shader property name.

Returns

int Unique integer for the name. 이름에서 유니크한 인티져를 가져온다 

Description

Gets unique identifier for a shader property name.

Using property identifiers is more efficient than passing strings to all material property functions. For example if you are calling Material.SetColor a lot, or using MaterialPropertyBlock, then it is better to get the identifiers of the properties you need just once. 

자주 셋칼라를 부를때나 메터리얼 프로퍼티 블럭을 사용할때에는 더 효율적이다. 

Each name of shader property (for example, _MainTex or _Color) is assigned an unique integer number in Unity, that stays the same for the whole game. The numbers will not be the same between different runs of the game or between machines, so do not store them or send them over network.

어느 머신이나 게임 심지어 네트웍에도 같기 때문에 네트웍으로 저장하거나 보낼 필요도 없다. 

 

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

문자열로 찾는 것 보다. 이런식으로 아이디를 할당하는 것이 더 낫다는 말. 최적화에 대한 문제인듯 하다 

private static readonly int reflectionTexString = Shader.PropertyToID("_ReflectionTex");

이런식으로 정의해 놓는 것. 이러면 저 이름을 int 로 저장한다고 한다. 번호로 저장한단 말이지

 

나중에

  material.SetTexture(reflectionTexStringreflectionTexture);

처럼 사용한다. 

 

반응형

'Shader ' 카테고리의 다른 글

Texcoord. xyzw와 UV1, UV2와의 관계  (1) 2021.02.11
돋보기 효과 만들기  (0) 2021.02.11
URP Position Transform  (0) 2021.01.27
외부 오브젝트의 값을 셰이더에 넘겨주기  (1) 2021.01.27
GetVertexPositionInputs  (1) 2020.12.14

댓글