Last active
December 7, 2018 03:24
-
-
Save baobao/0e466334d653d28359fde3314e75d3f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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