Instantly share code, notes, and snippets.

Embed
What would you like to do?
Scripts for saving parameters for Additive Shader mod.
// Additive Shader Scripts
//
// For Props and Vehicle Sub Meshes
//
// Mod not required for running the scripts and saving the asset.
// Removes LOD completely, as the shader doesn't work for LOD.
//
// Additive Shader Prop
var timeOn = 22.0f; // 24H time of day at which light turns on
var timeOff = 6.0f; // 24H time of day at which light turns off
var fade = 20.0f; // fading area around other objects, 0.5 a lot, 1 default, 10+ basically none
var intensity = 1.0f; // light multiplier, below 1 darker, 1 default, 1+ may bloom
var shader = Shader.Find("Custom/Particles/Additive (Soft)");
var asset = ToolsModifierControl.toolController.m_editPrefabInfo as PropInfo;
if(asset.m_material != null) asset.m_material.shader = shader;
asset.m_material.SetFloat("_Intensity", intensity);
asset.m_material.SetFloat("_InvFade", fade);
asset.m_mesh.name="AdditiveShader "+timeOn.ToString("R")+" "+timeOff.ToString("R")+" "+fade.ToString("R")+" "+intensity.ToString("R");
asset.m_lodMesh = null;
asset.m_lodMaterial = null;
asset.m_lodMaterialCombined = null;
asset.m_lodObject = null;
// Additive Shader Vehicle Sub Mesh
var timeOn = 22.0f; // 24H time of day at which light turns on
var timeOff = 6.0f; // 24H time of day at which light turns off
var fade = 20.0f; // fading area around other objects, 0.5 a lot, 1 default, 10+ basically none
var intensity = 3.0f; // light multiplier, below 1 darker, 1 default, 1+ may bloom
var submesh = 1; // sub mesh id, order as in the ui, starting from 1
var shader = Shader.Find("Custom/Particles/Additive (Soft)");
var asset = ToolsModifierControl.toolController.m_editPrefabInfo as VehicleInfo;
if(asset.m_subMeshes[submesh].m_subInfo.m_material != null) asset.m_subMeshes[submesh].m_subInfo.m_material.shader = shader;
asset.m_subMeshes[submesh].m_subInfo.m_material.SetFloat("_Intensity", intensity);
asset.m_subMeshes[submesh].m_subInfo.m_material.SetFloat("_InvFade", fade);
asset.m_subMeshes[submesh].m_subInfo.m_mesh.name="AdditiveShader "+timeOn.ToString("R")+" "+timeOff.ToString("R")+" "+fade.ToString("R")+" "+intensity.ToString("R");
Vector3[] vertices = asset.m_subMeshes[submesh].m_subInfo.m_mesh.vertices;
Color[] colors = new Color[vertices.Length];
for(int i = 0; i < vertices.Length; i++) colors[i] = Color.white;
asset.m_subMeshes[submesh].m_subInfo.m_mesh.colors = colors;
asset.m_subMeshes[submesh].m_subInfo.m_lodMesh = null;
asset.m_subMeshes[submesh].m_subInfo.m_lodMaterial = null;
asset.m_subMeshes[submesh].m_subInfo.m_lodMaterialCombined = null;
asset.m_subMeshes[submesh].m_subInfo.m_lodObject = null;
// Additive Shader Building
// HIGHLY NOT RECOMMENDED (limited render distance or very weird problems, use props instead)
var timeOn = 22.0f; // 24H time of day at which light turns on
var timeOff = 6.0f; // 24H time of day at which light turns off
var fade = 20.0f; // fading area around other objects, 0.5 a lot, 1 default, 10+ basically none
var intensity = 1.0f; // light multiplier, below 1 darker, 1 default, 1+ may bloom
var shader = Shader.Find("Custom/Particles/Additive (Soft)");
var asset = ToolsModifierControl.toolController.m_editPrefabInfo as BuildingInfo;
if(asset.m_material != null) asset.m_material.shader = shader;
asset.m_material.SetFloat("_Intensity", intensity);
asset.m_material.SetFloat("_InvFade", fade);
asset.m_mesh.name="AdditiveShader "+timeOn.ToString("R")+" "+timeOff.ToString("R")+" "+fade.ToString("R")+" "+intensity.ToString("R");
asset.m_lodMesh = null;
asset.m_lodMaterial = null;
asset.m_lodMaterialCombined = null;
asset.m_lodObject = null;
// Additive Shader Building Sub Mesh
// HIGHLY NOT RECOMMENDED (limited render distance or very weird problems, use props instead)
var timeOn = 22.0f; // 24H time of day at which light turns on
var timeOff = 6.0f; // 24H time of day at which light turns off
var fade = 20.0f; // fading area around other objects, 0.5 a lot, 1 default, 10+ basically none
var intensity = 2.0f; // light multiplier, below 1 darker, 1 default, 1+ may bloom
var submesh = 0; // sub mesh id, order as in the ui, starting from 0
var shader = Shader.Find("Custom/Particles/Additive (Soft)");
var asset = ToolsModifierControl.toolController.m_editPrefabInfo as BuildingInfo;
if(asset.m_subMeshes[submesh].m_subInfo.m_material != null) asset.m_subMeshes[submesh].m_subInfo.m_material.shader = shader;
asset.m_subMeshes[submesh].m_subInfo.m_material.SetFloat("_Intensity", intensity);
asset.m_subMeshes[submesh].m_subInfo.m_material.SetFloat("_InvFade", fade);
asset.m_subMeshes[submesh].m_subInfo.m_mesh.name="AdditiveShader "+timeOn.ToString("R")+" "+timeOff.ToString("R")+" "+fade.ToString("R")+" "+intensity.ToString("R");
Vector3[] vertices = asset.m_subMeshes[submesh].m_subInfo.m_mesh.vertices;
Color[] colors = new Color[vertices.Length];
for(int i = 0; i < vertices.Length; i++) colors[i] = Color.white;
asset.m_subMeshes[submesh].m_subInfo.m_mesh.colors = colors;
asset.m_subMeshes[submesh].m_subInfo.m_lodMesh = null;
asset.m_subMeshes[submesh].m_subInfo.m_lodMaterial = null;
asset.m_subMeshes[submesh].m_subInfo.m_lodMaterialCombined = null;
asset.m_subMeshes[submesh].m_subInfo.m_lodObject = null;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment