-
Notifications
You must be signed in to change notification settings - Fork 474
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
color copy with mips works, but fetching from BiRP SG not yet
- Loading branch information
1 parent
533baa2
commit 9420cd2
Showing
3 changed files
with
209 additions
and
165 deletions.
There are no files selected for viewing
60 changes: 52 additions & 8 deletions
60
UnityGLTF/Assets/UnityGLTF/Runtime/Scripts/RenderPipelines/CopyColorBuiltin.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,73 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
[ExecuteAlways, ImageEffectAllowedInSceneView] | ||
public class CopyColorBuiltin : MonoBehaviour | ||
{ | ||
public Renderer tempOutput; | ||
private MaterialPropertyBlock tempBlock; | ||
|
||
private RenderTexture opaqueTexture; | ||
private RenderTexture temp; | ||
private Dictionary<Camera, RenderTexture> temp = new Dictionary<Camera, RenderTexture>(); | ||
|
||
private void OnDisable() | ||
{ | ||
if(temp != null) | ||
RenderTexture.ReleaseTemporary(temp); | ||
if (temp != null) { | ||
foreach(var kvp in temp) | ||
RenderTexture.ReleaseTemporary(kvp.Value); | ||
} | ||
temp.Clear(); | ||
} | ||
|
||
private void OnPreRender() | ||
{ | ||
SetTexture(); | ||
} | ||
|
||
private void SetTexture() | ||
{ | ||
var current = Camera.current; | ||
if (!temp.ContainsKey(current)) | ||
{ | ||
Shader.SetGlobalTexture("_CameraOpaqueTexture", Texture2D.blackTexture); | ||
return; | ||
} | ||
|
||
Shader.SetGlobalTexture("_CameraOpaqueTexture", temp[current]); | ||
|
||
if (tempOutput) | ||
{ | ||
if (tempBlock == null) tempBlock = new MaterialPropertyBlock(); | ||
tempBlock.SetTexture("_MainTex", temp[current]); | ||
tempOutput.SetPropertyBlock(tempBlock); | ||
} | ||
} | ||
|
||
[ImageEffectOpaque] | ||
private void OnRenderImage(RenderTexture src, RenderTexture dest) | ||
{ | ||
var dsc = src.descriptor; | ||
dsc.useMipMap = true; | ||
dsc.autoGenerateMips = true; | ||
dsc.autoGenerateMips = false; | ||
dsc.msaaSamples = 1; | ||
dsc.width = Mathf.ClosestPowerOfTwo(dsc.width); | ||
dsc.height = Mathf.ClosestPowerOfTwo(dsc.height); | ||
|
||
var current = Camera.current; | ||
if (!temp.ContainsKey(current)) | ||
temp.Add(current, null); | ||
if(temp[current]) | ||
RenderTexture.ReleaseTemporary(temp[current]); | ||
|
||
RenderTexture.ReleaseTemporary(temp); | ||
temp = RenderTexture.GetTemporary(dsc); | ||
temp[current] = RenderTexture.GetTemporary(dsc); | ||
temp[current].filterMode = FilterMode.Trilinear; | ||
// temp[current].useMipMap = true; | ||
|
||
Graphics.Blit(src, temp); | ||
Graphics.Blit(src, temp[current]); | ||
temp[current].GenerateMips(); | ||
Graphics.Blit(src, dest); | ||
|
||
Shader.SetGlobalTexture("_CameraOpaqueTexture", temp); | ||
SetTexture(); | ||
} | ||
} |
Oops, something went wrong.