-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
241 additions
and
0 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<effect> | ||
<name>Funky Fisheye</name> | ||
<description>A customizable Fisheye Lens overlay.</description> | ||
<author>Nomok</author> | ||
<BackgroundTexture>1</BackgroundTexture> | ||
<sampler> | ||
<index>1</index> | ||
<filter>linear</filter> | ||
</sampler> | ||
<parameter> | ||
<name>Aperture</name> | ||
<code>aperture</code> | ||
<description>Focal Length</description> | ||
<type>float</type> | ||
<property>edit</property> | ||
<value>210.0</value> | ||
</parameter> | ||
<parameter> | ||
<name>Curve Scale</name> | ||
<code>scale</code> | ||
<description>Intensity of the Fisheye Lens</description> | ||
<type>float</type> | ||
<property>edit</property> | ||
<value>2.0</value> | ||
</parameter> | ||
<parameter> | ||
<name>Effect Scale</name> | ||
<code>fScale</code> | ||
<description>Intensity of the Effect</description> | ||
<type>float</type> | ||
<property>edit</property> | ||
<value>1.0</value> | ||
</parameter> | ||
<parameter> | ||
<name>Grid Scale</name> | ||
<code>xScale</code> | ||
<description>Scale of the Fisheye Image</description> | ||
<type>float</type> | ||
<property>edit</property> | ||
<value>1.0</value> | ||
</parameter> | ||
<parameter> | ||
<name>Overlay Mode</name> | ||
<code>overlay</code> | ||
<description>Toggles if the Fisheye Lens is used as an Overlay</description> | ||
<type>int</type> | ||
<property>checkbox</property> | ||
<value>0</value> | ||
</parameter> | ||
<parameter> | ||
<name>Edge Mode</name> | ||
<code>edgemode</code> | ||
<description>0 - No Edges, 1 - Edges with Stretched Colors, 2 - Transparent Edges</description> | ||
<type>int</type> | ||
<property>edit</property> | ||
<value>0</value> | ||
</parameter> | ||
<parameter> | ||
<name>Edge Scale</name> | ||
<code>edgeScale</code> | ||
<description>Scale of the Edge</description> | ||
<description></description> | ||
<type>float</type> | ||
<property>edit</property> | ||
<value>1.0</value> | ||
</parameter> | ||
</effect> | ||
|
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#define PI 3.141569 | ||
|
||
sampler2D Tex0 : register(s0); | ||
sampler2D Tex1 : register(s1); | ||
|
||
float aperture; | ||
float scale; | ||
float fScale; | ||
float xScale; | ||
bool overlay; | ||
int edgemode; | ||
float edgeScale; | ||
|
||
float2 fisheye(float2 xy, float d) | ||
{ | ||
float z = scale*sqrt(1.0-d*d*fScale); | ||
float r = atan2(d,z)/PI; | ||
r*=xScale; | ||
float phi = atan2(xy.y,xy.x); | ||
|
||
return r*float2(cos(phi),sin(phi))+0.5; | ||
} | ||
|
||
|
||
float4 ps_main(in float2 texCoord : TEXCOORD0) : COLOR0 | ||
{ | ||
float4 Out; | ||
|
||
float2 output = texCoord; | ||
float maxFactor = sin(0.5*aperture*(PI/180.0)); | ||
|
||
float2 xy = 2.0*texCoord-1.0; | ||
float d = length(xy*maxFactor); | ||
|
||
//for whatever reason hlsl doesn't have switch statements | ||
if(edgemode==0) | ||
{ | ||
output = fisheye(xy,d); | ||
} | ||
if(edgemode==2) | ||
{ | ||
if(d < edgeScale * maxFactor) | ||
output = fisheye(xy,d); | ||
} | ||
if(edgemode==1) | ||
{ | ||
if(d < edgeScale * maxFactor) | ||
{ | ||
output = fisheye(xy,d); | ||
}else{ | ||
output = float2(0.0,0.0); | ||
} | ||
} | ||
|
||
Out = overlay ? tex2D(Tex1,output) : tex2D(Tex0,output); | ||
return Out; | ||
} | ||
|
||
technique tech_main { pass P0 { PixelShader = compile ps_2_a ps_main(); }} |
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 |
---|---|---|
@@ -0,0 +1,114 @@ | ||
#define PI 3.141569 | ||
|
||
Texture2D<float4> Tex0: register(t0); sampler _Tex0 : register(s0); | ||
Texture2D<float4> Tex1: register(t1); sampler _Tex1 : register(s1); | ||
|
||
cbuffer PS_VARIABLES : register(b0) | ||
{ | ||
float aperture; | ||
float scale; | ||
float fScale; | ||
float xScale; | ||
bool overlay; | ||
int edgemode; | ||
float edgeScale; | ||
} | ||
|
||
struct PS_INPUT | ||
{ | ||
float4 Tint : COLOR0; | ||
float2 texCoord : TEXCOORD0; | ||
float4 Position : SV_POSITION; | ||
}; | ||
|
||
struct PS_OUTPUT | ||
{ | ||
float4 Color : SV_TARGET; | ||
}; | ||
|
||
float4 GetColorPM(float4 Image) | ||
{ | ||
if ( Image.a != 0 ) | ||
Image.rgb /= Image.a; | ||
return Image; | ||
} | ||
|
||
float2 fisheye(float2 xy, float d) | ||
{ | ||
float z = scale*sqrt(1.0-d*d*fScale); | ||
float r = atan2(d,z)/PI; | ||
r*=xScale; | ||
float phi = atan2(xy.y,xy.x); | ||
|
||
return r*float2(cos(phi),sin(phi))+0.5; | ||
} | ||
|
||
float4 ps_main(in PS_INPUT In) : SV_TARGET | ||
{ | ||
float2 _texCoord = In.texCoord.xy; | ||
|
||
float2 output = _texCoord; | ||
float maxFactor = sin(0.5*aperture*(PI/180.0)); | ||
|
||
float2 xy = 2.0*_texCoord-1.0; | ||
float d = length(xy*maxFactor); | ||
|
||
if(edgemode==0) | ||
{ | ||
output = fisheye(xy,d); | ||
} | ||
if(edgemode==2) | ||
{ | ||
if(d < (maxFactor/fScale)*edgeScale) | ||
output = fisheye(xy,d); | ||
} | ||
if(edgemode==1) | ||
{ | ||
if(d < edgeScale * maxFactor) | ||
{ | ||
output = fisheye(xy,d); | ||
}else{ | ||
output = float2(0.0,0.0); | ||
} | ||
} | ||
|
||
float4 Out = overlay ? Tex1.Sample(_Tex1,output)*In.Tint : Tex0.Sample(_Tex0,output)*In.Tint; | ||
|
||
return Out; | ||
} | ||
|
||
float4 ps_main_pm(in PS_INPUT In) : SV_TARGET | ||
{ | ||
float2 _texCoord = In.texCoord.xy; | ||
|
||
float2 output = _texCoord; | ||
float maxFactor = sin(0.5*aperture*(PI/180.0)); | ||
|
||
float2 xy = 2.0*_texCoord-1.0; | ||
float d = length(xy*maxFactor); | ||
|
||
if(edgemode==0) | ||
{ | ||
output = fisheye(xy,d); | ||
} | ||
if(edgemode==2) | ||
{ | ||
if(d < edgeScale * maxFactor) | ||
output = fisheye(xy,d); | ||
} | ||
if(edgemode==1) | ||
{ | ||
if(d < edgeScale * maxFactor) | ||
{ | ||
output = fisheye(xy,d); | ||
}else{ | ||
output = float2(0.0,0.0); | ||
} | ||
} | ||
|
||
float4 Out = overlay ? Tex1.Sample(_Tex1,output) : Tex0.Sample(_Tex0,output); | ||
|
||
Out.rgb *= Out.a; | ||
Out *= In.Tint; | ||
return Out; | ||
} |