Open Eu4ng opened 1 year ago
transparency typically works because z-writing is off for them.
Shader "2D/ScrollingBackground/TextureArray"
{
Properties
{
_MainTex ("Texture Array", 2DArray) = "" {}
_TexCount ("Texture Counts", INT) = 2
[Toggle] _SideScrolling ("Side Scrolling", Range(0, 1)) = 0
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float3 uv : TEXCOORD0;
};
struct v2f
{
float4 vertex : SV_POSITION;
float3 uv : TEXCOORD0;
};
UNITY_DECLARE_TEX2DARRAY(_MainTex);
float4 _MainTex_ST;
int _TexCount;
float _SideScrolling;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
o.uv.xy += _MainTex_ST.zw;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
float3 uv = i.uv;
if(_SideScrolling >= 1)
{
uv.z = floor(fmod(uv.x, _TexCount));
}
else
{
uv.z = floor(fmod(uv.y, _TexCount));
}
return UNITY_SAMPLE_TEX2DARRAY(_MainTex, uv);
}
ENDCG
}
}
}
using UnityEditor;
using UnityEngine;
public class TextureArrayWizard : ScriptableWizard
{
[MenuItem("Assets/Create/Texture Array")]
static void CreateWizard()
{
ScriptableWizard.DisplayWizard<TextureArrayWizard>(
"Create Texture Array", "Create"
);
}
public Texture2D[] textures;
void OnWizardCreate()
{
// 유효성 검사
if (textures.Length == 0) return;
string path = EditorUtility.SaveFilePanelInProject(
"Save Texture Array", "Texture Array", "asset", "Save Texture Array"
);
// 유효성 검사
if (path.Length == 0) return;
Texture2D t = textures[0];
Texture2DArray textureArray = new Texture2DArray(
t.width, t.height, textures.Length, t.format, t.mipmapCount > 1
);
textureArray.anisoLevel = t.anisoLevel;
textureArray.filterMode = t.filterMode;
textureArray.wrapMode = t.wrapMode;
for (int i = 0; i < textures.Length; i++)
{
for (int m = 0; m < t.mipmapCount; m++)
{
Graphics.CopyTexture(textures[i], 0, m, textureArray, i, m);
}
}
AssetDatabase.CreateAsset(textureArray, path);
}
}
Assets > Create > Texture Array (TextureArrayWizard)
머터리얼 생성
스크립트로 머터리얼의 텍스처 Offset 제어
shader_feature 특징 shader_feature에서 미사용 배리언트는 최종빌드에서는 포함되지 않는다.
즉, 빌드 이후 실행할때는 상태를 변경하지 못한다는 것이다.
“multi_compile” 셰이더 배리언트를 사용하면, 이문제를 해결 할 수 있다.
만드는 법
여러 텍스처를 사용하는 셰이더