Skip to content

Commit 6080d41

Browse files
authored
Added post fx
Removed the janky glow code from the post_rim shader and made it it's own shader. This was done to minimize weird artifacts from the previous version which utilized the main screen texture with a texture format that supports values higher than 1.0f
1 parent bfe9359 commit 6080d41

File tree

10 files changed

+1193
-0
lines changed

10 files changed

+1193
-0
lines changed

post_glow/glow.fx

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
#define GLOW_SAMPLE 15 // anything above 20 is going to potentially cause lag
2+
3+
4+
float script : STANDARDSGLOBAL <
5+
string ScriptOutput = "color";
6+
string ScriptClass = "scene";
7+
string ScriptOrder = "postprocess";
8+
> = 0.8;
9+
10+
float2 screen_size : VIEWPORTPIXELSIZE;
11+
static float2 screen_offset = ((float2)0.5f / screen_size);
12+
float4 clear_color = {0.5f, 0.5f, 0.5f, 0.0};
13+
float clear_depth = 1.0;
14+
15+
// ==========================================================
16+
// TEXTURES
17+
texture2D screen_texture : RENDERCOLORTARGET < float2 ViewPortRatio = {1.0,1.0};
18+
int MipLevels = 0;
19+
>;
20+
texture2D depthstencil_texture : RENDERDEPTHSTENCILTARGET <
21+
// float2 ViewPortRatio = {1.0, 1.0};
22+
// string Format = "D3DFMT_D24S8";
23+
>;
24+
texture2D glow_texture : OFFSCREENRENDERTARGET
25+
<
26+
string Description = "glow texture ";
27+
float2 ViewPortRatio = {1.0f, 1.0f};
28+
float4 ClearColor = {0.0f, 0.0f, 0.0f, 1.0f};
29+
float ClearDepth = 1.0f;
30+
bool AntiAlias = false;
31+
int Miplevels = 0;
32+
string DefaultEffect =
33+
"self=hide;"
34+
"*=glow_off.fx;";
35+
>;
36+
37+
// ==========================================================
38+
// SAMPLERS
39+
40+
sampler screen_sampler = sampler_state
41+
{
42+
texture = <screen_texture>;
43+
FILTER = ANISOTROPIC;
44+
ADDRESSV = CLAMP;
45+
ADDRESSU = CLAMP;
46+
};
47+
48+
sampler glow_sampler = sampler_state
49+
{
50+
texture = <glow_texture>;
51+
FILTER = ANISOTROPIC;
52+
ADDRESSV = CLAMP;
53+
ADDRESSU = CLAMP;
54+
};
55+
56+
57+
static float pi = 3.1415926;
58+
static int samples = GLOW_SAMPLE;
59+
static float sigma = (float)samples * 0.25;
60+
static float s = 2 * sigma * sigma;
61+
62+
float gauss(float2 i)
63+
{
64+
65+
return exp(-(i.x * i.x + i.y * i.y) / s) / (pi * s);
66+
}
67+
68+
float3 gaussianBlur(sampler sp, float2 uv, float2 scale)
69+
{
70+
float3 pixel = (float3)0.0f;
71+
float weightSum = 0.0f;
72+
float weight;
73+
float2 offset;
74+
75+
for(int i = -samples / 2; i < samples / 2; i++)
76+
{
77+
for(int j = -samples / 2; j < samples / 2; j++)
78+
{
79+
offset = float2(i, j);
80+
weight = gauss(offset);
81+
pixel += tex2Dlod(sp, float4(uv + scale * offset, 0.0f, 1.0f)).rgb * weight;
82+
weightSum += weight;
83+
}
84+
}
85+
return pixel / weightSum;
86+
}
87+
88+
89+
90+
// ==========================================================
91+
// STRUCTURE
92+
struct vs_out
93+
{
94+
float4 pos : POSITION;
95+
float2 uv : TEXCOORD0;
96+
};
97+
98+
// ==========================================================
99+
// VERTEX AND PIXEL SHADER
100+
vs_out vs_0(float4 pos : POSITION, float2 uv : TEXCOORD0)
101+
{
102+
vs_out o;
103+
o.pos = pos;
104+
o.uv = uv + screen_offset;
105+
return o;
106+
}
107+
108+
float4 ps_0(vs_out i) : COLOR
109+
{
110+
float4 color = (float4)1.0f;
111+
float2 uv = i.uv;
112+
color.xyz = color * tex2D(screen_sampler, uv);
113+
float3 glow = gaussianBlur(glow_sampler, uv, (float2)1.0f / screen_size.xy);
114+
color.xyz = color.xyz + glow;
115+
116+
return color;
117+
}
118+
119+
technique post_test <
120+
string Script =
121+
"RenderColorTarget0=screen_texture;"
122+
"RenderDepthStencilTarget=depthstencil_texture;"
123+
"ClearSetColor=clear_color;"
124+
"ClearSetDepth=clear_depth;"
125+
"Clear=Color;"
126+
"Clear=Depth;"
127+
"ScriptExternal=Color;"
128+
129+
130+
//final pass
131+
"RenderColorTarget0=;"
132+
"RenderDepthStencilTarget=;"
133+
"ClearSetColor=clear_color;"
134+
"ClearSetDepth=clear_depth;"
135+
"Clear=Color;"
136+
"Clear=Depth;"
137+
"Pass=drawFinal;"
138+
;
139+
>
140+
{
141+
pass drawFinal <string Script = "RenderColorTarget0=;"
142+
"RenderDepthStencilTarget=;""Draw=Buffer;";>
143+
{
144+
145+
VertexShader = compile vs_3_0 vs_0();
146+
ZEnable = false;
147+
ZWriteEnable = false;
148+
AlphaBlendEnable = true;
149+
CullMode = None;
150+
PixelShader = compile ps_3_0 ps_0();
151+
}
152+
}

