Skip to content

Instantly share code, notes, and snippets.

@baobao
Last active December 7, 2018 03:24
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PropertyToIdPerformance : MonoBehaviour
{
public Material mat;
public bool toggle;
public int cnt = 5000;
int propId = 0;
void Awake()
{
// プロパティユニークIDの取得
propId = Shader.PropertyToID("_Test");
}
void Update ()
{
for (int i = 0; i < cnt; i++)
{
if (toggle) {
mat.SetFloat(propId, 100);
} else {
mat.SetFloat("_Test", 100);
}
}
}
}
Shader "Custom/PropertyToIdPerformance"
{
Properties
{
_Test("Test", Float) = 0
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert_img
#pragma fragment frag
#include "UnityCG.cginc"
fixed4 frag (v2f_img i) : SV_Target
{
return fixed4(1,1,1,1);
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment