Рубрики
CgFx Unity Texture Examples "ShaderLab (CgFx,HLSL)" Surface HLSL

Шейдер «Срез Текстуры»

Shader "Custom/World/Cut"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
	_pov("pov", int) = 0
        _pos("Vector",vector) = (0,0,0,0)
    }
    SubShader
    {
    CGPROGRAM
    //surface
    #pragma surface surf Lambert
    //model
    #pragma target 3.0
    //vars
    sampler2D _MainTex;

    int _pov;
    fixed4 _pos;

    struct Input
    {
        float2 uv_MainTex;
        float3 worldPos;
    };

    void surf(Input IN, inout SurfaceOutput o)
    {
        switch (_pov)
        {
        case 0:
            clip(IN.worldPos.z > _pos.z ? 1 : -1);
            break;
        case 1:
            clip(IN.worldPos.x < _pos.x ? 1 : -1);
            break;
        case 2:
            clip(IN.worldPos.z > _pos.z ? 1 : -1);
            break;
        case 3:
            clip(IN.worldPos.x < _pos.x ? 1 : -1);
            break;
        }

        o.Albedo = tex2D(_MainTex, IN.uv_MainTex).rgb;
    }
    ENDCG
}
FallBack "Diffuse"
}

Рубрики
Unity ShaderLab "Основы"

Структура обёртки «ShaderLab»

Shader "Name" 
{ 
[Properties]
CGINCLUDE
Код на языке CG 
ENDCG 
SubShader
{
CGPROGRAM  
Код на языке CG  
ENDCG
} 
[Fallback] 
}
Рубрики
Unity Unity.GameObject.Component.Material "Shader"

Перевод float X в int X

Shader

struct appdata
{
float4 texcoord: TEXCOORD0;
};         
void vert(inout appdata v,out Input o)
{
UNITY_INITIALIZE_OUTPUT(Input, o);
o.tex = v.texcoord;
}
struct Input
{
float2 UV;
};
void surf(Input IN, inout SurfaceOutput o)
{ float X = IN.UV.x }
int x=(int)(X+0.001)int x=(int)(X)float x
clip(x ==7 ? 1 : -1)+
clip(x >5.9 && x < 7.1 ? 1 : -1)+++
clip(x > 6.99f && x < 7.01 ? 1 : -1)++
пример вёрстки UV=new Vector2(7,0) и выполнения кода при переводе float X в int X

Рубрики
Unity Unity.GameObject.Component.Material "Shader" ShaderLab "EXAMPLE"

Unity Shader Debugging

Пример вывода данных из Shader