Hässliche reuden ranz Map-Begrenzung

This commit is contained in:
Simon Lübeß
2024-04-08 16:43:05 +02:00
parent 8e995ec0a5
commit 739eb2bc4b
550 changed files with 108099 additions and 7582 deletions

View File

@ -0,0 +1,197 @@
using System;
using UnityEngine;
namespace UnityStandardAssets.ImageEffects
{
[ExecuteInEditMode]
[AddComponentMenu("Image Effects/Color Adjustments/Contrast Stretch")]
public class ContrastStretch : MonoBehaviour
{
/// Adaptation speed - percents per frame, if playing at 30FPS.
/// Default is 0.02 (2% each 1/30s).
public float adaptationSpeed = 0.02f;
/// If our scene is really dark (or really bright), we might not want to
/// stretch its contrast to the full range.
/// limitMinimum=0, limitMaximum=1 is the same as not applying the effect at all.
/// limitMinimum=1, limitMaximum=0 is always stretching colors to full range.
/// The limit on the minimum luminance (0...1) - we won't go above this.
public float limitMinimum = 0.2f;
/// The limit on the maximum luminance (0...1) - we won't go below this.
public float limitMaximum = 0.6f;
// To maintain adaptation levels over time, we need two 1x1 render textures
// and ping-pong between them.
private RenderTexture[] adaptRenderTex = new RenderTexture[2];
private int curAdaptIndex = 0;
// Computes scene luminance (grayscale) image
public Shader shaderLum;
private Material m_materialLum;
protected Material materialLum {
get {
if ( m_materialLum == null ) {
m_materialLum = new Material(shaderLum);
m_materialLum.hideFlags = HideFlags.HideAndDontSave;
}
return m_materialLum;
}
}
// Reduces size of the image by 2x2, while computing maximum/minimum values.
// By repeatedly applying this shader, we reduce the initial luminance image
// to 1x1 image with minimum/maximum luminances found.
public Shader shaderReduce;
private Material m_materialReduce;
protected Material materialReduce {
get {
if ( m_materialReduce == null ) {
m_materialReduce = new Material(shaderReduce);
m_materialReduce.hideFlags = HideFlags.HideAndDontSave;
}
return m_materialReduce;
}
}
// Adaptation shader - gradually "adapts" minimum/maximum luminances,
// based on currently adapted 1x1 image and the actual 1x1 image of the current scene.
public Shader shaderAdapt;
private Material m_materialAdapt;
protected Material materialAdapt {
get {
if ( m_materialAdapt == null ) {
m_materialAdapt = new Material(shaderAdapt);
m_materialAdapt.hideFlags = HideFlags.HideAndDontSave;
}
return m_materialAdapt;
}
}
// Final pass - stretches the color values of the original scene, based on currently
// adpated minimum/maximum values.
public Shader shaderApply;
private Material m_materialApply;
protected Material materialApply {
get {
if ( m_materialApply == null ) {
m_materialApply = new Material(shaderApply);
m_materialApply.hideFlags = HideFlags.HideAndDontSave;
}
return m_materialApply;
}
}
void Start()
{
// Disable if we don't support image effects
if (!SystemInfo.supportsImageEffects) {
enabled = false;
return;
}
if (!shaderAdapt.isSupported || !shaderApply.isSupported || !shaderLum.isSupported || !shaderReduce.isSupported) {
enabled = false;
return;
}
}
void OnEnable()
{
for( int i = 0; i < 2; ++i )
{
if ( !adaptRenderTex[i] ) {
adaptRenderTex[i] = new RenderTexture(1, 1, 0);
adaptRenderTex[i].hideFlags = HideFlags.HideAndDontSave;
}
}
}
void OnDisable()
{
for( int i = 0; i < 2; ++i )
{
DestroyImmediate( adaptRenderTex[i] );
adaptRenderTex[i] = null;
}
if ( m_materialLum )
DestroyImmediate( m_materialLum );
if ( m_materialReduce )
DestroyImmediate( m_materialReduce );
if ( m_materialAdapt )
DestroyImmediate( m_materialAdapt );
if ( m_materialApply )
DestroyImmediate( m_materialApply );
}
/// Apply the filter
void OnRenderImage (RenderTexture source, RenderTexture destination)
{
// Blit to smaller RT and convert to luminance on the way
const int TEMP_RATIO = 1; // 4x4 smaller
RenderTexture rtTempSrc = RenderTexture.GetTemporary(source.width/TEMP_RATIO, source.height/TEMP_RATIO);
Graphics.Blit (source, rtTempSrc, materialLum);
// Repeatedly reduce this image in size, computing min/max luminance values
// In the end we'll have 1x1 image with min/max luminances found.
const int FINAL_SIZE = 1;
//const int FINAL_SIZE = 1;
while( rtTempSrc.width > FINAL_SIZE || rtTempSrc.height > FINAL_SIZE )
{
const int REDUCE_RATIO = 2; // our shader does 2x2 reduction
int destW = rtTempSrc.width / REDUCE_RATIO;
if ( destW < FINAL_SIZE ) destW = FINAL_SIZE;
int destH = rtTempSrc.height / REDUCE_RATIO;
if ( destH < FINAL_SIZE ) destH = FINAL_SIZE;
RenderTexture rtTempDst = RenderTexture.GetTemporary(destW,destH);
Graphics.Blit (rtTempSrc, rtTempDst, materialReduce);
// Release old src temporary, and make new temporary the source
RenderTexture.ReleaseTemporary( rtTempSrc );
rtTempSrc = rtTempDst;
}
// Update viewer's adaptation level
CalculateAdaptation( rtTempSrc );
// Apply contrast strech to the original scene, using currently adapted parameters
materialApply.SetTexture("_AdaptTex", adaptRenderTex[curAdaptIndex] );
Graphics.Blit (source, destination, materialApply);
RenderTexture.ReleaseTemporary( rtTempSrc );
}
/// Helper function to do gradual adaptation to min/max luminances
private void CalculateAdaptation( Texture curTexture )
{
int prevAdaptIndex = curAdaptIndex;
curAdaptIndex = (curAdaptIndex+1) % 2;
// Adaptation speed is expressed in percents/frame, based on 30FPS.
// Calculate the adaptation lerp, based on current FPS.
float adaptLerp = 1.0f - Mathf.Pow( 1.0f - adaptationSpeed, 30.0f * Time.deltaTime );
const float kMinAdaptLerp = 0.01f;
adaptLerp = Mathf.Clamp( adaptLerp, kMinAdaptLerp, 1 );
materialAdapt.SetTexture("_CurTex", curTexture );
materialAdapt.SetVector("_AdaptParams", new Vector4(
adaptLerp,
limitMinimum,
limitMaximum,
0.0f
));
// clear destination RT so its contents don't need to be restored
Graphics.SetRenderTarget(adaptRenderTex[curAdaptIndex]);
GL.Clear(false, true, Color.black);
Graphics.Blit (
adaptRenderTex[prevAdaptIndex],
adaptRenderTex[curAdaptIndex],
materialAdapt);
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: ec92b071d2d424aecb3e46f28eb63174
MonoImporter:
serializedVersion: 2
defaultReferences:
- shaderLum: {fileID: 4800000, guid: befbb4b9c320b4b18a08ef7afb93b6c9, type: 3}
- shaderReduce: {fileID: 4800000, guid: 57b33a14b6d5347c5a85c36f6cb3b280, type: 3}
- shaderAdapt: {fileID: 4800000, guid: 257bc83cbeb544540bd0e558aa9b1383, type: 3}
- shaderApply: {fileID: 4800000, guid: f4901f25d4e1542589348bbb89563d8e, type: 3}
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@ -0,0 +1,147 @@
using System;
using UnityEngine;
namespace UnityStandardAssets.ImageEffects
{
[ExecuteInEditMode]
[RequireComponent (typeof(Camera))]
[AddComponentMenu ("Image Effects/Rendering/Global Fog")]
class GlobalFog : PostEffectsBase
{
[Tooltip("Apply distance-based fog?")]
public bool distanceFog = true;
[Tooltip("Distance fog is based on radial distance from camera when checked")]
public bool useRadialDistance = false;
[Tooltip("Apply height-based fog?")]
public bool heightFog = true;
[Tooltip("Fog top Y coordinate")]
public float height = 1.0f;
[Range(0.001f,10.0f)]
public float heightDensity = 2.0f;
[Tooltip("Push fog away from the camera by this amount")]
public float startDistance = 0.0f;
public Shader fogShader = null;
private Material fogMaterial = null;
public override bool CheckResources ()
{
CheckSupport (true);
fogMaterial = CheckShaderAndCreateMaterial (fogShader, fogMaterial);
if (!isSupported)
ReportAutoDisable ();
return isSupported;
}
[ImageEffectOpaque]
void OnRenderImage (RenderTexture source, RenderTexture destination)
{
if (CheckResources()==false || (!distanceFog && !heightFog))
{
Graphics.Blit (source, destination);
return;
}
Camera cam = GetComponent<Camera>();
Transform camtr = cam.transform;
float camNear = cam.nearClipPlane;
float camFar = cam.farClipPlane;
float camFov = cam.fieldOfView;
float camAspect = cam.aspect;
Matrix4x4 frustumCorners = Matrix4x4.identity;
float fovWHalf = camFov * 0.5f;
Vector3 toRight = camtr.right * camNear * Mathf.Tan (fovWHalf * Mathf.Deg2Rad) * camAspect;
Vector3 toTop = camtr.up * camNear * Mathf.Tan (fovWHalf * Mathf.Deg2Rad);
Vector3 topLeft = (camtr.forward * camNear - toRight + toTop);
float camScale = topLeft.magnitude * camFar/camNear;
topLeft.Normalize();
topLeft *= camScale;
Vector3 topRight = (camtr.forward * camNear + toRight + toTop);
topRight.Normalize();
topRight *= camScale;
Vector3 bottomRight = (camtr.forward * camNear + toRight - toTop);
bottomRight.Normalize();
bottomRight *= camScale;
Vector3 bottomLeft = (camtr.forward * camNear - toRight - toTop);
bottomLeft.Normalize();
bottomLeft *= camScale;
frustumCorners.SetRow (0, topLeft);
frustumCorners.SetRow (1, topRight);
frustumCorners.SetRow (2, bottomRight);
frustumCorners.SetRow (3, bottomLeft);
var camPos= camtr.position;
float FdotC = camPos.y-height;
float paramK = (FdotC <= 0.0f ? 1.0f : 0.0f);
fogMaterial.SetMatrix ("_FrustumCornersWS", frustumCorners);
fogMaterial.SetVector ("_CameraWS", camPos);
fogMaterial.SetVector ("_HeightParams", new Vector4 (height, FdotC, paramK, heightDensity*0.5f));
fogMaterial.SetVector ("_DistanceParams", new Vector4 (-Mathf.Max(startDistance,0.0f), 0, 0, 0));
var sceneMode= RenderSettings.fogMode;
var sceneDensity= RenderSettings.fogDensity;
var sceneStart= RenderSettings.fogStartDistance;
var sceneEnd= RenderSettings.fogEndDistance;
Vector4 sceneParams;
bool linear = (sceneMode == FogMode.Linear);
float diff = linear ? sceneEnd - sceneStart : 0.0f;
float invDiff = Mathf.Abs(diff) > 0.0001f ? 1.0f / diff : 0.0f;
sceneParams.x = sceneDensity * 1.2011224087f; // density / sqrt(ln(2)), used by Exp2 fog mode
sceneParams.y = sceneDensity * 1.4426950408f; // density / ln(2), used by Exp fog mode
sceneParams.z = linear ? -invDiff : 0.0f;
sceneParams.w = linear ? sceneEnd * invDiff : 0.0f;
fogMaterial.SetVector ("_SceneFogParams", sceneParams);
fogMaterial.SetVector ("_SceneFogMode", new Vector4((int)sceneMode, useRadialDistance ? 1 : 0, 0, 0));
int pass = 0;
if (distanceFog && heightFog)
pass = 0; // distance + height
else if (distanceFog)
pass = 1; // distance only
else
pass = 2; // height only
CustomGraphicsBlit (source, destination, fogMaterial, pass);
}
static void CustomGraphicsBlit (RenderTexture source, RenderTexture dest, Material fxMaterial, int passNr)
{
RenderTexture.active = dest;
fxMaterial.SetTexture ("_MainTex", source);
GL.PushMatrix ();
GL.LoadOrtho ();
fxMaterial.SetPass (passNr);
GL.Begin (GL.QUADS);
GL.MultiTexCoord2 (0, 0.0f, 0.0f);
GL.Vertex3 (0.0f, 0.0f, 3.0f); // BL
GL.MultiTexCoord2 (0, 1.0f, 0.0f);
GL.Vertex3 (1.0f, 0.0f, 2.0f); // BR
GL.MultiTexCoord2 (0, 1.0f, 1.0f);
GL.Vertex3 (1.0f, 1.0f, 1.0f); // TR
GL.MultiTexCoord2 (0, 0.0f, 1.0f);
GL.Vertex3 (0.0f, 1.0f, 0.0f); // TL
GL.End ();
GL.PopMatrix ();
}
}
}

View File

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 76b5ec6153a1d55438228df10fe66844
MonoImporter:
serializedVersion: 2
defaultReferences:
- fogShader: {fileID: 4800000, guid: 70d8568987ac0499f952b54c7c13e265, type: 3}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:

View File

@ -0,0 +1,243 @@
using System;
using UnityEngine;
namespace UnityStandardAssets.ImageEffects
{
[ExecuteInEditMode]
[RequireComponent (typeof(Camera))]
public class PostEffectsBase : MonoBehaviour
{
protected bool supportHDRTextures = true;
protected bool supportDX11 = false;
protected bool isSupported = true;
protected Material CheckShaderAndCreateMaterial ( Shader s, Material m2Create)
{
if (!s)
{
Debug.Log("Missing shader in " + ToString ());
enabled = false;
return null;
}
if (s.isSupported && m2Create && m2Create.shader == s)
return m2Create;
if (!s.isSupported)
{
NotSupported ();
Debug.Log("The shader " + s.ToString() + " on effect "+ToString()+" is not supported on this platform!");
return null;
}
else
{
m2Create = new Material (s);
m2Create.hideFlags = HideFlags.DontSave;
if (m2Create)
return m2Create;
else return null;
}
}
protected Material CreateMaterial (Shader s, Material m2Create)
{
if (!s)
{
Debug.Log ("Missing shader in " + ToString ());
return null;
}
if (m2Create && (m2Create.shader == s) && (s.isSupported))
return m2Create;
if (!s.isSupported)
{
return null;
}
else
{
m2Create = new Material (s);
m2Create.hideFlags = HideFlags.DontSave;
if (m2Create)
return m2Create;
else return null;
}
}
void OnEnable ()
{
isSupported = true;
}
protected bool CheckSupport ()
{
return CheckSupport (false);
}
public virtual bool CheckResources ()
{
Debug.LogWarning ("CheckResources () for " + ToString() + " should be overwritten.");
return isSupported;
}
protected void Start ()
{
CheckResources ();
}
protected bool CheckSupport (bool needDepth)
{
isSupported = true;
supportHDRTextures = SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGBHalf);
supportDX11 = SystemInfo.graphicsShaderLevel >= 50 && SystemInfo.supportsComputeShaders;
if (!SystemInfo.supportsImageEffects || !SystemInfo.supportsRenderTextures)
{
NotSupported ();
return false;
}
if (needDepth && !SystemInfo.SupportsRenderTextureFormat (RenderTextureFormat.Depth))
{
NotSupported ();
return false;
}
if (needDepth)
GetComponent<Camera>().depthTextureMode |= DepthTextureMode.Depth;
return true;
}
protected bool CheckSupport (bool needDepth, bool needHdr)
{
if (!CheckSupport(needDepth))
return false;
if (needHdr && !supportHDRTextures)
{
NotSupported ();
return false;
}
return true;
}
public bool Dx11Support ()
{
return supportDX11;
}
protected void ReportAutoDisable ()
{
Debug.LogWarning ("The image effect " + ToString() + " has been disabled as it's not supported on the current platform.");
}
// deprecated but needed for old effects to survive upgrading
bool CheckShader (Shader s)
{
Debug.Log("The shader " + s.ToString () + " on effect "+ ToString () + " is not part of the Unity 3.2+ effects suite anymore. For best performance and quality, please ensure you are using the latest Standard Assets Image Effects (Pro only) package.");
if (!s.isSupported)
{
NotSupported ();
return false;
}
else
{
return false;
}
}
protected void NotSupported ()
{
enabled = false;
isSupported = false;
return;
}
protected void DrawBorder (RenderTexture dest, Material material)
{
float x1;
float x2;
float y1;
float y2;
RenderTexture.active = dest;
bool invertY = true; // source.texelSize.y < 0.0ff;
// Set up the simple Matrix
GL.PushMatrix();
GL.LoadOrtho();
for (int i = 0; i < material.passCount; i++)
{
material.SetPass(i);
float y1_; float y2_;
if (invertY)
{
y1_ = 1.0f; y2_ = 0.0f;
}
else
{
y1_ = 0.0f; y2_ = 1.0f;
}
// left
x1 = 0.0f;
x2 = 0.0f + 1.0f/(dest.width*1.0f);
y1 = 0.0f;
y2 = 1.0f;
GL.Begin(GL.QUADS);
GL.TexCoord2(0.0f, y1_); GL.Vertex3(x1, y1, 0.1f);
GL.TexCoord2(1.0f, y1_); GL.Vertex3(x2, y1, 0.1f);
GL.TexCoord2(1.0f, y2_); GL.Vertex3(x2, y2, 0.1f);
GL.TexCoord2(0.0f, y2_); GL.Vertex3(x1, y2, 0.1f);
// right
x1 = 1.0f - 1.0f/(dest.width*1.0f);
x2 = 1.0f;
y1 = 0.0f;
y2 = 1.0f;
GL.TexCoord2(0.0f, y1_); GL.Vertex3(x1, y1, 0.1f);
GL.TexCoord2(1.0f, y1_); GL.Vertex3(x2, y1, 0.1f);
GL.TexCoord2(1.0f, y2_); GL.Vertex3(x2, y2, 0.1f);
GL.TexCoord2(0.0f, y2_); GL.Vertex3(x1, y2, 0.1f);
// top
x1 = 0.0f;
x2 = 1.0f;
y1 = 0.0f;
y2 = 0.0f + 1.0f/(dest.height*1.0f);
GL.TexCoord2(0.0f, y1_); GL.Vertex3(x1, y1, 0.1f);
GL.TexCoord2(1.0f, y1_); GL.Vertex3(x2, y1, 0.1f);
GL.TexCoord2(1.0f, y2_); GL.Vertex3(x2, y2, 0.1f);
GL.TexCoord2(0.0f, y2_); GL.Vertex3(x1, y2, 0.1f);
// bottom
x1 = 0.0f;
x2 = 1.0f;
y1 = 1.0f - 1.0f/(dest.height*1.0f);
y2 = 1.0f;
GL.TexCoord2(0.0f, y1_); GL.Vertex3(x1, y1, 0.1f);
GL.TexCoord2(1.0f, y1_); GL.Vertex3(x2, y1, 0.1f);
GL.TexCoord2(1.0f, y2_); GL.Vertex3(x2, y2, 0.1f);
GL.TexCoord2(0.0f, y2_); GL.Vertex3(x1, y2, 0.1f);
GL.End();
}
GL.PopMatrix();
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: b6f4318ec6c2bf643a0f9edfeeaba0ec
timeCreated: 1488826990
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: