Skip to content

Instantly share code, notes, and snippets.

@baobao
Last active December 7, 2018 03:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baobao/0e466334d653d28359fde3314e75d3f2 to your computer and use it in GitHub Desktop.
Save baobao/0e466334d653d28359fde3314e75d3f2 to your computer and use it in GitHub Desktop.
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