Skip to content

Commit

Permalink
fixed major bug with metrics (thx to nightfox696)
Browse files Browse the repository at this point in the history
  • Loading branch information
m10914 committed Jan 2, 2014
1 parent 9b39d5f commit b1b9425
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
6 changes: 5 additions & 1 deletion SMAA/SMAA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
public class SMAA : MonoBehaviour
{
public bool ApplyEffect;
public int State = 3;
public int State = 1;
public int Passes = 1;

private Texture2D black;
Expand Down Expand Up @@ -42,6 +42,8 @@ void OnRenderImage(RenderTexture source, RenderTexture destination)
{
Graphics.Blit(black, destination);

Vector4 metrics = new Vector4(1 / (float)Screen.width, 1 / (float)Screen.height, Screen.width, Screen.height);

if (this.ApplyEffect)
{
if (State == 1)
Expand All @@ -53,6 +55,7 @@ void OnRenderImage(RenderTexture source, RenderTexture destination)
mat.SetTexture("areaTex", GameObject.Find("TextureGenerator").GetComponent<AreaTexture>().alphaTex);
mat.SetTexture("luminTex", GameObject.Find("TextureGenerator").GetComponent<AreaTexture>().luminTex);
mat.SetTexture("searchTex", GameObject.Find("TextureGenerator").GetComponent<SearchTexture>().alphaTex);
mat.SetVector("SMAA_RT_METRICS", metrics);

var rt = RenderTexture.GetTemporary(Screen.width, Screen.height, 0);

Expand All @@ -67,6 +70,7 @@ void OnRenderImage(RenderTexture source, RenderTexture destination)
mat.SetTexture("luminTex", GameObject.Find("TextureGenerator").GetComponent<AreaTexture>().luminTex);
mat.SetTexture("searchTex", GameObject.Find("TextureGenerator").GetComponent<SearchTexture>().alphaTex);
mat.SetTexture("_SrcTex", source);
mat.SetVector("SMAA_RT_METRICS", metrics);

var rt = RenderTexture.GetTemporary(Screen.width, Screen.height, 0);
var rt2 = RenderTexture.GetTemporary(Screen.width, Screen.height, 0);
Expand Down
13 changes: 9 additions & 4 deletions SMAA/SMAAshader.shader
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
areaTex ("area texture", 2D) = "white" {}
luminTex ("lumin texture", 2D) = "white" {}
searchTex ("search texture", 2D) = "white" {}
SMAA_RT_METRICS ("rt metrics", Vector) = (0,0,0,0)
}
SubShader {
Tags { "RenderType"="Opaque" }
Expand Down Expand Up @@ -38,14 +39,15 @@
#pragma target 3.0

#define mad(a, b, c) (a * b + c)
#define SMAA_RT_METRICS float4(1.0 / 1280.0, 1.0 / 720.0, 1280.0, 720.0)
//#define SMAA_RT_METRICS float4(1.0 / 1280.0, 1.0 / 720.0, 1280.0, 720.0)
#define SMAA_THRESHOLD 0.05
#define SMAA_MAX_SEARCH_STEPS 32
#define SMAA_MAX_SEARCH_STEPS_DIAG 16
#define SMAA_CORNER_ROUNDING 25
#define SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR 2.0

sampler2D _MainTex;
float4 SMAA_RT_METRICS;

struct vertOUT
{
Expand Down Expand Up @@ -162,7 +164,7 @@
#pragma glsl

#define mad(a, b, c) (a * b + c)
#define SMAA_RT_METRICS float4(1.0 / 1280.0, 1.0 / 720.0, 1280.0, 720.0)
//#define SMAA_RT_METRICS float4(1.0 / 1280.0, 1.0 / 720.0, 1280.0, 720.0)
#define SMAA_THRESHOLD 0.05
#define SMAA_MAX_SEARCH_STEPS 32
#define SMAA_MAX_SEARCH_STEPS_DIAG 16
Expand All @@ -179,6 +181,7 @@
sampler2D areaTex;
sampler2D searchTex;
sampler2D luminTex;
float4 SMAA_RT_METRICS;

//--------------------------------------------------------
// S M A A framework
Expand Down Expand Up @@ -567,7 +570,7 @@ float2 SMAADetectVerticalCornerPattern(float2 weights, float2 texcoord, float2 d
#pragma glsl

#define mad(a, b, c) (a * b + c)
#define SMAA_RT_METRICS float4(1.0 / 1280.0, 1.0 / 720.0, 1280.0, 720.0)
//#define SMAA_RT_METRICS float4(1.0 / 1280.0, 1.0 / 720.0, 1280.0, 720.0)
#define SMAA_THRESHOLD 0.05
#define SMAA_MAX_SEARCH_STEPS 32
#define SMAA_MAX_SEARCH_STEPS_DIAG 16
Expand All @@ -576,6 +579,7 @@ float2 SMAADetectVerticalCornerPattern(float2 weights, float2 texcoord, float2 d

sampler2D _MainTex;
sampler2D _SrcTex;
float4 SMAA_RT_METRICS;

//-------------------------------------------------
// S M A A framework
Expand Down Expand Up @@ -672,14 +676,15 @@ void SMAAMovc(float4 cond, inout float4 variable, float4 value) {
#pragma glsl

#define mad(a, b, c) (a * b + c)
#define SMAA_RT_METRICS float4(1.0 / 1280.0, 1.0 / 720.0, 1280.0, 720.0)
//#define SMAA_RT_METRICS float4(1.0 / 1280.0, 1.0 / 720.0, 1280.0, 720.0)
#define SMAA_THRESHOLD 0.05
#define SMAA_MAX_SEARCH_STEPS 32
#define SMAA_MAX_SEARCH_STEPS_DIAG 16
#define SMAA_CORNER_ROUNDING 25
#define SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR 2.0

sampler2D _MainTex;
float4 SMAA_RT_METRICS;

struct vertOUT
{
Expand Down
4 changes: 4 additions & 0 deletions TestScene/Assets/SMAA/SMAA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ void OnRenderImage(RenderTexture source, RenderTexture destination)
{
Graphics.Blit(black, destination);

Vector4 metrics = new Vector4(1 / (float)Screen.width, 1 / (float)Screen.height, Screen.width, Screen.height);

if (this.ApplyEffect)
{
if (State == 1)
Expand All @@ -53,6 +55,7 @@ void OnRenderImage(RenderTexture source, RenderTexture destination)
mat.SetTexture("areaTex", GameObject.Find("TextureGenerator").GetComponent<AreaTexture>().alphaTex);
mat.SetTexture("luminTex", GameObject.Find("TextureGenerator").GetComponent<AreaTexture>().luminTex);
mat.SetTexture("searchTex", GameObject.Find("TextureGenerator").GetComponent<SearchTexture>().alphaTex);
mat.SetVector("SMAA_RT_METRICS", metrics);

var rt = RenderTexture.GetTemporary(Screen.width, Screen.height, 0);

Expand All @@ -67,6 +70,7 @@ void OnRenderImage(RenderTexture source, RenderTexture destination)
mat.SetTexture("luminTex", GameObject.Find("TextureGenerator").GetComponent<AreaTexture>().luminTex);
mat.SetTexture("searchTex", GameObject.Find("TextureGenerator").GetComponent<SearchTexture>().alphaTex);
mat.SetTexture("_SrcTex", source);
mat.SetVector("SMAA_RT_METRICS", metrics);

var rt = RenderTexture.GetTemporary(Screen.width, Screen.height, 0);
var rt2 = RenderTexture.GetTemporary(Screen.width, Screen.height, 0);
Expand Down
13 changes: 9 additions & 4 deletions TestScene/Assets/SMAA/SMAAshader.shader
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
areaTex ("area texture", 2D) = "white" {}
luminTex ("lumin texture", 2D) = "white" {}
searchTex ("search texture", 2D) = "white" {}
SMAA_RT_METRICS ("rt metrics", Vector) = (0,0,0,0)
}
SubShader {
Tags { "RenderType"="Opaque" }
Expand Down Expand Up @@ -38,14 +39,15 @@
#pragma target 3.0

#define mad(a, b, c) (a * b + c)
#define SMAA_RT_METRICS float4(1.0 / 1280.0, 1.0 / 720.0, 1280.0, 720.0)
//#define SMAA_RT_METRICS float4(1.0 / 1280.0, 1.0 / 720.0, 1280.0, 720.0)
#define SMAA_THRESHOLD 0.05
#define SMAA_MAX_SEARCH_STEPS 32
#define SMAA_MAX_SEARCH_STEPS_DIAG 16
#define SMAA_CORNER_ROUNDING 25
#define SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR 2.0

sampler2D _MainTex;
float4 SMAA_RT_METRICS;

struct vertOUT
{
Expand Down Expand Up @@ -162,7 +164,7 @@
#pragma glsl

#define mad(a, b, c) (a * b + c)
#define SMAA_RT_METRICS float4(1.0 / 1280.0, 1.0 / 720.0, 1280.0, 720.0)
//#define SMAA_RT_METRICS float4(1.0 / 1280.0, 1.0 / 720.0, 1280.0, 720.0)
#define SMAA_THRESHOLD 0.05
#define SMAA_MAX_SEARCH_STEPS 32
#define SMAA_MAX_SEARCH_STEPS_DIAG 16
Expand All @@ -179,6 +181,7 @@
sampler2D areaTex;
sampler2D searchTex;
sampler2D luminTex;
float4 SMAA_RT_METRICS;

//--------------------------------------------------------
// S M A A framework
Expand Down Expand Up @@ -567,7 +570,7 @@ float2 SMAADetectVerticalCornerPattern(float2 weights, float2 texcoord, float2 d
#pragma glsl

#define mad(a, b, c) (a * b + c)
#define SMAA_RT_METRICS float4(1.0 / 1280.0, 1.0 / 720.0, 1280.0, 720.0)
//#define SMAA_RT_METRICS float4(1.0 / 1280.0, 1.0 / 720.0, 1280.0, 720.0)
#define SMAA_THRESHOLD 0.05
#define SMAA_MAX_SEARCH_STEPS 32
#define SMAA_MAX_SEARCH_STEPS_DIAG 16
Expand All @@ -576,6 +579,7 @@ float2 SMAADetectVerticalCornerPattern(float2 weights, float2 texcoord, float2 d

sampler2D _MainTex;
sampler2D _SrcTex;
float4 SMAA_RT_METRICS;

//-------------------------------------------------
// S M A A framework
Expand Down Expand Up @@ -672,14 +676,15 @@ void SMAAMovc(float4 cond, inout float4 variable, float4 value) {
#pragma glsl

#define mad(a, b, c) (a * b + c)
#define SMAA_RT_METRICS float4(1.0 / 1280.0, 1.0 / 720.0, 1280.0, 720.0)
//#define SMAA_RT_METRICS float4(1.0 / 1280.0, 1.0 / 720.0, 1280.0, 720.0)
#define SMAA_THRESHOLD 0.05
#define SMAA_MAX_SEARCH_STEPS 32
#define SMAA_MAX_SEARCH_STEPS_DIAG 16
#define SMAA_CORNER_ROUNDING 25
#define SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR 2.0

sampler2D _MainTex;
float4 SMAA_RT_METRICS;

struct vertOUT
{
Expand Down

0 comments on commit b1b9425

Please sign in to comment.