diff --git a/post_glow/glow.fx b/post_glow/glow.fx new file mode 100644 index 0000000..c593034 --- /dev/null +++ b/post_glow/glow.fx @@ -0,0 +1,152 @@ +#define GLOW_SAMPLE 15 // anything above 20 is going to potentially cause lag + + +float script : STANDARDSGLOBAL < + string ScriptOutput = "color"; + string ScriptClass = "scene"; + string ScriptOrder = "postprocess"; +> = 0.8; + +float2 screen_size : VIEWPORTPIXELSIZE; +static float2 screen_offset = ((float2)0.5f / screen_size); +float4 clear_color = {0.5f, 0.5f, 0.5f, 0.0}; +float clear_depth = 1.0; + +// ========================================================== +// TEXTURES +texture2D screen_texture : RENDERCOLORTARGET < float2 ViewPortRatio = {1.0,1.0}; + int MipLevels = 0; +>; +texture2D depthstencil_texture : RENDERDEPTHSTENCILTARGET < + // float2 ViewPortRatio = {1.0, 1.0}; + // string Format = "D3DFMT_D24S8"; +>; +texture2D glow_texture : OFFSCREENRENDERTARGET +< + string Description = "glow texture "; + float2 ViewPortRatio = {1.0f, 1.0f}; + float4 ClearColor = {0.0f, 0.0f, 0.0f, 1.0f}; + float ClearDepth = 1.0f; + bool AntiAlias = false; + int Miplevels = 0; + string DefaultEffect = + "self=hide;" + "*=glow_off.fx;"; +>; + +// ========================================================== +// SAMPLERS + +sampler screen_sampler = sampler_state +{ + texture = ; + FILTER = ANISOTROPIC; + ADDRESSV = CLAMP; + ADDRESSU = CLAMP; +}; + +sampler glow_sampler = sampler_state +{ + texture = ; + FILTER = ANISOTROPIC; + ADDRESSV = CLAMP; + ADDRESSU = CLAMP; +}; + + +static float pi = 3.1415926; +static int samples = GLOW_SAMPLE; +static float sigma = (float)samples * 0.25; +static float s = 2 * sigma * sigma; + +float gauss(float2 i) +{ + + return exp(-(i.x * i.x + i.y * i.y) / s) / (pi * s); +} + +float3 gaussianBlur(sampler sp, float2 uv, float2 scale) +{ + float3 pixel = (float3)0.0f; + float weightSum = 0.0f; + float weight; + float2 offset; + + for(int i = -samples / 2; i < samples / 2; i++) + { + for(int j = -samples / 2; j < samples / 2; j++) + { + offset = float2(i, j); + weight = gauss(offset); + pixel += tex2Dlod(sp, float4(uv + scale * offset, 0.0f, 1.0f)).rgb * weight; + weightSum += weight; + } + } + return pixel / weightSum; +} + + + +// ========================================================== +// STRUCTURE +struct vs_out +{ + float4 pos : POSITION; + float2 uv : TEXCOORD0; +}; + +// ========================================================== +// VERTEX AND PIXEL SHADER +vs_out vs_0(float4 pos : POSITION, float2 uv : TEXCOORD0) +{ + vs_out o; + o.pos = pos; + o.uv = uv + screen_offset; + return o; +} + +float4 ps_0(vs_out i) : COLOR +{ + float4 color = (float4)1.0f; + float2 uv = i.uv; + color.xyz = color * tex2D(screen_sampler, uv); + float3 glow = gaussianBlur(glow_sampler, uv, (float2)1.0f / screen_size.xy); + color.xyz = color.xyz + glow; + + return color; +} + +technique post_test < + string Script = + "RenderColorTarget0=screen_texture;" + "RenderDepthStencilTarget=depthstencil_texture;" + "ClearSetColor=clear_color;" + "ClearSetDepth=clear_depth;" + "Clear=Color;" + "Clear=Depth;" + "ScriptExternal=Color;" + + + //final pass + "RenderColorTarget0=;" + "RenderDepthStencilTarget=;" + "ClearSetColor=clear_color;" + "ClearSetDepth=clear_depth;" + "Clear=Color;" + "Clear=Depth;" + "Pass=drawFinal;" + ; +> +{ + pass drawFinal + { + + VertexShader = compile vs_3_0 vs_0(); + ZEnable = false; + ZWriteEnable = false; + AlphaBlendEnable = true; + CullMode = None; + PixelShader = compile ps_3_0 ps_0(); + } +} diff --git a/post_glow/glow.x b/post_glow/glow.x new file mode 100644 index 0000000..eb77eb2 --- /dev/null +++ b/post_glow/glow.x @@ -0,0 +1,119 @@ +xof 0303txt 0032 +template Vector { + <3d82ab5e-62da-11cf-ab39-0020af71e433> + FLOAT x; + FLOAT y; + FLOAT z; +} + +template MeshFace { + <3d82ab5f-62da-11cf-ab39-0020af71e433> + DWORD nFaceVertexIndices; + array DWORD faceVertexIndices[nFaceVertexIndices]; +} + +template Mesh { + <3d82ab44-62da-11cf-ab39-0020af71e433> + DWORD nVertices; + array Vector vertices[nVertices]; + DWORD nFaces; + array MeshFace faces[nFaces]; + [...] +} + +template MeshNormals { + + DWORD nNormals; + array Vector normals[nNormals]; + DWORD nFaceNormals; + array MeshFace faceNormals[nFaceNormals]; +} + +template Coords2d { + + FLOAT u; + FLOAT v; +} + +template MeshTextureCoords { + + DWORD nTextureCoords; + array Coords2d textureCoords[nTextureCoords]; +} + +template ColorRGBA { + <35ff44e0-6c7c-11cf-8f52-0040333594a3> + FLOAT red; + FLOAT green; + FLOAT blue; + FLOAT alpha; +} + +template ColorRGB { + + FLOAT red; + FLOAT green; + FLOAT blue; +} + +template Material { + <3d82ab4d-62da-11cf-ab39-0020af71e433> + ColorRGBA faceColor; + FLOAT power; + ColorRGB specularColor; + ColorRGB emissiveColor; + [...] +} + +template MeshMaterialList { + + DWORD nMaterials; + DWORD nFaceIndexes; + array DWORD faceIndexes[nFaceIndexes]; + [Material <3d82ab4d-62da-11cf-ab39-0020af71e433>] +} + + +Mesh { + 4; + 0.100000;0.000000;0.100000;, + -0.100000;0.000000;-0.100000;, + -0.100000;0.000000;0.100000;, + 0.100000;0.000000;-0.100000;; + 2; + 3;0,1,2;, + 3;1,0,3;; + + MeshNormals { + 4; + 0.000000;1.000000;0.000000;, + 0.000000;1.000000;0.000000;, + 0.000000;1.000000;0.000000;, + 0.000000;1.000000;0.000000;; + 2; + 3;0,1,2;, + 3;1,0,3;; + } + + MeshTextureCoords { + 4; + 0.000000;0.000000;, + 0.000000;0.000000;, + 0.000000;0.000000;, + 0.000000;0.000000;; + } + + MeshMaterialList { + 1; + 2; + 0, + 0; + + Material { + 0.000000;0.000000;0.000000;1.000000;; + 0.000000; + 0.000000;0.000000;0.000000;; + 0.000000;0.000000;0.000000;; + } + } +} \ No newline at end of file diff --git a/post_glow/glow_off.fx b/post_glow/glow_off.fx new file mode 100644 index 0000000..f27ad8b --- /dev/null +++ b/post_glow/glow_off.fx @@ -0,0 +1,111 @@ +#define EMISSION_TOGGLE 0 // 0: off, 1: on +#define ALPHA_TYPE 0 // 0 : NONE, 1 : ALPHA ON, 2: ALPHA CLIP +// an alpha type of 0 will disable the glow +#define ALPHA_CLIP_RATE 0.5f + +float4x4 mm_wvp : WORLDVIEWPROJECTION; +float4x4 mm_view : VIEW; +#ifdef MIKUMIKUMOVING +float3 light_direction[MMM_LightCount] : LIGHTDIRECTIONS; +bool light_enable[MMM_LightCount] : LIGHTENABLES; +float3 light_ambients[MMM_LightCount] : LIGHTAMBIENTCOLORS; +#else +float3 light_direction : DIRECTION < string Object = "Light"; >; +#endif +bool use_texture; +texture2D diffuse_texture : MATERIALTEXTURE; +sampler2D diffuse_sampler = sampler_state +{ + texture = < diffuse_texture >; + FILTER = ANISOTROPIC; + ADDRESSU = WRAP; + ADDRESSV = WRAP; +}; + +struct vs_in +{ + float4 pos : POSITION; + float3 normal : TEXCOORD4; + float2 uv_a : TEXCOORD0; + float2 uv_b : TEXCOORD1; + float4 vertex : TEXCOORD2; + // float3 tangent : TEXCOORD4; +}; + +struct vs_out +{ + float4 pos : POSITION; + float3 normal : TEXCOORD0; + float2 uv : TEXCOORD1; +}; + +#ifdef MIKUMIKUMOVING +vs_out vs_model(MMM_SKINNING_INPUT IN,vs_in i) +{ + MMM_SKINNING_OUTPUT mmm = MMM_SkinnedPositionNormal(IN.Pos, IN.Normal, IN.BlendWeight, IN.BlendIndices, IN.SdefC, IN.SdefR0, IN.SdefR1); + i.pos = mmm.Position; + i.normal = mmm.Normal; +#else +vs_out vs_model(vs_in i) +{ +#endif + vs_out o; + // i.pos.xyz = i.pos.xyz + i.normal * 0.05f * i.vertex.a; + o.pos = mul(i.pos, mm_wvp); + o.normal = i.normal; + o.uv = i.uv_a; + return o; +} + +float4 ps_model(vs_out i) : COLOR0 +{ + // #ifdef MIKUMIKUMOVING + // float ndotl = dot(i.normal, -light_direction[0].xyz); + // #else + // float ndotl = dot(i.normal, -light_direction.xyz); + // #endif + float3 emission = (float3)1.0f; + float alpha = 1.0f; + + if(use_texture) + { + // sample alpha if it has a texture + float4 diffuse = tex2D(diffuse_sampler, i.uv); + emission.xyz = diffuse.xyz * diffuse.w; + #if ALPHA_TYPE == 1 + alpha = alpha * diffuse.w; + #if ALPHA_TYPE == 2 + clip(alpha - ALPHA_CLIP_RATE); + #endif + #endif + } + #if EMISSION_TOGGLE == 0 + emission = (float3)0.0f; + #endif + return float4(emission, alpha); +} + + +technique model_ss_tech < string MMDPass = "object_ss"; > +{ + pass model_front + { + cullmode = none; + VertexShader = compile vs_3_0 vs_model(); + PixelShader = compile ps_3_0 ps_model(); + } +}; + + +technique model_tech < string MMDPass = "object"; > +{ + pass model_front + { + cullmode = none; + VertexShader = compile vs_3_0 vs_model(); + PixelShader = compile ps_3_0 ps_model(); + } +} + +technique mmd_shadow < string MMDPass = "shadow"; > {} +technique mmd_edge < string MMDPass = "edge"; > {} \ No newline at end of file diff --git a/post_glow/glow_on.fx b/post_glow/glow_on.fx new file mode 100644 index 0000000..e02cfcd --- /dev/null +++ b/post_glow/glow_on.fx @@ -0,0 +1,111 @@ +#define EMISSION_TOGGLE 1 // 0: off, 1: on +#define ALPHA_TYPE 0 // 0 : NONE, 1 : ALPHA ON, 2: ALPHA CLIP +// an alpha type of 0 will disable the glow +#define ALPHA_CLIP_RATE 0.5f + +float4x4 mm_wvp : WORLDVIEWPROJECTION; +float4x4 mm_view : VIEW; +#ifdef MIKUMIKUMOVING +float3 light_direction[MMM_LightCount] : LIGHTDIRECTIONS; +bool light_enable[MMM_LightCount] : LIGHTENABLES; +float3 light_ambients[MMM_LightCount] : LIGHTAMBIENTCOLORS; +#else +float3 light_direction : DIRECTION < string Object = "Light"; >; +#endif +bool use_texture; +texture2D diffuse_texture : MATERIALTEXTURE; +sampler2D diffuse_sampler = sampler_state +{ + texture = < diffuse_texture >; + FILTER = ANISOTROPIC; + ADDRESSU = WRAP; + ADDRESSV = WRAP; +}; + +struct vs_in +{ + float4 pos : POSITION; + float3 normal : TEXCOORD4; + float2 uv_a : TEXCOORD0; + float2 uv_b : TEXCOORD1; + float4 vertex : TEXCOORD2; + // float3 tangent : TEXCOORD4; +}; + +struct vs_out +{ + float4 pos : POSITION; + float3 normal : TEXCOORD0; + float2 uv : TEXCOORD1; +}; + +#ifdef MIKUMIKUMOVING +vs_out vs_model(MMM_SKINNING_INPUT IN,vs_in i) +{ + MMM_SKINNING_OUTPUT mmm = MMM_SkinnedPositionNormal(IN.Pos, IN.Normal, IN.BlendWeight, IN.BlendIndices, IN.SdefC, IN.SdefR0, IN.SdefR1); + i.pos = mmm.Position; + i.normal = mmm.Normal; +#else +vs_out vs_model(vs_in i) +{ +#endif + vs_out o; + // i.pos.xyz = i.pos.xyz + i.normal * 0.05f * i.vertex.a; + o.pos = mul(i.pos, mm_wvp); + o.normal = i.normal; + o.uv = i.uv_a; + return o; +} + +float4 ps_model(vs_out i) : COLOR0 +{ + // #ifdef MIKUMIKUMOVING + // float ndotl = dot(i.normal, -light_direction[0].xyz); + // #else + // float ndotl = dot(i.normal, -light_direction.xyz); + // #endif + float3 emission = (float3)1.0f; + float alpha = 1.0f; + + if(use_texture) + { + // sample alpha if it has a texture + float4 diffuse = tex2D(diffuse_sampler, i.uv); + emission.xyz = diffuse.xyz * diffuse.w; + #if ALPHA_TYPE == 1 + alpha = alpha * diffuse.w; + #if ALPHA_TYPE == 2 + clip(alpha - ALPHA_CLIP_RATE); + #endif + #endif + } + #if EMISSION_TOGGLE == 0 + emission = (float3)0.0f; + #endif + return float4(emission, 1.0f); +} + + +technique model_ss_tech < string MMDPass = "object_ss"; > +{ + pass model_front + { + cullmode = none; + VertexShader = compile vs_3_0 vs_model(); + PixelShader = compile ps_3_0 ps_model(); + } +}; + + +technique model_tech < string MMDPass = "object"; > +{ + pass model_front + { + cullmode = none; + VertexShader = compile vs_3_0 vs_model(); + PixelShader = compile ps_3_0 ps_model(); + } +} + +technique mmd_shadow < string MMDPass = "shadow"; > {} +technique mmd_edge < string MMDPass = "edge"; > {} \ No newline at end of file diff --git a/post_rim/post_depth_render.fx b/post_rim/post_depth_render.fx new file mode 100644 index 0000000..2917d85 --- /dev/null +++ b/post_rim/post_depth_render.fx @@ -0,0 +1,102 @@ +#define ALPHA_TYPE 0 // 0 : NONE, 1 : OPACITY +#define ALPHA_CLIP_RATE 0.5f +#define DEPTH_RANGE 40.0f + +float4x4 mm_wvp : WORLDVIEWPROJECTION; +float4x4 mm_view : VIEW; +float4x4 mm_w : WORLD; +#ifdef MIKUMIKUMOVING +float3 light_direction[MMM_LightCount] : LIGHTDIRECTIONS; +bool light_enable[MMM_LightCount] : LIGHTENABLES; +float3 light_ambients[MMM_LightCount] : LIGHTAMBIENTCOLORS; +#else +float3 light_direction : DIRECTION < string Object = "Light"; >; +#endif + +float3 camera_position : POSITION < string Object = "Camera"; >; +bool use_texture; +texture2D diffuse_texture : MATERIALTEXTURE; +sampler2D diffuse_sampler = sampler_state +{ + texture = < diffuse_texture >; + FILTER = ANISOTROPIC; + ADDRESSU = WRAP; + ADDRESSV = WRAP; +}; + +struct vs_in +{ + float4 pos : POSITION; + float3 normal : TEXCOORD4; + float2 uv_a : TEXCOORD0; + float2 uv_b : TEXCOORD1; + float4 vertex : TEXCOORD2; + // float3 tangent : TEXCOORD4; +}; + +struct vs_out +{ + float4 pos : POSITION; + float3 normal : TEXCOORD0; + float2 uv : TEXCOORD1; +}; + +#ifdef MIKUMIKUMOVING +vs_out vs_model(MMM_SKINNING_INPUT IN,vs_in i) +{ + MMM_SKINNING_OUTPUT mmm = MMM_SkinnedPositionNormal(IN.Pos, IN.Normal, IN.BlendWeight, IN.BlendIndices, IN.SdefC, IN.SdefR0, IN.SdefR1); + i.pos = mmm.Position; + i.normal = mmm.Normal; +#else +vs_out vs_model(vs_in i) +{ +#endif + vs_out o; + // i.pos.xyz = i.pos.xyz + i.normal * 0.05f * i.vertex.a; + o.pos = mul(i.pos, mm_wvp); + o.normal = mul(i.pos.xyz, (float3x3)mm_w); + o.uv = i.uv_a; + return o; +} + +float4 ps_model(vs_out i) : COLOR0 +{ + float depth = length(camera_position - i.normal); + depth = depth / (DEPTH_RANGE ); + + if(use_texture) + { + // sample alpha if it has a texture + float alpha = tex2D(diffuse_sampler, i.uv).w; + #if ALPHA_TYPE == 1 + clip(alpha - ALPHA_CLIP_RATE); + #endif + } + return float4((float3)depth, 1.0f); +} + + +technique model_ss_tech < string MMDPass = "object_ss"; > +{ + pass model_front + { + cullmode = none; + VertexShader = compile vs_3_0 vs_model(); + PixelShader = compile ps_3_0 ps_model(); + } +}; + + +technique model_tech < string MMDPass = "object"; > +{ + pass model_front + { + cullmode = none; + VertexShader = compile vs_3_0 vs_model(); + PixelShader = compile ps_3_0 ps_model(); + } +} + + +technique mmd_shadow < string MMDPass = "shadow"; > {} +technique mmd_edge < string MMDPass = "edge"; > {} diff --git a/post_rim/post_depth_render_alpha.fx b/post_rim/post_depth_render_alpha.fx new file mode 100644 index 0000000..7e5fb39 --- /dev/null +++ b/post_rim/post_depth_render_alpha.fx @@ -0,0 +1,102 @@ +#define ALPHA_TYPE 1 // 0 : NONE, 1 : OPACITY +#define ALPHA_CLIP_RATE 0.5f +#define DEPTH_RANGE 40.0f + +float4x4 mm_wvp : WORLDVIEWPROJECTION; +float4x4 mm_view : VIEW; +float4x4 mm_w : WORLD; +#ifdef MIKUMIKUMOVING +float3 light_direction[MMM_LightCount] : LIGHTDIRECTIONS; +bool light_enable[MMM_LightCount] : LIGHTENABLES; +float3 light_ambients[MMM_LightCount] : LIGHTAMBIENTCOLORS; +#else +float3 light_direction : DIRECTION < string Object = "Light"; >; +#endif + +float3 camera_position : POSITION < string Object = "Camera"; >; +bool use_texture; +texture2D diffuse_texture : MATERIALTEXTURE; +sampler2D diffuse_sampler = sampler_state +{ + texture = < diffuse_texture >; + FILTER = ANISOTROPIC; + ADDRESSU = WRAP; + ADDRESSV = WRAP; +}; + +struct vs_in +{ + float4 pos : POSITION; + float3 normal : TEXCOORD4; + float2 uv_a : TEXCOORD0; + float2 uv_b : TEXCOORD1; + float4 vertex : TEXCOORD2; + // float3 tangent : TEXCOORD4; +}; + +struct vs_out +{ + float4 pos : POSITION; + float3 normal : TEXCOORD0; + float2 uv : TEXCOORD1; +}; + +#ifdef MIKUMIKUMOVING +vs_out vs_model(MMM_SKINNING_INPUT IN,vs_in i) +{ + MMM_SKINNING_OUTPUT mmm = MMM_SkinnedPositionNormal(IN.Pos, IN.Normal, IN.BlendWeight, IN.BlendIndices, IN.SdefC, IN.SdefR0, IN.SdefR1); + i.pos = mmm.Position; + i.normal = mmm.Normal; +#else +vs_out vs_model(vs_in i) +{ +#endif + vs_out o; + // i.pos.xyz = i.pos.xyz + i.normal * 0.05f * i.vertex.a; + o.pos = mul(i.pos, mm_wvp); + o.normal = mul(i.pos.xyz, (float3x3)mm_w); + o.uv = i.uv_a; + return o; +} + +float4 ps_model(vs_out i) : COLOR0 +{ + float depth = length(camera_position - i.normal); + depth = depth / (DEPTH_RANGE ); + + if(use_texture) + { + // sample alpha if it has a texture + float alpha = tex2D(diffuse_sampler, i.uv).w; + #if ALPHA_TYPE == 1 + clip(alpha - ALPHA_CLIP_RATE); + #endif + } + return float4((float3)depth, 1.0f); +} + + +technique model_ss_tech < string MMDPass = "object_ss"; > +{ + pass model_front + { + cullmode = none; + VertexShader = compile vs_3_0 vs_model(); + PixelShader = compile ps_3_0 ps_model(); + } +}; + + +technique model_tech < string MMDPass = "object"; > +{ + pass model_front + { + cullmode = none; + VertexShader = compile vs_3_0 vs_model(); + PixelShader = compile ps_3_0 ps_model(); + } +} + + +technique mmd_shadow < string MMDPass = "shadow"; > {} +technique mmd_edge < string MMDPass = "edge"; > {} diff --git a/post_rim/post_normal_render.fx b/post_rim/post_normal_render.fx new file mode 100644 index 0000000..9faf585 --- /dev/null +++ b/post_rim/post_normal_render.fx @@ -0,0 +1,100 @@ +#define ALPHA_TYPE 0 // 0 : NONE, 1 : OPACITY +#define ALPHA_CLIP_RATE 0.5f + +float4x4 mm_wvp : WORLDVIEWPROJECTION; +float4x4 mm_view : VIEW; +#ifdef MIKUMIKUMOVING +float3 light_direction[MMM_LightCount] : LIGHTDIRECTIONS; +bool light_enable[MMM_LightCount] : LIGHTENABLES; +float3 light_ambients[MMM_LightCount] : LIGHTAMBIENTCOLORS; +#else +float3 light_direction : DIRECTION < string Object = "Light"; >; +#endif +bool use_texture; +texture2D diffuse_texture : MATERIALTEXTURE; +sampler2D diffuse_sampler = sampler_state +{ + texture = < diffuse_texture >; + FILTER = ANISOTROPIC; + ADDRESSU = WRAP; + ADDRESSV = WRAP; +}; + +struct vs_in +{ + float4 pos : POSITION; + float3 normal : TEXCOORD4; + float2 uv_a : TEXCOORD0; + float2 uv_b : TEXCOORD1; + float4 vertex : TEXCOORD2; + // float3 tangent : TEXCOORD4; +}; + +struct vs_out +{ + float4 pos : POSITION; + float3 normal : TEXCOORD0; + float2 uv : TEXCOORD1; +}; + +#ifdef MIKUMIKUMOVING +vs_out vs_model(MMM_SKINNING_INPUT IN,vs_in i) +{ + MMM_SKINNING_OUTPUT mmm = MMM_SkinnedPositionNormal(IN.Pos, IN.Normal, IN.BlendWeight, IN.BlendIndices, IN.SdefC, IN.SdefR0, IN.SdefR1); + i.pos = mmm.Position; + i.normal = mmm.Normal; +#else +vs_out vs_model(vs_in i) +{ +#endif + vs_out o; + // i.pos.xyz = i.pos.xyz + i.normal * 0.05f * i.vertex.a; + o.pos = mul(i.pos, mm_wvp); + o.normal = i.normal; + o.uv = i.uv_a; + return o; +} + +float4 ps_model(vs_out i) : COLOR0 +{ + #ifdef MIKUMIKUMOVING + float ndotl = dot(i.normal, -light_direction[0].xyz); + #else + float ndotl = dot(i.normal, -light_direction.xyz); + #endif + + if(use_texture) + { + // sample alpha if it has a texture + float alpha = tex2D(diffuse_sampler, i.uv).w; + #if ALPHA_TYPE == 1 + clip(alpha - ALPHA_CLIP_RATE); + #endif + } + return float4(normalize(i.normal) * 0.5f + 0.5f, 1.0f); +} + + +technique model_ss_tech < string MMDPass = "object_ss"; > +{ + pass model_front + { + cullmode = none; + VertexShader = compile vs_3_0 vs_model(); + PixelShader = compile ps_3_0 ps_model(); + } +}; + + +technique model_tech < string MMDPass = "object"; > +{ + pass model_front + { + cullmode = none; + VertexShader = compile vs_3_0 vs_model(); + PixelShader = compile ps_3_0 ps_model(); + } +} + +technique mmd_shadow < string MMDPass = "shadow"; > {} +technique mmd_edge < string MMDPass = "edge"; > {} \ No newline at end of file diff --git a/post_rim/post_normal_render_alpha.fx b/post_rim/post_normal_render_alpha.fx new file mode 100644 index 0000000..0181dc5 --- /dev/null +++ b/post_rim/post_normal_render_alpha.fx @@ -0,0 +1,100 @@ +#define ALPHA_TYPE 1 // 0 : NONE, 1 : OPACITY +#define ALPHA_CLIP_RATE 0.5f + +float4x4 mm_wvp : WORLDVIEWPROJECTION; +float4x4 mm_view : VIEW; +#ifdef MIKUMIKUMOVING +float3 light_direction[MMM_LightCount] : LIGHTDIRECTIONS; +bool light_enable[MMM_LightCount] : LIGHTENABLES; +float3 light_ambients[MMM_LightCount] : LIGHTAMBIENTCOLORS; +#else +float3 light_direction : DIRECTION < string Object = "Light"; >; +#endif +bool use_texture; +texture2D diffuse_texture : MATERIALTEXTURE; +sampler2D diffuse_sampler = sampler_state +{ + texture = < diffuse_texture >; + FILTER = ANISOTROPIC; + ADDRESSU = WRAP; + ADDRESSV = WRAP; +}; + +struct vs_in +{ + float4 pos : POSITION; + float3 normal : TEXCOORD4; + float2 uv_a : TEXCOORD0; + float2 uv_b : TEXCOORD1; + float4 vertex : TEXCOORD2; + // float3 tangent : TEXCOORD4; +}; + +struct vs_out +{ + float4 pos : POSITION; + float3 normal : TEXCOORD0; + float2 uv : TEXCOORD1; +}; + +#ifdef MIKUMIKUMOVING +vs_out vs_model(MMM_SKINNING_INPUT IN,vs_in i) +{ + MMM_SKINNING_OUTPUT mmm = MMM_SkinnedPositionNormal(IN.Pos, IN.Normal, IN.BlendWeight, IN.BlendIndices, IN.SdefC, IN.SdefR0, IN.SdefR1); + i.pos = mmm.Position; + i.normal = mmm.Normal; +#else +vs_out vs_model(vs_in i) +{ +#endif + vs_out o; + // i.pos.xyz = i.pos.xyz + i.normal * 0.05f * i.vertex.a; + o.pos = mul(i.pos, mm_wvp); + o.normal = i.normal; + o.uv = i.uv_a; + return o; +} + +float4 ps_model(vs_out i) : COLOR0 +{ + #ifdef MIKUMIKUMOVING + float ndotl = dot(i.normal, -light_direction[0].xyz); + #else + float ndotl = dot(i.normal, -light_direction.xyz); + #endif + + if(use_texture) + { + // sample alpha if it has a texture + float alpha = tex2D(diffuse_sampler, i.uv).w; + #if ALPHA_TYPE == 1 + clip(alpha - ALPHA_CLIP_RATE); + #endif + } + return float4(normalize(i.normal) * 0.5f + 0.5f, 1.0f); +} + + +technique model_ss_tech < string MMDPass = "object_ss"; > +{ + pass model_front + { + cullmode = none; + VertexShader = compile vs_3_0 vs_model(); + PixelShader = compile ps_3_0 ps_model(); + } +}; + + +technique model_tech < string MMDPass = "object"; > +{ + pass model_front + { + cullmode = none; + VertexShader = compile vs_3_0 vs_model(); + PixelShader = compile ps_3_0 ps_model(); + } +} + +technique mmd_shadow < string MMDPass = "shadow"; > {} +technique mmd_edge < string MMDPass = "edge"; > {} \ No newline at end of file diff --git a/post_rim/post_rim.fx b/post_rim/post_rim.fx new file mode 100644 index 0000000..e53f6b4 --- /dev/null +++ b/post_rim/post_rim.fx @@ -0,0 +1,180 @@ +#define rim_color float4(0.25f, 0.25f, 0.25f, 1.0f) + + +float4x4 mm_wvp : WORLDVIEWPROJECTION; +float4x4 mm_view : VIEW; +#ifdef MIKUMIKUMOVING +float3 light_direction[MMM_LightCount] : LIGHTDIRECTIONS; +bool light_enable[MMM_LightCount] : LIGHTENABLES; +float3 light_ambients[MMM_LightCount] : LIGHTAMBIENTCOLORS; +#else +float3 light_direction : DIRECTION < string Object = "Light"; >; +#endif + +static float near = 1.0f; +static float far = 1000.f; +static float z_x = 1.0f - far / near; +static float z_y = far / near; +static float4 zbuffer_param = float4(z_x, z_y, z_x / far, z_y / far); + +float Script : STANDARDSGLOBAL +< + string ScriptOutput = "color"; + string ScriptClass = "scene"; + string ScriptOrder = "postprocess"; +> = 0.8; + +float4 clear_color = { 0.5f, 0.5f, 0.5f, 1.0f }; +float clear_depth = 1.0f; + +float2 viewport_size : VIEWPORTPIXELSIZE; +float2 screen_size : VIEWPORTPIXELSIZE; +static const float2 viewport_offset = (float2)0.5f / viewport_size; + +texture2D depth_buff : RENDERDEPTHSTENCILTARGET ; + +texture2D screen_texture : RENDERCOLORTARGET; +texture2D normal_texture : OFFSCREENRENDERTARGET +< + string Description = "camera normal texture"; + float4 ClearColor = {0.5f, 0.5f, 0.0f, 1.0f}; + float ClearDepth = 1.0f; + bool AntiAlias = true; + string DefaultEffect = "* = post_normal_render.fx;"; +>; + +texture2D depth_texture : OFFSCREENRENDERTARGET +< + string Description = "camera depth texture"; + float4 ClearColor = {10.0f, 10.0f, 10.0f, 1.0f}; + float ClearDepth = 1.0f; + bool AntiAlias = true; + string Format = "R32F"; + string DefaultEffect = "* = post_depth_render.fx;"; +>; + +sampler screen_sampler = sampler_state +{ + texture = ; + MinFilter = NONE; + MagFilter = NONE; + MipFilter = NONE; + AddressU = CLAMP; + AddressV = CLAMP; +}; + + + +sampler2D normal_sampler = sampler_state +{ + texture = ; + MinFilter = NONE; + MagFilter = NONE; + MipFilter = NONE; + AddressU = CLAMP; + AddressV = CLAMP; +}; + +sampler2D depth_sampler = sampler_state +{ + texture = ; + MinFilter = NONE; + MagFilter = NONE; + MipFilter = NONE; + AddressU = CLAMP; + AddressV = CLAMP; +}; + + +struct vs_in +{ + float4 pos : POSITION; + float2 uv : TEXCOORD0; +}; + +struct vs_out +{ + float4 pos : POSITION; + float2 uv : TEXCOORD0; + float3 normal : TEXCOORD1; +}; + +vs_out vs_rim(vs_in i) +{ + vs_out o; + o.pos = i.pos; + o.uv = i.uv + viewport_offset; + o.normal = i.pos.xyz * 0.5f + 0.5f; + return o; +} + + + +float4 ps_rim(vs_out i) : COLOR0 +{ + + // initialize inputs + float3 quad_normal = normalize(i.normal); + float2 uv = i.uv; + + // sample textures using basic uvs + float4 screen = tex2D(screen_sampler, uv); + float3 normal_tex = tex2D(normal_sampler, uv); + float depth = tex2D(depth_sampler, uv).x; + normal_tex = normal_tex * 2.0f - 1.0f; + + // depth = zbuffer_param.x * depth + zbuffer_param.y; + // depth = 1.0f / depth; + + float3 normal_vs = mul(normal_tex, (float3x3)mm_view); + float2 normal_depth_coords = normal_vs.xy * (float2)0.00200000009f + uv.xy; + + // sample normal offset depth texture + float off_depth = tex2D(depth_sampler, normal_depth_coords).x; + // off_depth = zbuffer_param.x * depth + zbuffer_param.y; + // off_depth = 1.0f / off_depth; + + float d = -depth + off_depth; + d = max(d, 0.001f); + d = pow(d, 0.04f); + d = d - 0.8f; + d = d * 10.0f; + d = clamp(d, 0.0f, 1.0f); + float d_2 = (d * d) * (d * -2.0f + 3.0f); + float depth_weird = min(((-depth) + 2.0f) * 0.3f + depth, 1.0f); + d_2 = depth_weird * d_2; + // screen.xyz = d_2; + screen.xyz = screen + (d_2 * rim_color); + return screen; +} + +technique PostEffectTec +< + string Script = + "RenderColorTarget0=screen_texture;" + "RenderDepthStencilTarget=depth_buff;" + "ClearSetColor=clear_color;" + "ClearSetDepth=clear_depth;" + "Clear=Color;" + "Clear=Depth;" + "ScriptExternal=Color;" + + + "RenderColorTarget0=;" + "RenderDepthStencilTarget=;" + "ClearSetColor = clear_color;" + "ClearSetDepth = clear_depth;" + "Clear=Color;" + "Clear=Depth;" + "Pass=pass_rim;"; +> +{ + + pass pass_rim < string Script = "Draw=Buffer;"; > + { + AlphaBlendEnable = true; + VertexShader = compile vs_3_0 vs_rim(); + PixelShader = compile ps_3_0 ps_rim(); + } + +}; diff --git a/post_rim/post_rim.x b/post_rim/post_rim.x new file mode 100644 index 0000000..c4c9a20 --- /dev/null +++ b/post_rim/post_rim.x @@ -0,0 +1,116 @@ +xof 0303txt 0032 +template Vector { + <3d82ab5e-62da-11cf-ab39-0020af71e433> + FLOAT x; + FLOAT y; + FLOAT z; +} + +template MeshFace { + <3d82ab5f-62da-11cf-ab39-0020af71e433> + DWORD nFaceVertexIndices; + array DWORD faceVertexIndices[nFaceVertexIndices]; +} + +template Mesh { + <3d82ab44-62da-11cf-ab39-0020af71e433> + DWORD nVertices; + array Vector vertices[nVertices]; + DWORD nFaces; + array MeshFace faces[nFaces]; + [...] +} + +template MeshNormals { + + DWORD nNormals; + array Vector normals[nNormals]; + DWORD nFaceNormals; + array MeshFace faceNormals[nFaceNormals]; +} + +template Coords2d { + + FLOAT u; + FLOAT v; +} + +template MeshTextureCoords { + + DWORD nTextureCoords; + array Coords2d textureCoords[nTextureCoords]; +} + +template ColorRGBA { + <35ff44e0-6c7c-11cf-8f52-0040333594a3> + FLOAT red; + FLOAT green; + FLOAT blue; + FLOAT alpha; +} + +template ColorRGB { + + FLOAT red; + FLOAT green; + FLOAT blue; +} + +template Material { + <3d82ab4d-62da-11cf-ab39-0020af71e433> + ColorRGBA faceColor; + FLOAT power; + ColorRGB specularColor; + ColorRGB emissiveColor; + [...] +} + +template MeshMaterialList { + + DWORD nMaterials; + DWORD nFaceIndexes; + array DWORD faceIndexes[nFaceIndexes]; + [Material <3d82ab4d-62da-11cf-ab39-0020af71e433>] +} + + +Mesh { + 3; + -0.010785;0.127195;-0.000000;, + -0.052251;0.044264;-0.000000;, + 0.056020;0.028138;-0.000000;; + 2; + 3;0,2,1;, + 3;0,1,2;; + + MeshNormals { + 3; + 0.000000;0.000000;-1.000000;, + 0.000000;0.000000;-1.000000;, + 0.000000;0.000000;-1.000000;; + 2; + 3;0,2,1;, + 3;0,1,2;; + } + + MeshTextureCoords { + 3; + 0.000000;0.000000;, + 0.000000;0.000000;, + 0.000000;0.000000;; + } + + MeshMaterialList { + 1; + 2; + 0, + 0; + + Material { + 1.000000;1.000000;1.000000;1.000000;; + 5.000000; + 0.000000;0.000000;0.000000;; + 1.000000;1.000000;1.000000;; + } + } +} \ No newline at end of file