Skip to content

Commit

Permalink
コミットし忘れをコミット
Browse files Browse the repository at this point in the history
  • Loading branch information
RYUICHIKAWANO committed Feb 17, 2020
1 parent ecc2993 commit 864b56f
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 581 deletions.
29 changes: 12 additions & 17 deletions Chapter18/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Application::Initialize() {
_heapForSpriteFont = _dx12->CreateDescriptorHeapForSpriteFont();
spriteFont = new DirectX::SpriteFont(_dx12->Device(),
resUploadBatch,
L"font/hgpop.spritefont",
L"font/fonttest.spritefont",
_heapForSpriteFont->GetCPUDescriptorHandleForHeapStart(),
_heapForSpriteFont->GetGPUDescriptorHandleForHeapStart());
auto future = resUploadBatch.End(_dx12->CmdQue());
Expand Down Expand Up @@ -149,10 +149,10 @@ Application::Initialize() {
1, //レンダーターゲット数
false, //デプスありか?
false, //反対デプスありか?
10000);//最大パーティクルの数
2000);//最大パーティクルの数


_efkManager = Effekseer::Manager::Create(10000);//最大インスタンス数
_efkManager = Effekseer::Manager::Create(2000);//最大インスタンス数


//「系」を左手系にしておく(とにかくクライアント側の系に合わせる)
Expand Down Expand Up @@ -185,32 +185,27 @@ Application::Initialize() {

// エフェクトの再生
_efkHandle = _efkManager->Play(_effect, 0, 0, 0);





_actor.reset(new PMDActor(_dx12, "Model/初音ミク.pmd"));
_actor->Move(-10, 0, 10);

_pmdRenderer->AddActor(_actor);
_pmdRenderer->AddActor("Model/初音ミクmetal.pmd");

auto satori = make_shared<PMDActor>(_dx12, "Model/鏡音リン.pmd");
satori->Move(-5, 0, 5);
_pmdRenderer->AddActor(satori);
auto rin = make_shared<PMDActor>(_dx12, "Model/鏡音リン.pmd");
rin->Move(-5, 0, 5);
_pmdRenderer->AddActor(rin);

auto ruka = make_shared<PMDActor>(_dx12, "Model/巡音ルカ.pmd");
ruka->Move(10, 0, 10);
_pmdRenderer->AddActor(ruka);

auto hibiki = make_shared<PMDActor>(_dx12, "Model/弱音ハク.pmd");
hibiki->Move(-10, 0, 0);
_pmdRenderer->AddActor(hibiki);
auto haku = make_shared<PMDActor>(_dx12, "Model/弱音ハク.pmd");
haku->Move(-10, 0, 0);
_pmdRenderer->AddActor(haku);

auto katu = make_shared<PMDActor>(_dx12, "Model/カイト.pmd");
katu->Move(10, 0, 0);
_pmdRenderer->AddActor(katu);
auto kaito = make_shared<PMDActor>(_dx12, "Model/カイト.pmd");
kaito->Move(10, 0, 0);
_pmdRenderer->AddActor(kaito);


_pmdRenderer->AnimationStart();
Expand Down
162 changes: 15 additions & 147 deletions Chapter18/BasicVertexShader.hlsl
Original file line number Diff line number Diff line change
@@ -1,195 +1,66 @@
SamplerState smp : register(s0);
SamplerState clutSmp : register(s1);
SamplerComparisonState shadowSmp : register(s2);

#include"Type.hlsli"
//マテリアル用スロット
cbuffer materialBuffer : register(b0) {
cbuffer MaterialBuffer : register(b0) {
float4 diffuse;
float power;
float3 specular;
float3 ambient;
};
//マテリアル用
Texture2D<float4> tex : register(t0);//通常テクスチャ
Texture2D<float4> sph : register(t1);//スフィアマップ(乗算)
Texture2D<float4> spa : register(t2);//スフィアマップ(加算)
Texture2D<float4> toon : register(t3);//トゥーンテクスチャ

//シャドウマップ用
Texture2D<float> lightDepthTex : register(t4);//デプス

//シーン管理用スロット
cbuffer sceneBuffer : register(b1) {
cbuffer SceneBuffer : register(b1) {
matrix view;//ビュー
matrix proj;//プロジェクション
matrix invPro;//逆射影行列
matrix invproj;//プロジェクション
matrix lightCamera;//ライトビュープロジェ
matrix shadow;//影行列
float4 lightVec;//ライトベクトル
float3 eye;//視点
bool isSelfShadow;//シャドウマップフラグ
};

//アクター座標変換用スロット
cbuffer transBuffer : register(b2) {
cbuffer TransBuffer : register(b2) {
matrix world;
}

//ボーン行列配列
cbuffer transBuffer : register(b3) {
cbuffer BonesBuffer : register(b3) {
matrix bones[512];
}

//表示設定
cbuffer DrawSetting : register(b4) {
uint outline;
uint rimFlg;
float rimStrength;
}


//返すのはSV_POSITIONだけではない
struct Output {
float4 svpos : SV_POSITION;
float4 pos : POSITION;
float4 tpos : TPOS;
float4 normal : NORMAL;
float2 uv : TEXCOORD;
float instNo : INSTNO;
};
struct PixelOutput {
float4 color:SV_TARGET0;//標準
float4 normal:SV_TARGET1;//法線
float4 highLum:SV_TARGET2;//高輝度
};

struct PrimitiveOutput {
float4 svpos:SV_POSITION;
float4 tpos : TPOS;
float4 normal:NORMAL;
};



PrimitiveOutput PrimitiveVS(float4 pos:POSITION, float4 normal : NORMAL) {
PrimitiveOutput output;
PrimitiveType PrimitiveVS(float4 pos:POSITION, float4 normal : NORMAL) {
PrimitiveType output;
output.svpos = mul(proj, mul(view, pos));
output.tpos = mul(lightCamera, pos);
output.normal = normal;
return output;
}
PixelOutput PrimitivePS(PrimitiveOutput input){
float3 light = normalize(float3(1,-1,1));
float bright = dot(input.normal, -light);

float shadowWeight = 1.0f;
float3 posFromLightVP = input.tpos.xyz / input.tpos.w;
float2 shadowUV = (input.tpos.xy / input.tpos.w + float2(1, -1))*float2(0.5, -0.5);
float depthFromLight = lightDepthTex.SampleCmpLevelZero(
shadowSmp,
shadowUV,
posFromLightVP.z - 0.005f);
shadowWeight = lerp(0.5f, 1.0f, depthFromLight);

float b = bright*shadowWeight;

PixelOutput po;
po.color=float4(b, b, b, 1);
po.normal = float4((input.normal.xyz+1)*0.5,1);
return po;
}

//頂点シェーダ(頂点情報から必要なものを次の人へ渡す)
//パイプラインに投げるためにはSV_POSITIONが必要
Output VS(float4 pos:POSITION,float4 normal:NORMAL,float2 uv:TEXCOORD,min16uint2 boneno:BONENO,min16uint weight:WEIGHT,uint instNo:SV_InstanceID) {
BasicType BasicVS(float4 pos:POSITION,float4 normal:NORMAL,float2 uv:TEXCOORD,min16uint2 boneno:BONENO,min16uint weight:WEIGHT,uint instNo:SV_InstanceID) {
//1280,720を直で使って構わない。
Output output;
BasicType output;
float fWeight = float(weight) / 100.0f;
matrix conBone = bones[boneno.x]*fWeight +
bones[boneno.y]*(1.0f - fWeight);

output.pos = mul(world,
mul(conBone,pos)
);
//if (instNo == 0) {
// output.pos = mul(shadow, output.pos);
//}
output.instNo = (float)instNo;

output.svpos = mul(proj,mul(view, output.pos));
//output.svpos = mul(lightCamera, output.pos);
output.tpos = mul(lightCamera, output.pos);
// output.tpos.w = 1;
output.uv = uv;
normal.w = 0;
output.normal = mul(world,mul(conBone,normal));
//output.uv = uv;
return output;
}



//ピクセルシェーダ
PixelOutput PS(Output input) {
float3 eyeray = normalize(input.pos-eye);
float3 light = normalize(float3(1,-1,1));
float3 rlight = reflect(light, input.normal);

//スペキュラ輝度
float p = saturate(dot(rlight, -eyeray));

//MSDNのpowのドキュメントによると
//p=0だったりp==0&&power==0のときNANの可能性が
//あるため、念のため以下のようなコードにしている
//https://docs.microsoft.com/ja-jp/windows/win32/direct3dhlsl/dx-graphics-hlsl-pow
float specB = 0;
if (p > 0 && power > 0) {
specB=pow(p, power);
}

//ディフューズ明るさ
float diffB = dot(-light, input.normal);
float4 toonCol = toon.Sample(clutSmp, float2(0, 1 - diffB));


float4 texCol = tex.Sample(smp, input.uv);

//col.rgb= pow(col.rgb, 1.0 / 2.2);
float2 spUV= (input.normal.xy
*float2(1, -1) //まず上下だけひっくりかえす
+ float2(1, 1)//(1,1)を足して-1~1を0~2にする
) / 2;
float4 sphCol = sph.Sample(smp, spUV);
float4 spaCol = spa.Sample(smp, spUV);

//float4 ret= spaCol + sphCol * texCol*toonCol*diffuse + float4(ambient*0.6, 1)
float4 ret = float4((spaCol + sphCol * texCol * toonCol*diffuse).rgb,diffuse.a)
+ float4(specular*specB, 1);


float shadowWeight = 1.0f;
float3 posFromLightVP=input.tpos.xyz / input.tpos.w;
float2 shadowUV = (input.tpos.xy/input.tpos.w+float2(1,-1))*float2(0.5,-0.5);
float depthFromLight = lightDepthTex.SampleCmpLevelZero(
shadowSmp,
shadowUV,
posFromLightVP.z-0.005f);
shadowWeight = lerp(0.5f, 1.0f, depthFromLight);

//float rim= rimFlg?dot(input.normal, -eyeray):0;
float rim = rimFlg?pow(1.0f-saturate(dot(input.normal, -eyeray)),rimStrength):0.0f ;
PixelOutput po;
float4 retcol = float4(ret.rgb*shadowWeight + float3(rim, rim, rim), ret.a);
po.color = retcol;
po.normal = float4(0.5*(input.normal.rgb+1),1);
po.highLum = float4(0,0,0,1);
if (dot(float3(0.299f, 0.587f, 0.114f), retcol.rgb) > 0.95f) {
po.highLum.rgb = float3(1, 1, 1);// step(0.99, retcol.rgb);
}

return po;
}

//影用頂点座標変換
float4
shadowVS(float4 pos:POSITION, float4 normal : NORMAL, float2 uv : TEXCOORD, min16uint2 boneno : BONENO, min16uint weight : WEIGHT) :SV_POSITION{
ShadowVS(float4 pos:POSITION, float4 normal : NORMAL, float2 uv : TEXCOORD, min16uint2 boneno : BONENO, min16uint weight : WEIGHT) :SV_POSITION{
float fWeight = float(weight) / 100.0f;
matrix conBone = bones[boneno.x] * fWeight +
bones[boneno.y] * (1.0f - fWeight);
Expand All @@ -198,7 +69,4 @@ shadowVS(float4 pos:POSITION, float4 normal : NORMAL, float2 uv : TEXCOORD, min1
return mul(lightCamera, pos);
}

float4
shadowPS(float4 pos:SV_POSITION):SV_TARGET {
return float4(1,1,1,1);
}

88 changes: 50 additions & 38 deletions Chapter18/Chapter18.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -160,59 +160,71 @@
<ClInclude Include="PrimitiveRenderer.h" />
</ItemGroup>
<ItemGroup>
<FxCompile Include="BasicShader.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Effect</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">5.0</ShaderModel>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Effect</ShaderType>
<FxCompile Include="BasicVertexShader.hlsl">
<EntryPointName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">BasicVS</EntryPointName>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">5.0</ShaderModel>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Geometry</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">4.0</ShaderModel>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Effect</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Vertex</ShaderType>
<EntryPointName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">BasicVS</EntryPointName>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">5.0</ShaderModel>
<EntryPointName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
</EntryPointName>
<EntryPointName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
</EntryPointName>
<EntryPointName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
</EntryPointName>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Vertex</ShaderType>
</FxCompile>
<FxCompile Include="pera.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Effect</ShaderType>
<FxCompile Include="BasicPixelShader.hlsl">
<EntryPointName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">BasicPS</EntryPointName>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">5.0</ShaderModel>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Geometry</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">4.0</ShaderModel>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Geometry</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">4.0</ShaderModel>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Effect</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType>
<EntryPointName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">BasicPS</EntryPointName>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">5.0</ShaderModel>
<EntryPointName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
</EntryPointName>
<EntryPointName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
</EntryPointName>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Pixel</ShaderType>
</FxCompile>
<FxCompile Include="ShrinkShader.hlsl">
<FxCompile Include="PeraPixelShader.hlsl">
<EntryPointName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">PeraPS</EntryPointName>
<EntryPointName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">PeraPS</EntryPointName>
<EntryPointName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">PeraPS</EntryPointName>
<EntryPointName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">PeraPS</EntryPointName>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">5.0</ShaderModel>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">5.0</ShaderModel>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">5.0</ShaderModel>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">5.0</ShaderModel>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Pixel</ShaderType>
</FxCompile>
<FxCompile Include="PeraVertexShader.hlsl">
<EntryPointName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">PeraVS</EntryPointName>
<EntryPointName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">PeraVS</EntryPointName>
<EntryPointName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">PeraVS</EntryPointName>
<EntryPointName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">PeraVS</EntryPointName>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">5.0</ShaderModel>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">5.0</ShaderModel>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Geometry</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">4.0</ShaderModel>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Geometry</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">4.0</ShaderModel>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Geometry</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">4.0</ShaderModel>
<EntryPointName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">ShrinkPS</EntryPointName>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">5.0</ShaderModel>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">5.0</ShaderModel>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Vertex</ShaderType>
</FxCompile>
<FxCompile Include="ssao.hlsl">
<FxCompile Include="ShrinkPixelShader.hlsl">
<EntryPointName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">ShrinkPS</EntryPointName>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">5.0</ShaderModel>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Domain</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">5.0</ShaderModel>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Domain</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">5.0</ShaderModel>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Domain</ShaderType>
<EntryPointName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">ShrinkPS</EntryPointName>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Pixel</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">5.0</ShaderModel>
</FxCompile>
<FxCompile Include="SSAOPixelShader.hlsl">
<EntryPointName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">SsaoPS</EntryPointName>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">5.0</ShaderModel>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType>
<EntryPointName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">SsaoPS</EntryPointName>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">5.0</ShaderModel>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Pixel</ShaderType>
</FxCompile>
</ItemGroup>
<ItemGroup>
<None Include="FXAA.hlsli" />
<None Include="Type.hlsli" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
Expand Down
Loading

0 comments on commit 864b56f

Please sign in to comment.