post_glow/glow.x

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
xof 0303txt 0032
2+
template Vector {
3+
<3d82ab5e-62da-11cf-ab39-0020af71e433>
4+
FLOAT x;
5+
FLOAT y;
6+
FLOAT z;
7+
}
8+
9+
template MeshFace {
10+
<3d82ab5f-62da-11cf-ab39-0020af71e433>
11+
DWORD nFaceVertexIndices;
12+
array DWORD faceVertexIndices[nFaceVertexIndices];
13+
}
14+
15+
template Mesh {
16+
<3d82ab44-62da-11cf-ab39-0020af71e433>
17+
DWORD nVertices;
18+
array Vector vertices[nVertices];
19+
DWORD nFaces;
20+
array MeshFace faces[nFaces];
21+
[...]
22+
}
23+
24+
template MeshNormals {
25+
<f6f23f43-7686-11cf-8f52-0040333594a3>
26+
DWORD nNormals;
27+
array Vector normals[nNormals];
28+
DWORD nFaceNormals;
29+
array MeshFace faceNormals[nFaceNormals];
30+
}
31+
32+
template Coords2d {
33+
<f6f23f44-7686-11cf-8f52-0040333594a3>
34+
FLOAT u;
35+
FLOAT v;
36+
}
37+
38+
template MeshTextureCoords {
39+
<f6f23f40-7686-11cf-8f52-0040333594a3>
40+
DWORD nTextureCoords;
41+
array Coords2d textureCoords[nTextureCoords];
42+
}
43+
44+
template ColorRGBA {
45+
<35ff44e0-6c7c-11cf-8f52-0040333594a3>
46+
FLOAT red;
47+
FLOAT green;
48+
FLOAT blue;
49+
FLOAT alpha;
50+
}
51+
52+
template ColorRGB {
53+
<d3e16e81-7835-11cf-8f52-0040333594a3>
54+
FLOAT red;
55+
FLOAT green;
56+
FLOAT blue;
57+
}
58+
59+
template Material {
60+
<3d82ab4d-62da-11cf-ab39-0020af71e433>
61+
ColorRGBA faceColor;
62+
FLOAT power;
63+
ColorRGB specularColor;
64+
ColorRGB emissiveColor;
65+
[...]
66+
}
67+
68+
template MeshMaterialList {
69+
<f6f23f42-7686-11cf-8f52-0040333594a3>
70+
DWORD nMaterials;
71+
DWORD nFaceIndexes;
72+
array DWORD faceIndexes[nFaceIndexes];
73+
[Material <3d82ab4d-62da-11cf-ab39-0020af71e433>]
74+
}
75+
76+
77+
Mesh {
78+
4;
79+
0.100000;0.000000;0.100000;,
80+
-0.100000;0.000000;-0.100000;,
81+
-0.100000;0.000000;0.100000;,
82+
0.100000;0.000000;-0.100000;;
83+
2;
84+
3;0,1,2;,
85+
3;1,0,3;;
86+
87+
MeshNormals {
88+
4;
89+
0.000000;1.000000;0.000000;,
90+
0.000000;1.000000;0.000000;,
91+
0.000000;1.000000;0.000000;,
92+
0.000000;1.000000;0.000000;;
93+
2;
94+
3;0,1,2;,
95+
3;1,0,3;;
96+
}
97+
98+
MeshTextureCoords {
99+
4;
100+
0.000000;0.000000;,
101+
0.000000;0.000000;,
102+
0.000000;0.000000;,
103+
0.000000;0.000000;;
104+
}
105+
106+
MeshMaterialList {
107+
1;
108+
2;
109+
0,
110+
0;
111+
112+
Material {
113+
0.000000;0.000000;0.000000;1.000000;;
114+
0.000000;
115+
0.000000;0.000000;0.000000;;
116+
0.000000;0.000000;0.000000;;
117+
}
118+
}
119+
}

