-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathTinyPlanet.fx
More file actions
92 lines (71 loc) · 2.56 KB
/
TinyPlanet.fx
File metadata and controls
92 lines (71 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*-----------------------------------------------------------------------------------------------------*/
/* Tiny Planet Shader - by Radegast Stravinsky of Ultros. */
/* There are plenty of shaders that make your game look amazing. This isn't one of them. */
/*-----------------------------------------------------------------------------------------------------*/
#include "Include/TinyPlanet.fxh"
#include "Reshade.fxh"
texture texColorBuffer : COLOR;
texture texDepthBuffer : DEPTH;
texture TinyPlanetTarget
{
Width = BUFFER_WIDTH;
Height = BUFFER_HEIGHT;
MipLevels = LINEAR;
Format = RGBA8;
};
sampler samplerColor
{
Texture = texColorBuffer;
AddressU = WRAP;
AddressV = WRAP;
AddressW = WRAP;
MagFilter = LINEAR;
MinFilter = LINEAR;
MipFilter = LINEAR;
MinLOD = 0.0f;
MaxLOD = 1000.0f;
MipLODBias = 0.0f;
SRGBTexture = false;
};
// Pixel Shaders (in order of appearance in the technique)
float4 PreTP(float4 pos : SV_Position, float2 texcoord : TEXCOORD0) : SV_TARGET
{
const float inv_seam = 1 - seam_scale;
float4 tc1 = tex2D(samplerColor, texcoord + float2(inv_seam, 0.0));
float4 tc = tex2D(samplerColor, texcoord * float2(seam_scale, 1.0));
if(texcoord.x < inv_seam){
tc.rgb = lerp(tc1.rgb, tc.rgb, 1- clamp((inv_seam-texcoord.x) * 10., 0, 1));
}
if(texcoord.x > seam_scale) tc.rgb = lerp(tc.rgb, tc1.rgb, clamp((texcoord.x-seam_scale) * 10., 0, 1));
return tc;
}
float4 TinyPlanet(float4 pos : SV_Position, float2 texcoord : TEXCOORD0) : SV_TARGET
{
const float ar = 1.0 * (float)BUFFER_HEIGHT / (float)BUFFER_WIDTH;
const float3x3 rot = getrot(float3(lerp(0,360,x_coord),lerp(0, 360,y_coord), z_rotation));
const float2 rads = float2(PI * 2.0 , PI);
const float2 pnt = (texcoord - 0.5 - offset).xy * float2(scale, scale*ar);
// Project to Sphere
const float x2y2 = pnt.x * pnt.x + pnt.y * pnt.y;
float3 sphere_pnt = float3(2.0 * pnt, x2y2 - 1.0) / (x2y2 + 1.0);
sphere_pnt = mul(sphere_pnt, rot);
// Convert to Spherical Coordinates
const float r = length(sphere_pnt);
const float lon = atan2(sphere_pnt.y, sphere_pnt.x);
const float lat = acos(sphere_pnt.z / r);
return tex2D(samplerColor, float2(lon, lat) / rads);
}
// Technique
technique TinyPlanet <ui_label="Tiny Planet";>
{
pass p0
{
VertexShader = PostProcessVS;
PixelShader = PreTP;
}
pass p1
{
VertexShader = PostProcessVS;
PixelShader = TinyPlanet;
}
};