Shaders and Materials

Abhishek Smith

Abhishek Smith

Building Outscal | Land Jobs in the gaming industry | EA, Epic Games, TCS, | CMU, IIT K

Basic Material Properties

  • material.color = Simple color setting
  • material.mainTexture = Main texture assignment
  • material.shader = Shader selection
  • Don't modify these every frame - breaks batching!

Custom Shader Properties

  • SetColor() for specific color properties
  • SetTexture() for custom texture maps
  • SetFloat() for numeric properties (transparency, gloss)
  • SetVector() for Vector3/Vector4 properties
  • Perfect for controlled material modifications

Performance Heroes

  • EnableInstancing for reduced draw calls
  • Proper render queue management for layered effects
  • Shader.WarmupAllShaders() prevents stutters
  • Avoid per-frame property changes
  • Never use Shader.Find() in Update()

Global Shader Control

  • SetGlobalFloat() affects all shaders at once
  • SetGlobalColor() perfect for day/night cycles
  • Override tags for custom rendering passes
  • Efficient for system-wide visual effects

Pro Tips:

  • Cache material references in Awake()
  • Use Shader.PropertyToID to avoid string lookups
  • Enable GPU instancing for repeated meshes
  • Warm up shaders during load screens
  • Use MaterialPropertyBlock for instance variations

Common Pitfalls:

  • Excessive runtime material creation (use sparingly!)
  • Modifying shared materials affects ALL instances
  • Memory leaks from undisposed runtime materials
  • Heavy emission effects on mobile platforms
  • Untested shader compatibility across devices

Show More