post_glow/glow_off.fx

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#define EMISSION_TOGGLE 0 // 0: off, 1: on
2+
#define ALPHA_TYPE 0 // 0 : NONE, 1 : ALPHA ON, 2: ALPHA CLIP
3+
// an alpha type of 0 will disable the glow
4+
#define ALPHA_CLIP_RATE 0.5f
5+
6+
float4x4 mm_wvp : WORLDVIEWPROJECTION;
7+
float4x4 mm_view : VIEW;
8+
#ifdef MIKUMIKUMOVING
9+
float3 light_direction[MMM_LightCount] : LIGHTDIRECTIONS;
10+
bool light_enable[MMM_LightCount] : LIGHTENABLES;
11+
float3 light_ambients[MMM_LightCount] : LIGHTAMBIENTCOLORS;
12+
#else
13+
float3 light_direction : DIRECTION < string Object = "Light"; >;
14+
#endif
15+
bool use_texture;
16+
texture2D diffuse_texture : MATERIALTEXTURE;
17+
sampler2D diffuse_sampler = sampler_state
18+
{
19+
texture = < diffuse_texture >;
20+
FILTER = ANISOTROPIC;
21+
ADDRESSU = WRAP;
22+
ADDRESSV = WRAP;
23+
};
24+
25+
struct vs_in
26+
{
27+
float4 pos : POSITION;
28+
float3 normal : TEXCOORD4;
29+
float2 uv_a : TEXCOORD0;
30+
float2 uv_b : TEXCOORD1;
31+
float4 vertex : TEXCOORD2;
32+
// float3 tangent : TEXCOORD4;
33+
};
34+
35+
struct vs_out
36+
{
37+
float4 pos : POSITION;
38+
float3 normal : TEXCOORD0;
39+
float2 uv : TEXCOORD1;
40+
};
41+
42+
#ifdef MIKUMIKUMOVING
43+
vs_out vs_model(MMM_SKINNING_INPUT IN,vs_in i)
44+
{
45+
MMM_SKINNING_OUTPUT mmm = MMM_SkinnedPositionNormal(IN.Pos, IN.Normal, IN.BlendWeight, IN.BlendIndices, IN.SdefC, IN.SdefR0, IN.SdefR1);
46+
i.pos = mmm.Position;
47+
i.normal = mmm.Normal;
48+
#else
49+
vs_out vs_model(vs_in i)
50+
{
51+
#endif
52+
vs_out o;
53+
// i.pos.xyz = i.pos.xyz + i.normal * 0.05f * i.vertex.a;
54+
o.pos = mul(i.pos, mm_wvp);
55+
o.normal = i.normal;
56+
o.uv = i.uv_a;
57+
return o;
58+
}
59+
60+
float4 ps_model(vs_out i) : COLOR0
61+
{
62+
// #ifdef MIKUMIKUMOVING
63+
// float ndotl = dot(i.normal, -light_direction[0].xyz);
64+
// #else
65+
// float ndotl = dot(i.normal, -light_direction.xyz);
66+
// #endif
67+
float3 emission = (float3)1.0f;
68+
float alpha = 1.0f;
69+
70+
if(use_texture)
71+
{
72+
// sample alpha if it has a texture
73+
float4 diffuse = tex2D(diffuse_sampler, i.uv);
74+
emission.xyz = diffuse.xyz * diffuse.w;
75+
#if ALPHA_TYPE == 1
76+
alpha = alpha * diffuse.w;
77+
#if ALPHA_TYPE == 2
78+
clip(alpha - ALPHA_CLIP_RATE);
79+
#endif
80+
#endif
81+
}
82+
#if EMISSION_TOGGLE == 0
83+
emission = (float3)0.0f;
84+
#endif
85+
return float4(emission, alpha);
86+
}
87+
88+
89+
technique model_ss_tech < string MMDPass = "object_ss"; >
90+
{
91+
pass model_front
92+
{
93+
cullmode = none;
94+
VertexShader = compile vs_3_0 vs_model();
95+
PixelShader = compile ps_3_0 ps_model();
96+
}
97+
};
98+
99+
100+
technique model_tech < string MMDPass = "object"; >
101+
{
102+
pass model_front
103+
{
104+
cullmode = none;
105+
VertexShader = compile vs_3_0 vs_model();
106+
PixelShader = compile ps_3_0 ps_model();
107+
}
108+
}
109+
110+
technique mmd_shadow < string MMDPass = "shadow"; > {}
111+
technique mmd_edge < string MMDPass = "edge"; > {}

0 commit comments

Comments
 (0)