Skip to content

Instantly share code, notes, and snippets.

@kimsama
Created March 25, 2016 03:52
Show Gist options
  • Select an option

  • Save kimsama/c442b13957d092c1493a to your computer and use it in GitHub Desktop.

Select an option

Save kimsama/c442b13957d092c1493a to your computer and use it in GitHub Desktop.
http://forum.unity3d.com/threads/standard-shader-how-to-add-lightmap-from-3dsmax-on-uv2.278166/#post-1923095 Modifying the Standard shader is not a way to fix it. Lightmaps should go where they belong and that is the LightmapSettings.lightmaps array. A specific Renderer can then use a lightmap by using its index (Renderer.lightmapIndex) and then…
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
public class SetLightmapsManually : MonoBehaviour
{
public int m_lightmapIndex = 255;
public float m_lightmapTilingX = 1f;
public float m_lightmapTilingY = 1f;
public float m_lightmapOffsetX = 0f;
public float m_lightmapOffsetY = 0f;
public bool m_setLightmapValues = false;
public Texture2D[] m_lightmapArray;
public bool m_setLightmapArray = false;
void Update ()
{
if (m_setLightmapValues)
{
m_setLightmapValues = false;
Renderer r;
if (r = GetComponent<Renderer>())
{
r.lightmapIndex = m_lightmapIndex;
r.lightmapScaleOffset = new Vector4(m_lightmapTilingX, m_lightmapTilingY, m_lightmapOffsetX, m_lightmapOffsetY);
}
}
if (m_setLightmapArray)
{
m_setLightmapArray = false;
if (m_lightmapArray.Length > 0)
{
LightmapData[] lightmapData = new LightmapData[m_lightmapArray.Length];
for (int i=0; i<lightmapData.Length; i++)
{
lightmapData[i] = new LightmapData();
lightmapData[i].lightmapFar = m_lightmapArray[i];
}
LightmapSettings.lightmaps = lightmapData;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment