Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
KH40-khoast40 authored Jan 29, 2022
1 parent 01087dc commit 177e123
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 3 deletions.
97 changes: 97 additions & 0 deletions HgShadow_ObjHeader.fxh
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
////////////////////////////////////////////////////////////////////////////////////////////////
//
// HgShadow_ObjHeader.fxh : HgShadow オブジェクト影描画に必要な基本パラメータ定義ヘッダファイル
// ここのパラメータをシェーダエフェクトファイルで #include して使用します。
// 作成: 針金P
//
////////////////////////////////////////////////////////////////////////////////////////////////
// パラメータ宣言

// 制御パラメータ
#define HgShadow_CTRLFILENAME "HgShadow.x"
bool HgShadow_Valid : CONTROLOBJECT < string name = HgShadow_CTRLFILENAME; >;

float HgShadow_DensityUp : CONTROLOBJECT < string name = "(self)"; string item = "ShadowDen+"; >;
float HgShadow_DensityDown : CONTROLOBJECT < string name = "(self)"; string item = "ShadowDen-"; >;

#ifndef MIKUMIKUMOVING

float HgShadow_AcsRx : CONTROLOBJECT < string name = HgShadow_CTRLFILENAME; string item = "Rx"; >;
float HgShadow_ObjTr : CONTROLOBJECT < string name = "(self)"; string item = "Tr"; >;
static float HgShadow_Density = max((degrees(HgShadow_AcsRx) + 5.0f*HgShadow_DensityUp + 1.0f)*(1.0f - HgShadow_DensityDown), 0.0f);

#else

shared float HgShadow_MMM_Density;
static float HgShadow_Density = max((HgShadow_MMM_Density + 5.0f*HgShadow_DensityUp)*(1.0f - HgShadow_DensityDown), 0.0f);

#endif


// 影生成描画結果を記録するためのレンダーターゲット
shared texture2D HgShadow_ViewportMap2 : RENDERCOLORTARGET;
sampler2D HgShadow_ViewportMapSamp = sampler_state {
texture = <HgShadow_ViewportMap2>;
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = LINEAR;
AddressU = CLAMP;
AddressV = CLAMP;
};


// スクリーンサイズ
float2 HgShadow_ViewportSize : VIEWPORTPIXELSIZE;
static float2 HgShadow_ViewportOffset = (float2(0.5,0.5)/HgShadow_ViewportSize);


// セルフシャドウの遮蔽率を求める
float HgShadow_GetSelfShadowRate(float4 PPos)
{
// スクリーンの座標
float2 texCoord = float2( ( PPos.x/PPos.w + 1.0f ) * 0.5f,
1.0f - ( PPos.y/PPos.w + 1.0f ) * 0.5f ) + HgShadow_ViewportOffset;

// 遮蔽率
float comp = 1.0f - tex2Dlod( HgShadow_ViewportMapSamp, float4(texCoord, 0, 0) ).r;

return (1.0f-(1.0f-comp) * min(HgShadow_Density, 1.0f));
}


struct HgShadow_COLOR {
float4 Color; // オブジェクト色
float4 ShadowColor; // 影色
};


// 影色に濃度を加味する
HgShadow_COLOR HgShadow_GetShadowDensity(float4 Color, float4 ShadowColor, bool useToon, float LightNormal)
{
HgShadow_COLOR Out;
Out.Color = Color;
Out.ShadowColor = ShadowColor;

if( !useToon || length(Color.rgb-ShadowColor.rgb) > 0.01f ){
float e = max(HgShadow_Density, 1.0f);
float a = 1.0f / e;
float b = 1.0f - smoothstep(3.0f, 6.0f, e);
float3 color = lerp(ShadowColor.rgb*a, ShadowColor.rgb*b, pow(ShadowColor.rgb, e));
Out.ShadowColor = float4(saturate(color), ShadowColor.a);
}
if( !useToon ){
float e = lerp( max(HgShadow_Density, 1.0f), 1.0f, smoothstep(0.0f, 0.4f, LightNormal) );
float a = 1.0f / e;
float b = 1.0f - smoothstep(3.0f, 6.0f, e);
float3 color = lerp(Color.rgb*a, Color.rgb*b, pow(Color.rgb, e));
Out.Color = float4(saturate(color), Color.a);
#ifndef MIKUMIKUMOVING
Out.Color.a *= HgShadow_ObjTr;
Out.ShadowColor.a *= HgShadow_ObjTr;
#endif
}

return Out;
}


14 changes: 12 additions & 2 deletions Object.fx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

//Shadekai (Project Sekai shader for MMD)

#define SekaiMap_Texture "tex_chr_SCL_B_00_H.png" //The texture that ends with "_H"
#define ShadowColorMap_Texture "tex_chr_SCL_B_00_S.png" //The texture that ends with "_S"
#define SekaiMap_Texture "tex_bdy_MIK_00_H.png" //The texture that ends with "_H"
#define ShadowColorMap_Texture "tex_bdy_MIK_00_S.png" //The texture that ends with "_S"

#define Character 20
//////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -12,6 +12,16 @@
// 3.Shiho 7.Shizuku 11.Touya 15.Rui 19.Mizuki
//////////////////////////////////////////////////////////////////////////////////////////////////////////

#define Shadow 1
//0 to disable, 1 to enable
//If you choose 1, you have to load HgShadow.x for the model to have real-time shadow
//Choose 0 if you don't want the model to have real-time shadow even when HgShadow.x is loaded
//The model won't have real-time shadow regardless of the options if HgShadow.x is not loaded

#define Shadow_Sharp 1
//0 to choose soft shadow , 1 to choose sharp shadow
//For Sekai's artstyle, sharp shadow is recommended. And no, sharp not as in default MMD's busted pixelated shadow, it's Hgshadow but sharpened

float Rim_Intensity = 0.35;
float Rim_Length = 0.25; //SMALLER number means LONGER rim
float Rim_Thickness = 0.65; //SMALLER number means THICKER rim
Expand Down
23 changes: 22 additions & 1 deletion Shadekai.fxsub
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
////////////////////////////////////////////////////////////////////////////////////////////////
//
// Shadekai (Project Sekai shader for MMD)
// Shadekai (Project Sekai shader for MMD) v1.1
//
// By: KH40 (khoast40)
// Base shader: ���͉��P
Expand All @@ -9,6 +9,8 @@
////////////////////////////////////////////////////////////////////////////////////////////////
// �p�����[�^�錾

#include "HgShadow_ObjHeader.fxh"

// ���@�ϊ��s��
float4x4 WorldViewProjMatrix : WORLDVIEWPROJECTION;
float4x4 WorldMatrix : WORLD;
Expand Down Expand Up @@ -90,6 +92,7 @@ struct BufferShadow_OUTPUT
float3 Normal : TEXCOORD2; // �@��
float3 Eye : TEXCOORD3; // �J�����Ƃ̑��Έʒu
float4 VColor : TEXCOORD4;
float4 PPos : TEXCOORD5; // �ˉe���W
float4 Color : COLOR0; // �f�B�t���[�Y�F
};

Expand All @@ -100,6 +103,8 @@ BufferShadow_OUTPUT Basic_VS(float4 Pos : POSITION, float3 Normal : NORMAL, floa

// �J�������_�̃��[���h�r���[�ˉe�ϊ�
Out.Pos = mul( Pos, WorldViewProjMatrix );

Out.PPos = Out.Pos;

// �J�����Ƃ̑��Έʒu
Out.Eye = CameraPosition - mul( Pos, WorldMatrix );
Expand Down Expand Up @@ -142,6 +147,22 @@ float4 Basic_PS( BufferShadow_OUTPUT IN ) : COLOR

float comp = ((saturate(dot(IN.Normal,-LightDirection))));
comp = smoothstep(0,0.01,comp);

#if Shadow == 1

if(HgShadow_Valid)
{
float compshadow = HgShadow_GetSelfShadowRate(IN.PPos);

#if Shadow_Sharp == 1
compshadow = step(0.25,compshadow);
#endif

comp = min(comp,compshadow);
}

#endif

Color = lerp(ShadowTexColor, TexColor, comp);

float3 ColorSkin = Color.rgb * Skin_Color[Character]/255;
Expand Down

0 comments on commit 177e123

Please sign in to comment.