Added Fog and other fixes

This commit is contained in:
2026-07-06 18:01:21 +03:00
parent fc837b2f9a
commit 72b48492cc
573 changed files with 397423 additions and 104 deletions
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: de51b6c800c0cee4bbfc508637635830
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,107 @@
using UnityEditor;
using UnityEngine;
namespace Mirza.VFXToolKit
{
[CustomEditor(typeof(MVFXTK_LiveRenderTexture))]
public class MVFXTK_LiveRenderTextureEditor : Editor
{
//public bool squareAspectRatioPreview;
private MaterialEditor materialEditor;
void OnEnable()
{
// Subscribe to Editor update for continuous refresh.
EditorApplication.update += Repaint;
}
void OnDisable()
{
// Unsubscribe to prevent memory leaks.
EditorApplication.update -= Repaint;
}
public override void OnInspectorGUI()
{
// Reference target component.
MVFXTK_LiveRenderTexture manager = (MVFXTK_LiveRenderTexture)target;
// Draw default inspector.
DrawDefaultInspector();
// Custom inspector.
//EditorGUILayout.Space();
//EditorGUILayout.LabelField("Custom Editor", EditorStyles.boldLabel);
//squareAspectRatioPreview = EditorGUILayout.Toggle("Square Aspect Ratio Preview", squareAspectRatioPreview);
// Preview if exists.
if (manager.renderTexture != null)
{
EditorGUILayout.Space();
EditorGUILayout.LabelField($"Render Texture Preview ({manager.renderTexture.width} x {manager.renderTexture.height})", EditorStyles.boldLabel);
// Keep texture square.
float renderTextureAspect;
//if (squareAspectRatioPreview)
//{
// renderTextureAspect = 1.0f;
//}
//else
//{
// Use the non-overridden resolution for preview.
// Reason: with an override, the aspectio ratio may be too extreme.
renderTextureAspect = manager.aspectResolution.x / (float)manager.aspectResolution.y;
//}
// Render.
EditorGUI.DrawPreviewTexture(GUILayoutUtility.GetAspectRect(renderTextureAspect), manager.renderTexture);
}
else
{
EditorGUILayout.HelpBox("No render texture to preview.", MessageType.Info);
}
// If material exists, allow editing and preview.
if (manager.updateMaterial != null)
{
EditorGUILayout.Space();
EditorGUILayout.LabelField("Material Settings", EditorStyles.boldLabel);
// Check if MaterialEditor needs to be created or updated.
if (materialEditor == null || materialEditor.target != manager.updateMaterial)
{
materialEditor = (MaterialEditor)CreateEditor(manager.updateMaterial);
}
// Render MaterialEditor.
materialEditor.DrawHeader();
materialEditor.OnInspectorGUI();
// Show preview of material.
Rect materialPreviewRect = GUILayoutUtility.GetRect(100, 100);
EditorGUI.DrawPreviewTexture(materialPreviewRect, Texture2D.whiteTexture, manager.updateMaterial);
}
else
{
EditorGUILayout.HelpBox("No update material assigned for editing.", MessageType.Info);
}
}
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: d6ae5ade674ee3a419b9516deb4e035c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 277702
packageName: AERO - Volumetric Fog and Mist
packageVersion: 1.8.0
assetPath: Assets/Mirza/_VFXToolkit/_Demo/Scripts/Editor/MVFXTK_LiveRenderTextureEditor.cs
uploadId: 933120
@@ -0,0 +1,46 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Mirza.VFXToolKit
{
public class MFXTK_AnimateMaterialUV : MonoBehaviour
{
Material material;
public Vector2 animation = new(0.0f, 0.5f);
public string propertyName = "_MainTex";
[Space]
public bool sharedMaterial;
Vector2 startOffset;
void Start()
{
if (!sharedMaterial)
{
material = GetComponent<Renderer>().material;
}
else
{
material = GetComponent<Renderer>().sharedMaterial;
}
startOffset = material.GetTextureOffset(propertyName);
}
void OnDisable()
{
material.SetTextureOffset(propertyName, startOffset);
}
void Update()
{
Vector2 offset = material.GetTextureOffset(propertyName);
offset += animation * Time.deltaTime;
material.SetTextureOffset(propertyName, offset);
}
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 60f2081901e2c5041b1bd1aa0c48450e
AssetOrigin:
serializedVersion: 1
productId: 277702
packageName: AERO - Volumetric Fog and Mist
packageVersion: 1.8.0
assetPath: Assets/Mirza/_VFXToolkit/_Demo/Scripts/MFXTK_AnimateMaterialUV.cs
uploadId: 933120
@@ -0,0 +1,142 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Mirza.VFXToolKit
{
public class MFXTK_CameraController : MonoBehaviour
{
public bool dragEnabled = true;
[Space]
public float speed = 2.0f;
public float lerpSpeed = 10.0f;
[Space]
public Vector2 rotateAroundYRange = new(25.0f, -25.0f);
public Vector2 rotateAroundXRange = new(12.5f, -12.5f);
[Space]
public Vector2 zoomRange = new(-4.0f, -2.5f);
[Space]
public float zoomLerpSpeed = 20.0f;
public float zoomStep = 0.5f;
float currentZoom;
[Space]
public Transform zoomTransform;
Vector3 currentEulerAngles;
Quaternion targetRotation;
bool focusEnabledThisFrame;
bool previouslyFocused;
void Start()
{
targetRotation = transform.localRotation;
currentEulerAngles = targetRotation.eulerAngles;
currentZoom = zoomTransform.localPosition.z;
}
// ...
public void OnBeginDrag()
{
dragEnabled = true;
}
public void OnEndDrag()
{
dragEnabled = false;
}
// ...
void Update()
{
bool isFocused = Application.isFocused;
focusEnabledThisFrame = isFocused && !previouslyFocused;
// Early out if legacy input manager is disabled.
// -- (required, else there will be an error on play).
#if !ENABLE_LEGACY_INPUT_MANAGER
return;
#endif
// Rotate.
if (dragEnabled && Input.GetMouseButton(0))
{
Vector2 mouse = Vector2.zero;
mouse.x = Input.GetAxisRaw("Mouse X");
mouse.y = Input.GetAxisRaw("Mouse Y");
// Prevent annoying sudden and large mouse values (especially in the editor).
// > From returning to game view/window after clicking around the editor.
if (focusEnabledThisFrame)
{
mouse = Vector2.zero;
}
mouse *= speed;
currentEulerAngles.x -= mouse.y;
currentEulerAngles.y += mouse.x;
//currentEulerAngles.x = Mathf.Clamp(currentEulerAngles.x, rotateAroundXRange.x, rotateAroundXRange.y);
//currentEulerAngles.y = Mathf.Clamp(currentEulerAngles.y, rotateAroundYRange.x, rotateAroundYRange.y);
targetRotation = Quaternion.Euler(currentEulerAngles);
}
transform.localRotation = Quaternion.Lerp(transform.localRotation, targetRotation, Time.deltaTime * lerpSpeed);
// Zoom. Only if mouse in viewport of main camera.
// -- (fixes annoying issue of mouse-wheel'ing outside game window changing zoom...).
// Check if mouse is in normalized viewport range [0.0, 1.0].
Vector2 mousePositionInViewport = Camera.main.ScreenToViewportPoint(Input.mousePosition);
bool isMouseInsideViewPort =
(mousePositionInViewport.x > 0.0f && mousePositionInViewport.x < 1.0f) &&
(mousePositionInViewport.y > 0.0f && mousePositionInViewport.y < 1.0f);
if (isMouseInsideViewPort)
{
float scroll = Input.GetAxis("Mouse ScrollWheel");
// Sign to make either -1.0 or 1.0 (else, it's like 0.1).
if (scroll != 0.0f)
{
scroll = Mathf.Sign(scroll);
}
scroll *= zoomStep;
currentZoom += scroll;
currentZoom = Mathf.Clamp(currentZoom, zoomRange.x, zoomRange.y);
Vector3 localPosition = zoomTransform.localPosition;
localPosition.z = Mathf.Lerp(localPosition.z, currentZoom, Time.deltaTime * zoomLerpSpeed);
zoomTransform.localPosition = localPosition;
}
previouslyFocused = isFocused;
}
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 8ceab5e0c7bc25e44a1fc2ea317e97af
AssetOrigin:
serializedVersion: 1
productId: 277702
packageName: AERO - Volumetric Fog and Mist
packageVersion: 1.8.0
assetPath: Assets/Mirza/_VFXToolkit/_Demo/Scripts/MFXTK_CameraController.cs
uploadId: 933120
@@ -0,0 +1,127 @@
using System;
using TMPro;
using UnityEngine;
namespace Mirza.VFXToolKit
{
[ExecuteAlways]
public class MVFXTK_FPSDisplay : MonoBehaviour
{
public float fps { get; private set; } // Frames per second (interval average).
public float frameMS { get; private set; } // Milliseconds per frame (interval average).
GUIStyle style = new();
public int size = 32;
[Range(0.0f, 2.0f)]
public float scale = 1.0f;
[Space]
public Vector2 position = new(32.0f, 32.0f);
public enum Alignment { Left, Right }
public Alignment alignment = Alignment.Left;
[Space]
public Color colour = Color.green;
[Space]
public float updateInterval = 0.5f;
float elapsedIntervalTime;
int intervalFrameCount;
[Space]
[Tooltip("Optional. Will render using GUI if not assigned.")]
public TextMeshProUGUI textMesh;
// Get average FPS and frame delta (ms) for current interval (so far, if called early).
public float GetIntervalFPS()
{
// 1 / time.unscaledDeltaTime for same-frame results.
// Same as above, but uses accumulated frameCount and deltaTime.
return intervalFrameCount / elapsedIntervalTime;
}
public float GetIntervalFrameMS()
{
// Calculate average frame delta during interval (time / frames).
// Same as Time.unscaledDeltaTime * 1000.0f, using accumulation.
return (elapsedIntervalTime * 1000.0f) / intervalFrameCount;
}
float GetScreenScale()
{
return scale * (Screen.height / 1080.0f);
}
void Update()
{
intervalFrameCount++;
elapsedIntervalTime += Time.unscaledDeltaTime;
if (elapsedIntervalTime >= updateInterval)
{
fps = GetIntervalFPS();
frameMS = GetIntervalFrameMS();
fps = (float)Math.Round(fps, 2);
frameMS = (float)Math.Round(frameMS, 2);
intervalFrameCount = 0;
elapsedIntervalTime = 0.0f;
}
if (textMesh)
{
textMesh.text = GetFPSText();
}
else
{
//style.fontSize = Mathf.RoundToInt(size * scale);
style.fontSize = Mathf.RoundToInt(size * GetScreenScale());
style.fontStyle = FontStyle.Bold;
style.normal.textColor = colour;
}
}
string GetFPSText()
{
if (!Application.isPlaying)
{
//return "FPS: -- NOT PLAYING.";
return $"FPS: {fps:--} ({frameMS:--} ms)";
}
return $"FPS: {fps:.00} ({frameMS:.00} ms)";
}
void OnGUI()
{
string fpsText = GetFPSText();
if (!textMesh)
{
Vector2 scaledPosition = position * GetScreenScale();
float x = scaledPosition.x;
if (alignment == Alignment.Right)
{
x = Screen.width - x - style.CalcSize(new GUIContent(fpsText)).x;
}
GUI.Label(new Rect(x, scaledPosition.y, 200, 100), fpsText, style);
}
}
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 6f89cc6358924444c9404ae30296d565
AssetOrigin:
serializedVersion: 1
productId: 277702
packageName: AERO - Volumetric Fog and Mist
packageVersion: 1.8.0
assetPath: Assets/Mirza/_VFXToolkit/_Demo/Scripts/MFXTK_FPSDisplay.cs
uploadId: 933120
@@ -0,0 +1,30 @@
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace Mirza.VFXToolKit
{
[ExecuteAlways]
public class MFXTK_RenderScaleSliderUI : MonoBehaviour
{
Slider slider;
public MFXTK_SetRenderScale setRenderScale;
public TextMeshProUGUI label;
void Start()
{
slider = GetComponent<Slider>();
slider.onValueChanged.AddListener(SetRenderScale);
}
public void SetRenderScale(float value)
{
setRenderScale.renderScale = value * 0.25f;
label.text = setRenderScale.renderScale.ToString("0.00x");
}
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 2d310e947c476b445afa806a42a18eb7
AssetOrigin:
serializedVersion: 1
productId: 277702
packageName: AERO - Volumetric Fog and Mist
packageVersion: 1.8.0
assetPath: Assets/Mirza/_VFXToolkit/_Demo/Scripts/MFXTK_RenderScaleSliderUI.cs
uploadId: 933120
@@ -0,0 +1,37 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Mirza.VFXToolKit
{
public class MVFXTK_SetFPS : MonoBehaviour
{
public int targetFPS = 60;
[Space]
public bool forceSet = true;
public bool unlockOnDisable = true;
void OnEnable()
{
Application.targetFrameRate = targetFPS;
}
void Update()
{
if (forceSet)
{
Application.targetFrameRate = targetFPS;
}
}
void OnDisable()
{
if (unlockOnDisable)
{
Application.targetFrameRate = -1;
}
}
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: f8ebb833d0c3b6f4589fbf1bec862baf
AssetOrigin:
serializedVersion: 1
productId: 277702
packageName: AERO - Volumetric Fog and Mist
packageVersion: 1.8.0
assetPath: Assets/Mirza/_VFXToolkit/_Demo/Scripts/MFXTK_SetFPSOnStart.cs
uploadId: 933120
@@ -0,0 +1,39 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering.Universal;
namespace Mirza.VFXToolKit
{
[ExecuteAlways]
public class MFXTK_SetRenderScale : MonoBehaviour
{
[Range(0.25f, 2.0f)]
public float renderScale = 1.0f;
public bool executeInEditMode;
UniversalRenderPipelineAsset urpAsset;
void Start()
{
urpAsset = QualitySettings.renderPipeline as UniversalRenderPipelineAsset;
}
void Update()
{
if (!executeInEditMode && !Application.isPlaying)
{
return;
}
urpAsset.renderScale = renderScale;
}
public void SetRenderScale(float value)
{
renderScale = value;
}
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: c5797055057e8b54eab1c5c48fa76507
AssetOrigin:
serializedVersion: 1
productId: 277702
packageName: AERO - Volumetric Fog and Mist
packageVersion: 1.8.0
assetPath: Assets/Mirza/_VFXToolkit/_Demo/Scripts/MFXTK_SetRenderScale.cs
uploadId: 933120
@@ -0,0 +1,22 @@
using TMPro;
using UnityEngine;
namespace Mirza.VFXToolKit
{
public class MFXTK_SetRenderScaleDropdownUI : MonoBehaviour
{
TMP_Dropdown dropdown;
public MFXTK_SetRenderScale setRenderScale;
void Start()
{
dropdown = GetComponent<TMP_Dropdown>();
dropdown.onValueChanged.AddListener(SetRenderScale);
}
public void SetRenderScale(int value)
{
setRenderScale.renderScale = 0.25f + (value * 0.25f);
}
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: e0b11718a1c27f14eaf7ea6e86de0f3d
AssetOrigin:
serializedVersion: 1
productId: 277702
packageName: AERO - Volumetric Fog and Mist
packageVersion: 1.8.0
assetPath: Assets/Mirza/_VFXToolkit/_Demo/Scripts/MFXTK_SetRenderScaleDropdownUI.cs
uploadId: 933120
@@ -0,0 +1,53 @@
using UnityEngine;
using UnityEngine.Rendering.Universal;
namespace Mirza.VFXToolKit
{
// This script copies *almost* all settings from the target camera.
// Target texture and culling mask are preserved for specific rendering purposes.
// It's typically used for that -> same camera view, different render and texture.
[ExecuteAlways]
public class MVFXTK_CameraCopyFrom : MonoBehaviour
{
Camera camera;
public Camera target;
public float priorityOffset = -1;
[Space]
public bool copyBackgroundType = true;
void LateUpdate()
{
if (!camera)
{
camera = GetComponent<Camera>();
}
RenderTexture targetTexture = camera.targetTexture;
int cullingMask = camera.cullingMask;
CameraClearFlags backgroundType = camera.clearFlags;
Color backgroundColour = camera.backgroundColor;
// ...
camera.CopyFrom(target);
camera.depth += priorityOffset;
camera.targetTexture = targetTexture;
camera.cullingMask = cullingMask;
if (!copyBackgroundType)
{
camera.clearFlags = backgroundType;
camera.backgroundColor = backgroundColour;
}
}
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 9e4af7057a670ea46bb98c7b08392b1c
AssetOrigin:
serializedVersion: 1
productId: 277702
packageName: AERO - Volumetric Fog and Mist
packageVersion: 1.8.0
assetPath: Assets/Mirza/_VFXToolkit/_Demo/Scripts/MVFXTK_CameraCopyFrom.cs
uploadId: 933120
@@ -0,0 +1,86 @@
using UnityEngine;
namespace Mirza.VFXToolKit
{
// This script sets the emissive color of the material on the first child object
// to match the colour of the Light component on the current GameObject.
[ExecuteAlways]
public class MVFXTK_LightColourMesh : MonoBehaviour
{
Light light;
Material material;
Renderer renderer;
public float intensityScale = 1.0f;
public bool executeInEditMode;
public enum Target { Parent, Child, Self }
[Space]
public Target target = Target.Child;
[Space]
public string propertyName = "_EmissionColor";
// ...
void Start()
{
light = GetComponent<Light>();
switch (target)
{
case Target.Parent:
{
renderer = transform.parent.GetComponent<Renderer>();
break;
}
case Target.Child:
{
renderer = transform.GetChild(0).GetComponent<Renderer>();
break;
}
case Target.Self:
{
renderer = GetComponent<Renderer>();
break;
}
default:
{
throw new System.Exception("Unknown type.");
}
}
}
void LateUpdate()
{
if (Application.isPlaying)
{
material = renderer.material;
}
else
{
if (!executeInEditMode)
{
return;
}
material = renderer.sharedMaterial;
}
if (!material.IsKeywordEnabled("_EMISSION"))
{
material.EnableKeyword("_EMISSION");
}
float intensity = light.intensity * intensityScale;
Color colour = light.color * intensity;
material.SetColor(propertyName, colour);
}
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: baebf7b7a254c8b4d9a06735b47019e1
AssetOrigin:
serializedVersion: 1
productId: 277702
packageName: AERO - Volumetric Fog and Mist
packageVersion: 1.8.0
assetPath: Assets/Mirza/_VFXToolkit/_Demo/Scripts/MVFXTK_LightColourMesh.cs
uploadId: 933120
@@ -0,0 +1,235 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
namespace Mirza.VFXToolKit
{
[ExecuteInEditMode]
public class MVFXTK_LiveRenderTexture : MonoBehaviour
{
[System.Serializable]
public struct SendToMaterialData
{
public Material material;
public string textureName;
}
// Do not assign anything to these in the editor,
// they're managed entirely by the script.
[Header("READ ONLY")]
[Space]
public RenderTexture renderTexture;
public CustomRenderTexture customRenderTexture;
// Aspect resolution is used by the custom editor to preview the render texture (prevent extreme aspect ratios).
// The actual resolution for the texture may be different if an override is set.
[Space]
public Vector2Int aspectResolution;
[Header("Read/Write")]
[Space]
public bool isCustomRenderTexture;
[Space]
[Range(1, 32)]
public int downsampleLevel = 1;
[Space]
[Range(0.0f, 2.0f)]
public float widthScale = 1.0f;
[Range(0.0f, 2.0f)]
public float heightScale = 1.0f;
[Space]
public FilterMode filterMode = FilterMode.Point;
public GraphicsFormat renderTextureFormat = GraphicsFormat.R16G16B16A16_SFloat;
[Space]
public bool useMipMap;
[Space]
public Camera camera;
[Space]
public Material updateMaterial;
// State change requiring refresh.
Component previousThisComponent;
void Awake()
{
// If new object (which may be a copy and carry over textures),
// don't destroy textures, but ensure references are null so new ones will be created for THIS component,
// while not destroying the old ones which would otherwise force the other component to recreate them, too.
renderTexture = null;
customRenderTexture = null;
//print($"{name} - Nulling textures.");
}
void Start()
{
}
void DestroyTextures()
{
// Not sure if release is necessary before destroying.
// CustomRenderTexture is first (just in case) since a CRT is always a RT, but an RT isn't always a CRT.
// Remove before releasing/destroying to prevent an annoying error message.
if (camera)
{
camera.targetTexture = null;
}
// OBLIDERATE.
if (customRenderTexture)
{
customRenderTexture.Release();
DestroyImmediate(customRenderTexture);
}
if (renderTexture)
{
renderTexture.Release();
DestroyImmediate(renderTexture);
}
//print($"{name} - Destroying textures ({textures} / 2).");
}
void OnDestroy()
{
DestroyTextures();
}
public Vector2Int GetDownsampledResolution()
{
return new Vector2Int(Screen.width / downsampleLevel, Screen.height / downsampleLevel);
}
void Update()
{
// Update resolution.
aspectResolution = GetDownsampledResolution();
Vector2Int resolution = aspectResolution;
resolution.x = Mathf.FloorToInt(resolution.x * widthScale);
resolution.y = Mathf.FloorToInt(resolution.y * heightScale);
resolution.x = Mathf.Max(1, resolution.x);
resolution.y = Mathf.Max(1, resolution.y);
// Create/refresh render texture if needed.
bool destroyTextures = !renderTexture;
destroyTextures = destroyTextures || previousThisComponent != this;
destroyTextures = destroyTextures || renderTexture.width != resolution.x || renderTexture.height != resolution.y;
destroyTextures = destroyTextures || renderTexture.graphicsFormat != renderTextureFormat;
destroyTextures = destroyTextures || renderTexture.useMipMap != useMipMap;
// Need new render texture if custom render texture is toggled and current render texture is not a custom render texture.
if (isCustomRenderTexture)
{
destroyTextures = destroyTextures || renderTexture != customRenderTexture;
}
else
{
destroyTextures = destroyTextures || customRenderTexture != null;
}
if (destroyTextures)
{
DestroyTextures();
// Force editor to update so editor slots reflect internal state.
#if UNITY_EDITOR
UnityEditor.EditorUtility.SetDirty(this);
UnityEditor.SceneView.RepaintAll();
#endif
}
//if (renderTexture)
//{
// if (renderTexture.width != resolution.x || renderTexture.height != resolution.y)
// {
// renderTexture.Release();
// renderTexture.width = resolution.x;
// renderTexture.height = resolution.y;
// renderTexture.Create();
// }
//}
// Create if null.
if (!renderTexture)
{
//print($"{name} - Creating texture.");
if (!isCustomRenderTexture)
{
renderTexture = new RenderTexture(resolution.x, resolution.y, 16, renderTextureFormat, 0)
{
useMipMap = useMipMap,
autoGenerateMips = useMipMap
};
}
else
{
customRenderTexture = new CustomRenderTexture(resolution.x, resolution.y, renderTextureFormat);
renderTexture = customRenderTexture;
}
//print($"{name} - Textures created.");
}
// Update render texture settings.
renderTexture.name = name;
renderTexture.filterMode = filterMode;
if (customRenderTexture)
{
customRenderTexture.material = updateMaterial;
customRenderTexture.updateMode = CustomRenderTextureUpdateMode.Realtime;
}
// Set as target for camera.
if (camera)
{
camera.targetTexture = renderTexture;
}
// State change requiring refresh.
previousThisComponent = this;
}
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 913da6667c58a2545ad804ce8a087a69
AssetOrigin:
serializedVersion: 1
productId: 277702
packageName: AERO - Volumetric Fog and Mist
packageVersion: 1.8.0
assetPath: Assets/Mirza/_VFXToolkit/_Demo/Scripts/MVFXTK_LiveRenderTexture.cs
uploadId: 933120
@@ -0,0 +1,31 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Mirza.VFXToolKit
{
// Reads from live render texture to send to current object's renderer material.
// Example use: I have a camera rendering backfaces,
// and I read that texture into the current renderer material to use in that shader,
// such as for multi-transparency refraction (or something).
[ExecuteInEditMode]
public class MVFXTK_LiveRenderTextureReceiveToRendererMaterial : MonoBehaviour
{
public MVFXTK_LiveRenderTexture liveRenderTexture;
Renderer renderer;
public string textureName = "_MainTex";
void Update()
{
if (!renderer)
{
renderer = GetComponent<Renderer>();
}
renderer.sharedMaterial.SetTexture(textureName, liveRenderTexture.renderTexture);
}
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 83766d8e7737efc4498b9849d635fa12
AssetOrigin:
serializedVersion: 1
productId: 277702
packageName: AERO - Volumetric Fog and Mist
packageVersion: 1.8.0
assetPath: Assets/Mirza/_VFXToolkit/_Demo/Scripts/MVFXTK_LiveRenderTextureReceiveToRendererMaterial.cs
uploadId: 933120
@@ -0,0 +1,41 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Mirza.VFXToolKit
{
// Sends (assigns) the dynamic/live texture on the current game object to a material.
// Example use: a live render texture from a camera is used to send to a blur custom render texture material.
[ExecuteInEditMode]
[RequireComponent(typeof(MVFXTK_LiveRenderTexture))]
public class MVFXTK_LiveRenderTextureSendToMaterial : MonoBehaviour
{
MVFXTK_LiveRenderTexture liveRenderTexture;
public Material material;
public string textureName = "_MainTex";
void SendToMaterial(Material material, string textureName)
{
if (material.HasProperty(textureName))
{
material.SetTexture(textureName, liveRenderTexture.renderTexture);
}
else
{
Debug.LogWarning($"Material does not have texture property named {textureName}.");
}
}
void LateUpdate()
{
if (!liveRenderTexture)
{
liveRenderTexture = GetComponent<MVFXTK_LiveRenderTexture>();
}
SendToMaterial(material, textureName);
}
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 7726a59b60b254c4a85bda7a6d331bac
AssetOrigin:
serializedVersion: 1
productId: 277702
packageName: AERO - Volumetric Fog and Mist
packageVersion: 1.8.0
assetPath: Assets/Mirza/_VFXToolkit/_Demo/Scripts/MVFXTK_LiveRenderTextureSendToMaterial.cs
uploadId: 933120
@@ -0,0 +1,26 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Mirza.VFXToolKit
{
// Sets live texture as a global shader texture.
[ExecuteInEditMode]
[RequireComponent(typeof(MVFXTK_LiveRenderTexture))]
public class MVFXTK_LiveRenderTextureSetAsGlobalTexture : MonoBehaviour
{
MVFXTK_LiveRenderTexture liveRenderTexture;
public string textureName = "_CameraGlobalTexture";
void LateUpdate()
{
if (!liveRenderTexture)
{
liveRenderTexture = GetComponent<MVFXTK_LiveRenderTexture>();
}
Shader.SetGlobalTexture(textureName, liveRenderTexture.renderTexture);
}
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: d560bf039fdcc614e8fc6585a39f65cc
AssetOrigin:
serializedVersion: 1
productId: 277702
packageName: AERO - Volumetric Fog and Mist
packageVersion: 1.8.0
assetPath: Assets/Mirza/_VFXToolkit/_Demo/Scripts/MVFXTK_LiveRenderTextureSetAsGlobalTexture.cs
uploadId: 933120
@@ -0,0 +1,71 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Mirza.VFXToolKit
{
public class MVFXTK_Rotator : MonoBehaviour
{
public Vector3 rotation;
public Space space = Space.Self;
// Internal rotation state to accumulate cleanly over time.
Quaternion currentRotation;
//void Start()
//{
// // Store initial rotation.
// currentRotation = transform.localRotation;
//}
void OnEnable()
{
currentRotation = transform.localRotation;
}
// Putting this in Update allows the user to modify the rotation in the editor,
// while the script continues to run. The continous rotation is applied in LateUpdate.
void Update()
{
// Store the current rotation for the next frame.
if (space == Space.Self)
{
currentRotation = transform.localRotation;
}
else
{
currentRotation = transform.rotation;
}
}
void LateUpdate()
{
// Compute delta rotation this frame.
Quaternion deltaRotation = Quaternion.Euler(rotation * Time.deltaTime);
// Apply depending on world vs. local space.
if (space == Space.Self)
{
currentRotation *= deltaRotation;
// Apply the accumulated quaternion.
transform.localRotation = currentRotation;
}
else
{
// World space: multiply from the *outside*.
currentRotation = deltaRotation * currentRotation;
transform.rotation = currentRotation;
}
}
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 11e1993bd358e7349905a9ef8bce0bf7
AssetOrigin:
serializedVersion: 1
productId: 277702
packageName: AERO - Volumetric Fog and Mist
packageVersion: 1.8.0
assetPath: Assets/Mirza/_VFXToolkit/_Demo/Scripts/MVFXTK_Rotator.cs
uploadId: 933120