[add] normal PBR
This commit is contained in:
@@ -1,362 +1,10 @@
|
||||
#ifndef ENGINE_SHADER_DEFINES_HLSLI
|
||||
#define ENGINE_SHADER_DEFINES_HLSLI
|
||||
|
||||
vector g_vMtrlDiffuse = 1.f;
|
||||
vector g_vMtrlAmbient = 1.f;
|
||||
vector g_vMtrlSpecular = 1.f;
|
||||
#include "Engine_Shader_Constants.hlsli"
|
||||
#include "Engine_Shader_Structures.hlsli"
|
||||
#include "Engine_Shader_Samplers.hlsli"
|
||||
#include "Engine_Shader_States.hlsli"
|
||||
#include "Engine_Shader_Functions.hlsli"
|
||||
|
||||
float PI = 3.14592;
|
||||
|
||||
sampler DefaultSampler = sampler_state
|
||||
{
|
||||
Filter = MIN_MAG_MIP_LINEAR;
|
||||
AddressU = wrap;
|
||||
AddressV = wrap;
|
||||
};
|
||||
|
||||
sampler ClampSampler = sampler_state
|
||||
{
|
||||
Filter = MIN_MAG_MIP_POINT;
|
||||
AddressU = clamp;
|
||||
AddressV = clamp;
|
||||
};
|
||||
|
||||
sampler MirrorSampler = sampler_state
|
||||
{
|
||||
Filter = MIN_MAG_MIP_LINEAR;
|
||||
AddressU = mirror;
|
||||
AddressV = mirror;
|
||||
};
|
||||
|
||||
sampler BorderZeroSampler = sampler_state
|
||||
{
|
||||
Filter = MIN_MAG_MIP_POINT;
|
||||
AddressU = Border;
|
||||
AddressV = Border;
|
||||
BorderColor = float4(0, 0, 0, 0);
|
||||
};
|
||||
|
||||
sampler PointSampler = sampler_state
|
||||
{
|
||||
Filter = MIN_MAG_MIP_POINT;
|
||||
AddressU = wrap;
|
||||
AddressV = wrap;
|
||||
};
|
||||
|
||||
RasterizerState RS_Default
|
||||
{
|
||||
FillMode = Solid;
|
||||
CullMode = Back;
|
||||
};
|
||||
|
||||
RasterizerState RS_Nocull
|
||||
{
|
||||
FillMode = Solid;
|
||||
CullMode = None;
|
||||
FrontCounterClockwise = false;
|
||||
DepthClipEnable = false;
|
||||
};
|
||||
|
||||
RasterizerState RS_Nocull_Wireframe
|
||||
{
|
||||
FillMode = Wireframe;
|
||||
CullMode = None;
|
||||
FrontCounterClockwise = false;
|
||||
DepthBias = 0;
|
||||
SlopeScaledDepthBias = 0.f;
|
||||
DepthBiasClamp = 0.f;
|
||||
DepthClipEnable = false;
|
||||
ScissorEnable = false;
|
||||
MultisampleEnable = false;
|
||||
AntialiasedLineEnable = false;
|
||||
};
|
||||
|
||||
RasterizerState RS_Scissor
|
||||
{
|
||||
FillMode = Solid;
|
||||
CullMode = Back;
|
||||
FrontCounterClockwise = false;
|
||||
ScissorEnable = true;
|
||||
};
|
||||
|
||||
DepthStencilState DSS_Default
|
||||
{
|
||||
DepthEnable = true;
|
||||
DepthWriteMask = all;
|
||||
DepthFunc = less_equal;
|
||||
};
|
||||
|
||||
DepthStencilState DSS_None
|
||||
{
|
||||
DepthEnable = false;
|
||||
DepthWriteMask = zero;
|
||||
};
|
||||
|
||||
DepthStencilState DSS_Effect
|
||||
{
|
||||
DepthEnable = true;
|
||||
DepthWriteMask = zero;
|
||||
DepthFunc = less_equal;
|
||||
StencilEnable = false;
|
||||
};
|
||||
|
||||
BlendState BS_None
|
||||
{
|
||||
BlendEnable[0] = false;
|
||||
};
|
||||
|
||||
BlendState BS_AlphaBlend // ALPHA_BLEND
|
||||
{
|
||||
BlendEnable[0] = true;
|
||||
BlendEnable[1] = true;
|
||||
BlendEnable[2] = true;
|
||||
BlendEnable[3] = true;
|
||||
BlendEnable[4] = true;
|
||||
BlendEnable[5] = true;
|
||||
BlendEnable[6] = true;
|
||||
BlendEnable[7] = true;
|
||||
|
||||
// Ac * Aa + Bc * (1 - Aa);
|
||||
SrcBlend = Src_Alpha;
|
||||
DestBlend = Inv_Src_Alpha;
|
||||
BlendOp = Add;
|
||||
};
|
||||
|
||||
BlendState BS_Blend // ADDITIVE_BLEND
|
||||
{
|
||||
BlendEnable[0] = true;
|
||||
BlendEnable[1] = true;
|
||||
BlendEnable[2] = true;
|
||||
BlendEnable[3] = true;
|
||||
BlendEnable[4] = true;
|
||||
BlendEnable[5] = true;
|
||||
BlendEnable[6] = true;
|
||||
BlendEnable[7] = true;
|
||||
|
||||
// Ac * (1) + Bc * (1);
|
||||
SrcBlend = one;
|
||||
DestBlend = one;
|
||||
BlendOp = Add;
|
||||
};
|
||||
|
||||
BlendState BS_UIBlend
|
||||
{
|
||||
BlendEnable[0] = true;
|
||||
BlendEnable[1] = true;
|
||||
BlendEnable[2] = true;
|
||||
BlendEnable[3] = true;
|
||||
BlendEnable[4] = true;
|
||||
BlendEnable[5] = true;
|
||||
BlendEnable[6] = true;
|
||||
BlendEnable[7] = true;
|
||||
|
||||
SrcBlend = Src_Alpha;
|
||||
DestBlend = Inv_Src_Alpha;
|
||||
BlendOp = Add;
|
||||
|
||||
SrcBlendAlpha = One;
|
||||
DestBlendAlpha = Zero;
|
||||
BlendOpAlpha = Add;
|
||||
|
||||
RenderTargetWriteMask[0] = 0x0F; // RGBA 모두 출력
|
||||
};
|
||||
|
||||
BlendState BS_WB_Acc
|
||||
{
|
||||
BlendEnable[0] = true;
|
||||
BlendEnable[1] = true;
|
||||
BlendEnable[2] = true;
|
||||
BlendEnable[3] = true;
|
||||
BlendEnable[4] = true;
|
||||
BlendEnable[5] = true;
|
||||
BlendEnable[6] = true;
|
||||
BlendEnable[7] = true;
|
||||
|
||||
SrcBlend[0] = one;
|
||||
DestBlend[0] = one;
|
||||
BlendOp[0] = Add;
|
||||
|
||||
SrcBlend[1] = Zero;
|
||||
DestBlend[1] = Inv_Src_Alpha;
|
||||
BlendOp[1] = Add;
|
||||
|
||||
|
||||
SrcBlend[2] = one;
|
||||
DestBlend[2] = one;
|
||||
BlendOp[2] = Add;
|
||||
};
|
||||
|
||||
BlendState BS_WeightBlend
|
||||
{
|
||||
BlendEnable[0] = true;
|
||||
BlendEnable[1] = true;
|
||||
BlendEnable[2] = true;
|
||||
BlendEnable[3] = true;
|
||||
BlendEnable[4] = true;
|
||||
BlendEnable[5] = true;
|
||||
BlendEnable[6] = true;
|
||||
BlendEnable[7] = true;
|
||||
|
||||
|
||||
SrcBlend[0] = Src_Alpha;
|
||||
DestBlend[0] = Inv_Src_Alpha;
|
||||
|
||||
BlendOp[0] = Add;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
float ShadowVisibility_hwPCF(Texture2D ShadowMap, float4 vLightClip, float2 vShadowMapSize, float bias)
|
||||
{
|
||||
float2 uv = float2(vLightClip.x / vLightClip.w, -vLightClip.y / vLightClip.w) * 0.5f + 0.5f;
|
||||
float fDepthCenter = saturate(vLightClip.z / vLightClip.w);
|
||||
float2 vTexel = 1.f / vShadowMapSize;
|
||||
|
||||
float fVisibility = 0.f;
|
||||
for (int v = -1; v <= 1; ++v)
|
||||
{
|
||||
for (int u = -1; u <= 1; ++u)
|
||||
{
|
||||
float2 vOffset = float2(u, v) * vTexel;
|
||||
float fDepth = ShadowMap.Sample(DefaultSampler, uv + vOffset).x;
|
||||
fVisibility += (fDepthCenter - bias > fDepth) ? 0.f : 1.f;
|
||||
}
|
||||
}
|
||||
return fVisibility / 9.f;
|
||||
}
|
||||
|
||||
float GetRimLight(float3 vCamPosition, float3 vPosition, float3 vNormal, float fRimPower, float fRimStrength)
|
||||
{
|
||||
float fRimLight = (1 - dot(normalize(vCamPosition - vPosition), vNormal));
|
||||
fRimLight = pow(fRimLight, fRimPower);
|
||||
fRimLight = fRimLight * fRimStrength;
|
||||
return fRimLight;
|
||||
}
|
||||
|
||||
float2 Get_MovedUV(float2 vOriginalUV, float fDeltaU, float fDeltaV, uint iIndexU, uint iIndexV)
|
||||
{
|
||||
float2 vDelta = float2(fDeltaU, fDeltaV);
|
||||
float2 vOffset = float2(iIndexU * fDeltaU, iIndexV * fDeltaV);
|
||||
return vOriginalUV * vDelta + vOffset;
|
||||
}
|
||||
|
||||
float2 UV_Cutting(float2 vUV, float2 vUVCutting, int iCurrentFrame)
|
||||
{
|
||||
float2 UV = vUV; // 이미지의 UV값
|
||||
|
||||
int iTotalFrame = vUVCutting.x * vUVCutting.y; // 이미지의 최대 프레임 (몇 곱하기 몇인지)
|
||||
|
||||
int iFrameX = iCurrentFrame % (int) vUVCutting.x; // 현재 x축의 위치(현재 이미지의 몇번째 칸을 보여줄 지)
|
||||
int iFrameY = iCurrentFrame / (int) vUVCutting.x; // 현재 y축의 위치(현재 이미지의 몇번째 줄을 보여줄 지)
|
||||
|
||||
float fFreamWidth = 1.0 / vUVCutting.x; // 1.0 나누기 이미지 갯수를 해서 한칸에 얼마나 갈지 정해준다.
|
||||
float fFreamHeight = 1.0 / vUVCutting.y; // 1.0 나누기 이미지 갯수를 해서 한줄에 얼마나 갈지 정해준다.
|
||||
|
||||
UV.x = UV.x * fFreamWidth + iFrameX * fFreamWidth; // 먼저 uv를 0~1이 아닌 0~fFrameWidth로 만든 다음에 한칸씩 옆으로 밀어준다.
|
||||
UV.y = UV.y * fFreamHeight + iFrameY * fFreamHeight; // 먼저 uv를 0~1이 아닌 0~fFrameHeight로 만든 다음에 한줄씩 밑으로 내려준다.
|
||||
|
||||
return UV;
|
||||
}
|
||||
|
||||
struct PBR_LIGHT_OUT
|
||||
{
|
||||
float3 vShade;
|
||||
float3 vSpecular;
|
||||
};
|
||||
|
||||
// (Kd F(Lambert)) + (Ks F(cook-torrance))
|
||||
|
||||
//float LambertDiffuse(float c)
|
||||
//{
|
||||
// return c / PI;
|
||||
//}
|
||||
|
||||
// F(cook-torrance)
|
||||
// DFG / (4 (Wo dot N) (Wi dot N))
|
||||
|
||||
// D(distribution, NormalDistribution function), 표면의 거칠기에 영향을 받는 halfWay vector
|
||||
// G(Geometry, GeometryFunc), 에너지 보존법칙 적용
|
||||
// F(Fresnel-Fresnel equation), 표면 각도에 따른 반사율
|
||||
|
||||
// F->D
|
||||
float NDF_ggxtr(float3 vNormal, float3 vHalfWayVector, float fAlpha) // NormalDistributionGGXTR, (H, halfWay vector), (A, Roughness), (N, Normal)
|
||||
{
|
||||
float a2 = fAlpha * fAlpha;
|
||||
float NdotH = saturate(dot(vNormal, vHalfWayVector));
|
||||
float NdotH2 = NdotH * NdotH;
|
||||
|
||||
float nom = a2;
|
||||
float denom = (NdotH2 * (a2 - 1.f) + 1.f);
|
||||
|
||||
denom = PI * denom * denom;
|
||||
return (nom / denom);
|
||||
}
|
||||
|
||||
// F->G
|
||||
// GschlickGGX(n, v, k)
|
||||
// k는 이하 두개 조명 조건에 따라 가변적임
|
||||
// Direct // Kdir -> ((a + 1) * (a + 1)) / 8 // direct lighting 추천
|
||||
// IBL Lighting // Kibl -> a * a / 2 // 이미지 기반 조명기법
|
||||
|
||||
float Geometry_SchlickGGX(float NdotV, float fK)
|
||||
{
|
||||
return NdotV / (NdotV * (1.0f - fK) + fK);
|
||||
}
|
||||
|
||||
float Geometry_Smith(float3 vNormal, float3 vFromView, float3 vFromLight, float k)
|
||||
{
|
||||
// Geometry Obstruction
|
||||
// 철이 있는, 주로 튀어나온 장애물
|
||||
float NdotV = saturate(dot(vNormal, vFromView));
|
||||
|
||||
// Geometry Shadowing
|
||||
// 요가 있는, 주로 음푹 들어간 장애물 (그래서 셰도잉)
|
||||
float NdotL = saturate(dot(vNormal, vFromLight));
|
||||
|
||||
// 요철이 골고루 있다고 가정하고 적당히 섞음
|
||||
return Geometry_SchlickGGX(NdotV, k) * Geometry_SchlickGGX(NdotL, k);
|
||||
}
|
||||
|
||||
// F -> F
|
||||
float3 Fresnel_Schlick(float cosTheta, float3 F0)
|
||||
{
|
||||
// 모서리 부분의 반사
|
||||
return F0 + (1.0f - F0) * pow(1.0f - cosTheta, 5.0f);
|
||||
}
|
||||
|
||||
PBR_LIGHT_OUT PBR_Lighting(
|
||||
float3 vNormal, float3 vFromView, float3 vFromLight,
|
||||
float3 vAlbedo, float fMetallic, float fRoughness,
|
||||
float3 vLightColor, float fAttenuation, float3 vFO
|
||||
) {
|
||||
PBR_LIGHT_OUT Out;
|
||||
Out.vShade = 0;
|
||||
Out.vSpecular = 0;
|
||||
|
||||
float3 vHalfVector = normalize(vFromView + vFromLight);
|
||||
float NdotL = saturate(dot(vNormal, vFromLight));
|
||||
float NdotV = saturate(dot(vNormal, vFromView));
|
||||
if (NdotL <= 0 || NdotV <= 0)
|
||||
{
|
||||
return Out;
|
||||
}
|
||||
float fAlpha = max(fRoughness * fRoughness, 0.04f);
|
||||
float k = ((fRoughness + 1.f) * (fRoughness + 1.f)) / 8.f;
|
||||
|
||||
float D = NDF_ggxtr(vNormal, vHalfVector, fAlpha);
|
||||
float G = Geometry_Smith(vNormal, vFromView, vFromLight, k);
|
||||
float3 F = Fresnel_Schlick(saturate(dot(vHalfVector, vFromView)), vFO);
|
||||
|
||||
float3 vNumerator = D * G * F;
|
||||
float fDenom = max(4.f * NdotL * NdotV, 1e-7);
|
||||
float3 specularBRDF = vNumerator / fDenom;
|
||||
|
||||
float3 kS = F;
|
||||
float3 kD = (1.f - kS) * (1.f -fMetallic);
|
||||
|
||||
//Out.vShade = float(1.f, 1.f, 1. 1.f);
|
||||
Out.vShade = (kD / PI) * (NdotL * fAttenuation) * vLightColor;
|
||||
|
||||
Out.vSpecular = specularBRDF * vLightColor * fAttenuation * NdotL;
|
||||
|
||||
return Out;
|
||||
}
|
||||
#endif // ENGINE_SHADER_DEFINES_HLSLI
|
||||
|
||||
@@ -35,14 +35,13 @@ Texture2D g_BlurTexture;
|
||||
Texture2D g_BlurXTexture;
|
||||
Texture2D g_BlurWeightTexture;
|
||||
|
||||
Texture2D g_SurfaceTexture;
|
||||
|
||||
|
||||
vector g_vLightDiffuse;
|
||||
vector g_vLightAmbient;
|
||||
vector g_vLightSpecular;
|
||||
|
||||
|
||||
|
||||
struct VS_IN
|
||||
{
|
||||
float3 vPosition : POSITION;
|
||||
@@ -56,9 +55,9 @@ struct VS_OUT
|
||||
};
|
||||
VS_OUT VS_MAIN(VS_IN In)
|
||||
{
|
||||
VS_OUT Out;
|
||||
VS_OUT Out;
|
||||
|
||||
matrix matWV, matWVP;
|
||||
matrix matWV, matWVP;
|
||||
|
||||
matWV = mul(g_WorldMatrix, g_ViewMatrix);
|
||||
matWVP = mul(matWV, g_ProjMatrix);
|
||||
@@ -66,7 +65,7 @@ VS_OUT VS_MAIN(VS_IN In)
|
||||
Out.vPosition = mul(vector(In.vPosition, 1.f), matWVP);
|
||||
Out.vTexcoord = In.vTexcoord;
|
||||
|
||||
return Out;
|
||||
return Out;
|
||||
}
|
||||
|
||||
struct PS_IN
|
||||
@@ -99,41 +98,77 @@ PS_OUT_LIGHT PS_MAIN_DIRECTIONAL(PS_IN In)
|
||||
{
|
||||
PS_OUT_LIGHT Out;
|
||||
|
||||
vector vNormalDesc = g_NormalTexture.Sample(DefaultSampler, In.vTexcoord);
|
||||
float2 uv = In.vTexcoord;
|
||||
|
||||
float4 vNormal = vector(vNormalDesc.xyz * 2.f - 1.f, 0.0f);
|
||||
// float3 vNormal = normalize(g_NormalTexture.Sample(DefaultSampler, uv).xyz * 2.f - 1);
|
||||
float3 vNormal = DecodeNormalFromRG(g_NormalTexture, DefaultSampler, uv);
|
||||
|
||||
Out.vShade = g_vLightDiffuse * saturate(max(dot(normalize(g_vLightDir) * -1.f, vNormal), 0.f) + (g_vLightAmbient * g_vMtrlAmbient));
|
||||
float4 vDepth = g_DepthTexture.Sample(DefaultSampler, uv);
|
||||
|
||||
vector vDepthDesc = g_DepthTexture.Sample(DefaultSampler, In.vTexcoord);
|
||||
float fViewZ = vDepth.y * g_fFar;
|
||||
|
||||
float fViewZ = vDepthDesc.y * g_fFar;
|
||||
float4 vWorldPosition;
|
||||
{
|
||||
vWorldPosition.x = uv.x * 2 - 1;
|
||||
vWorldPosition.y = uv.y * -2 + 1;
|
||||
vWorldPosition.z = vDepth.x;
|
||||
vWorldPosition.w = 1.f;
|
||||
vWorldPosition *= fViewZ;
|
||||
vWorldPosition = mul(vWorldPosition, g_invmatProj);
|
||||
vWorldPosition = mul(vWorldPosition, g_invMatView);
|
||||
}
|
||||
|
||||
vector vPosition;
|
||||
float3 vF0;
|
||||
float fMetallic;
|
||||
float fRoughness;
|
||||
float fOcclusion;
|
||||
float fAttenuation;
|
||||
|
||||
{ // vDepthDesc과 vTexcoord.xy로부터 World Position의 추론
|
||||
/* 직육면체의 NDC */
|
||||
/* LocalPos * World * View * Proj * ( 1 / w ) */
|
||||
vPosition.x = In.vTexcoord.x * 2.f - 1.f;
|
||||
vPosition.y = In.vTexcoord.y * -2.f + 1.f;
|
||||
vPosition.z = vDepthDesc.x;
|
||||
vPosition.w = 1.f;
|
||||
float3 vWPos = vWorldPosition.xyz;
|
||||
float3 vFromView = normalize(vWPos - g_vCamPosition.xyz); // 카메라에서 픽셀로 가는 방향
|
||||
float3 vFromLight = normalize(g_vLightDir.xyz); // 라이트에서 오는 라이트 벡터
|
||||
|
||||
/* [* (1 / w)] 소거*/
|
||||
/* z나누기를 되돌림 */
|
||||
vPosition = vPosition * fViewZ;
|
||||
// vPosition.x = In.vTexcoord.x * 2.f - 1.f * Far;
|
||||
// vPosition.y = In.vTexcoord.y * -2.f + 1.f * Far;
|
||||
// vPosition.z = vDepthDesc.x * Far;
|
||||
// vPosition.w = Far;
|
||||
float3 vAlbedo = g_DiffuseTexture.Sample(DefaultSampler, uv).rgb;
|
||||
|
||||
vPosition = mul(vPosition, g_invmatProj);
|
||||
vPosition = mul(vPosition, g_invMatView);
|
||||
}
|
||||
vector vLook = vPosition - g_vCamPosition;
|
||||
vector vReflect = reflect(normalize(g_vLightDir), vNormal);
|
||||
if (true == AlmostEqual3(vDepth.b, AI_TEXTURE_TYPE_METALNESS)) // Metallic
|
||||
{
|
||||
float3 vMRO = g_SurfaceTexture.Sample(DefaultSampler, uv).rgb;
|
||||
fMetallic = vMRO.r;
|
||||
fRoughness = vMRO.g;
|
||||
fOcclusion = vMRO.b;
|
||||
|
||||
vF0 = lerp(float3(0.04f, 0.04f, 0.04f), vAlbedo, fMetallic);
|
||||
}
|
||||
else if (true == AlmostEqual3(vDepth.b, AI_TEXTURE_TYPE_SPECULAR)) // Specular
|
||||
{
|
||||
float3 vSRO = g_SurfaceTexture.Sample(DefaultSampler, uv).rgb;
|
||||
float3 vSpec = vSRO.r;
|
||||
|
||||
fMetallic = 0.f;
|
||||
fRoughness = vSRO.g;
|
||||
fOcclusion = vSRO.b;
|
||||
|
||||
|
||||
vF0 = vSpec.xxx;
|
||||
}
|
||||
else
|
||||
{
|
||||
fMetallic = 0.f;
|
||||
fRoughness = 0.5f;
|
||||
fOcclusion = 1.f;
|
||||
vF0 = float3(0.04f, 0.04f, 0.04f);
|
||||
}
|
||||
|
||||
Out.vSpecular = (g_vLightSpecular * g_vMtrlSpecular) * pow(max(dot(normalize(vLook) * -1.f, normalize(vReflect)), 0.f), 50.f);
|
||||
fAttenuation = 1.f;
|
||||
|
||||
float fDiffuseAOStrength = lerp(0.3f, 1.f, fOcclusion);
|
||||
|
||||
PBR_LIGHT_OUT PBR_Out = PBR_Lighting(vNormal, vFromView, vFromLight, vAlbedo, fMetallic, fRoughness, g_vLightDiffuse.rgb, fAttenuation, vF0);
|
||||
|
||||
PBR_Out.vShade *= fDiffuseAOStrength;
|
||||
|
||||
Out.vShade = float4(PBR_Out.vShade, 1.f);
|
||||
Out.vSpecular = float4(PBR_Out.vSpecular, 1.f);
|
||||
|
||||
return Out;
|
||||
}
|
||||
@@ -142,38 +177,81 @@ PS_OUT_LIGHT PS_MAIN_POINT(PS_IN In)
|
||||
{
|
||||
PS_OUT_LIGHT Out;
|
||||
|
||||
vector vNormalDesc = g_NormalTexture.Sample(DefaultSampler, In.vTexcoord);
|
||||
float2 uv = In.vTexcoord;
|
||||
|
||||
float4 vNormal = vector(vNormalDesc.xyz * 2.f - 1.f, 0.f);
|
||||
float3 vNormal = DecodeNormalFromRG(g_NormalTexture, DefaultSampler, uv);
|
||||
|
||||
vector vDepthDesc = g_DepthTexture.Sample(DefaultSampler, In.vTexcoord);
|
||||
float fViewZ = vDepthDesc.y * g_fFar;
|
||||
float4 vDepth = g_DepthTexture.Sample(DefaultSampler, uv);
|
||||
|
||||
vector vPosition;
|
||||
/* 0 ~ 1 에서 -1 ~ 1 */
|
||||
vPosition.x = In.vTexcoord.x * 2.f - 1.f;
|
||||
vPosition.y = In.vTexcoord.y * -2.f + 1.f;
|
||||
vPosition.z = vDepthDesc.x;
|
||||
vPosition.w = 1.f;
|
||||
vPosition = vPosition * fViewZ;
|
||||
vPosition = mul(vPosition, g_invmatProj);
|
||||
vPosition = mul(vPosition, g_invMatView);
|
||||
float fViewZ = vDepth.y * g_fFar;
|
||||
|
||||
vector vLightDir = vPosition - (g_vLightPos + g_vLightPosOffset);
|
||||
float fDistance = length(vLightDir);
|
||||
float fAttenuation = saturate((g_fLightRange - fDistance) / g_fLightRange);
|
||||
if (fAttenuation <= 0.f)
|
||||
float4 vWorldPosition;
|
||||
{
|
||||
discard;
|
||||
vWorldPosition.x = uv.x * 2 - 1;
|
||||
vWorldPosition.y = uv.y * -2 + 1;
|
||||
vWorldPosition.z = vDepth.x;
|
||||
vWorldPosition.w = 1.f;
|
||||
vWorldPosition *= fViewZ;
|
||||
vWorldPosition = mul(vWorldPosition, g_invmatProj);
|
||||
vWorldPosition = mul(vWorldPosition, g_invMatView);
|
||||
}
|
||||
vLightDir = normalize(vLightDir);
|
||||
|
||||
Out.vShade = fAttenuation * (g_vLightDiffuse * saturate(max(dot(vLightDir * -1.f, vNormal), 0.f) + (g_vLightAmbient * g_vMtrlAmbient)));
|
||||
float3 vWPos = vWorldPosition.xyz;
|
||||
float3 vFromView = normalize(vWPos - g_vCamPosition.xyz); // 카메라에서 픽셀로 가는 방향
|
||||
float3 vFromLight = normalize(g_vLightDir.xyz); // 라이트에서 오는 라이트 벡터
|
||||
|
||||
vector vLook = vPosition - g_vCamPosition;
|
||||
vector vReflect = reflect(vLightDir, vNormal);
|
||||
float3 vF0;
|
||||
float fMetallic;
|
||||
float fRoughness;
|
||||
float fOcclusion;
|
||||
float fAttenuation;
|
||||
|
||||
Out.vSpecular = fAttenuation * ((g_vLightSpecular * g_vMtrlSpecular) * pow(max(dot(normalize(vLook) * -1.f, normalize(vReflect)), 0.f), 50.f));
|
||||
{
|
||||
float fDistance = length(vFromLight);
|
||||
fAttenuation = saturate((g_fLightRange - fDistance) / g_fLightRange);
|
||||
if (fAttenuation <= 0.f)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
}
|
||||
|
||||
float3 vAlbedo = g_DiffuseTexture.Sample(DefaultSampler, uv).rgb;
|
||||
|
||||
if (true == AlmostEqual3(vDepth.b, AI_TEXTURE_TYPE_METALNESS)) // Metallic
|
||||
{
|
||||
float3 vMRO = g_SurfaceTexture.Sample(DefaultSampler, uv).rgb;
|
||||
fMetallic = vMRO.r;
|
||||
fRoughness = vMRO.g;
|
||||
fOcclusion = vMRO.b;
|
||||
|
||||
vF0 = lerp(float3(0.04f, 0.04f, 0.04f), vAlbedo, fMetallic);
|
||||
}
|
||||
else if (true == AlmostEqual3(vDepth.b, AI_TEXTURE_TYPE_SPECULAR)) // Specular
|
||||
{
|
||||
float3 vSRO = g_SurfaceTexture.Sample(DefaultSampler, uv).rgb;
|
||||
float3 vSpec = vSRO.r;
|
||||
|
||||
fMetallic = 0.f;
|
||||
fRoughness = vSRO.g;
|
||||
fOcclusion = vSRO.b;
|
||||
|
||||
|
||||
vF0 = vSpec.xxx;
|
||||
}
|
||||
else
|
||||
{
|
||||
fMetallic = 0.f;
|
||||
fRoughness = 0.5f;
|
||||
fOcclusion = 1.f;
|
||||
vF0 = float3(0.04f, 0.04f, 0.04f);
|
||||
}
|
||||
|
||||
PBR_LIGHT_OUT PBR_Out = PBR_Lighting(vNormal, vFromView, vFromLight,
|
||||
vAlbedo, fMetallic, fRoughness,
|
||||
g_vLightDiffuse.rgb, fAttenuation, vF0);
|
||||
|
||||
Out.vShade = float4(PBR_Out.vShade, 1.f);
|
||||
Out.vSpecular = float4(PBR_Out.vSpecular, 1.f);
|
||||
|
||||
return Out;
|
||||
}
|
||||
@@ -182,46 +260,85 @@ PS_OUT_LIGHT PS_MAIN_SPOT(PS_IN In)
|
||||
{
|
||||
PS_OUT_LIGHT Out;
|
||||
|
||||
vector vNormalDesc = g_NormalTexture.Sample(DefaultSampler, In.vTexcoord);
|
||||
float2 uv = In.vTexcoord;
|
||||
|
||||
float4 vNormal = vector(vNormalDesc.xyz * 2.f - 1.f, 0.f);
|
||||
float3 vNormal = DecodeNormalFromRG(g_NormalTexture, DefaultSampler, uv);
|
||||
|
||||
vector vDepthDesc = g_DepthTexture.Sample(DefaultSampler, In.vTexcoord);
|
||||
float fViewZ = vDepthDesc.y * g_fFar;
|
||||
float4 vDepth = g_DepthTexture.Sample(DefaultSampler, uv);
|
||||
|
||||
vector vPosition;
|
||||
/* 0 ~ 1 에서 -1 ~ 1 */
|
||||
vPosition.x = In.vTexcoord.x * 2.f - 1.f;
|
||||
vPosition.y = In.vTexcoord.y * -2.f + 1.f;
|
||||
vPosition.z = vDepthDesc.x;
|
||||
vPosition.w = 1.f;
|
||||
vPosition = vPosition * fViewZ;
|
||||
vPosition = mul(vPosition, g_invmatProj);
|
||||
vPosition = mul(vPosition, g_invMatView);
|
||||
float fViewZ = vDepth.y * g_fFar;
|
||||
|
||||
vector vLightDir = vPosition - g_vLightPos;
|
||||
float fDistance = length(vLightDir);
|
||||
float fAttenuation = saturate((g_fLightRange - fDistance) / g_fLightRange);
|
||||
if (fAttenuation <= 0.f)
|
||||
float4 vWorldPosition;
|
||||
{
|
||||
discard;
|
||||
vWorldPosition.x = uv.x * 2 - 1;
|
||||
vWorldPosition.y = uv.y * -2 + 1;
|
||||
vWorldPosition.z = vDepth.x;
|
||||
vWorldPosition.w = 1.f;
|
||||
vWorldPosition *= fViewZ;
|
||||
vWorldPosition = mul(vWorldPosition, g_invmatProj);
|
||||
vWorldPosition = mul(vWorldPosition, g_invMatView);
|
||||
}
|
||||
vLightDir = normalize(vLightDir);
|
||||
vector vSpotDir = normalize(g_vLightDir);
|
||||
float fCosAngle = dot(vLightDir, vSpotDir);
|
||||
|
||||
float3 vWPos = vWorldPosition.xyz;
|
||||
float3 vFromView = normalize(vWPos - g_vCamPosition.xyz); // 카메라에서 픽셀로 가는 방향
|
||||
float3 vFromLight = normalize(g_vLightDir.xyz); // 라이트에서 오는 라이트 벡터
|
||||
|
||||
float3 vF0;
|
||||
float fMetallic;
|
||||
float fRoughness;
|
||||
float fOcclusion;
|
||||
float fAttenuation;
|
||||
{
|
||||
float fDistance = length(vFromLight);
|
||||
fAttenuation = saturate((g_fLightRange - fDistance) / g_fLightRange);
|
||||
if (fAttenuation <= 0.f)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
}
|
||||
float fCosAngle = dot(vFromLight, g_vLightDir.xyz);
|
||||
if (fCosAngle < g_fSpotOuterAngle)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
float fSpotAttenenuation = saturate((fCosAngle - g_fSpotInnerAngle) / (g_fSpotInnerAngle - g_fSpotOuterAngle));
|
||||
float fSpotAttenenuation = saturate((fCosAngle - g_fSpotInnerAngle) / (g_fSpotInnerAngle - g_fSpotOuterAngle));
|
||||
fAttenuation *= fSpotAttenenuation;
|
||||
|
||||
Out.vShade = fAttenuation * (g_vLightDiffuse * saturate(max(dot(vLightDir * -1.f, vNormal), 0.f) + (g_vLightAmbient * g_vMtrlAmbient)));
|
||||
float3 vAlbedo = g_DiffuseTexture.Sample(DefaultSampler, uv).rgb;
|
||||
|
||||
vector vLook = vPosition - g_vCamPosition;
|
||||
vector vReflect = reflect(vLightDir, vNormal);
|
||||
if (true == AlmostEqual3(vDepth.b, AI_TEXTURE_TYPE_METALNESS)) // Metallic
|
||||
{
|
||||
float3 vMRO = g_SurfaceTexture.Sample(DefaultSampler, uv).rgb;
|
||||
fMetallic = vMRO.r;
|
||||
fRoughness = vMRO.g;
|
||||
fOcclusion = vMRO.b;
|
||||
|
||||
vF0 = lerp(float3(0.04f, 0.04f, 0.04f), vAlbedo, fMetallic);
|
||||
}
|
||||
else if (true == AlmostEqual3(vDepth.b, AI_TEXTURE_TYPE_SPECULAR)) // Specular
|
||||
{
|
||||
float3 vSRO = g_SurfaceTexture.Sample(DefaultSampler, uv).rgb;
|
||||
float3 vSpec = vSRO.r;
|
||||
|
||||
fMetallic = 0.f;
|
||||
fRoughness = vSRO.g;
|
||||
fOcclusion = vSRO.b;
|
||||
|
||||
|
||||
vF0 = vSpec.xxx;
|
||||
}
|
||||
else
|
||||
{
|
||||
fMetallic = 0.f;
|
||||
fRoughness = 0.5f;
|
||||
fOcclusion = 1.f;
|
||||
vF0 = float3(0.04f, 0.04f, 0.04f);
|
||||
}
|
||||
|
||||
Out.vSpecular = fAttenuation * ((g_vLightSpecular * g_vMtrlSpecular) * pow(max(dot(normalize(vLook) * -1.f, normalize(vReflect)), 0.f), 50.f));
|
||||
PBR_LIGHT_OUT PBR_Out = PBR_Lighting(vNormal, vFromView, vFromLight, vAlbedo, fMetallic, fRoughness, g_vLightDiffuse.rgb, fAttenuation, vF0);
|
||||
|
||||
Out.vShade = float4(PBR_Out.vShade, 1.f);
|
||||
Out.vSpecular = float4(PBR_Out.vSpecular, 1.f);
|
||||
|
||||
return Out;
|
||||
}
|
||||
@@ -271,107 +388,7 @@ PS_OUT_BACKBUFFER PS_MAIN_COMBINED(PS_IN In)
|
||||
vPosition = mul(vPosition, g_invmatProj);
|
||||
vPosition = mul(vPosition, g_invMatView);
|
||||
vPreShadowPosition = vPosition;
|
||||
/* (로컬위치 * 월드) -> (로컬위치 * 월드 * 광원의 뷰 * 광원의 투영 ) */
|
||||
vPosition = mul(vPosition, g_LightViewMatrix);
|
||||
vPosition = mul(vPosition, g_LightProjMatrix);
|
||||
vPreShadowPosition = mul(vPreShadowPosition, g_PreShadowLightViewMatrix);
|
||||
vPreShadowPosition = mul(vPreShadowPosition, g_PreShadowLightProjMatrix);
|
||||
|
||||
/* (로컬위치 * 월드 * 광원의 뷰 * 광원의 투영 ) -> (로컬위치 * 월드 * 광원의 뷰 * 광원의 투영 * (/w) */
|
||||
float2 vTexcoord, vPreShadowTexcoord;
|
||||
vTexcoord.x = (vPosition.x / vPosition.w) * 0.5f + 0.5f;
|
||||
vTexcoord.y = (vPosition.y / vPosition.w) * -0.5f + 0.5f;
|
||||
vPreShadowTexcoord.x = (vPreShadowPosition.x / vPreShadowPosition.w) * 0.5f + 0.5f;
|
||||
vPreShadowTexcoord.y = (vPreShadowPosition.y / vPreShadowPosition.w) * -0.5f + 0.5f;
|
||||
|
||||
/* 광원의 NDC에서 샘플링 */
|
||||
float fVisibility_Dynamic = ShadowVisibility_hwPCF(g_ShadowTexture, vPosition, float2(g_iMaxShadowWidth, g_iMaxShadowHeight), 0.0005f);
|
||||
float fVisibility_Static = ShadowVisibility_hwPCF(g_PreShadowTexture, vPreShadowPosition, float2(g_iMaxShadowWidth, g_iMaxShadowHeight), 0.0005f);
|
||||
|
||||
Out.vBackBuffer.rgb *= lerp(0.5f, 1.f, min(fVisibility_Dynamic, fVisibility_Static));
|
||||
//float fShadowDepth = g_ShadowTexture.Sample(DefaultSampler, vTexcoord).x;
|
||||
//float fPreShadowDepth = g_PreShadowTexture.Sample(DefaultSampler, vPreShadowTexcoord).x;
|
||||
//bool IsShadow = { false };
|
||||
//if (vPosition.z - 0.0005f > fShadowDepth)
|
||||
//{
|
||||
// IsShadow = true;
|
||||
//}
|
||||
//if (vPreShadowPosition.z - 0.0005f > fPreShadowDepth)
|
||||
//{
|
||||
// IsShadow = true;
|
||||
//}
|
||||
//if (true == IsShadow)
|
||||
//{
|
||||
// Out.vBackBuffer *= 0.5f;
|
||||
//}
|
||||
float4 vColor = 0.f;
|
||||
|
||||
//int iBlurWeight = g_BlurWeightTexture.Sample(ClampSampler, In.vTexcoord).r * 32.f;
|
||||
|
||||
//int iBlurMin;
|
||||
//int iBlurMax;
|
||||
|
||||
//if (iBlurWeight % 2 == 0)
|
||||
//{
|
||||
// iBlurMin = -1 * iBlurWeight / 2;
|
||||
// iBlurMax = iBlurWeight / 2;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// iBlurMin = -iBlurWeight / 2;
|
||||
// iBlurMax = iBlurWeight / 2 + 1;
|
||||
//}
|
||||
|
||||
//[loop] // 변수로 루프돌리려면 반드시 필요함
|
||||
for (int i = -15; i < 16; ++i)
|
||||
{
|
||||
vTexcoord.x = In.vTexcoord.x;
|
||||
vTexcoord.y = In.vTexcoord.y + (float) i / g_vResolution.y;
|
||||
|
||||
vColor += g_fWeights[i + 15] * g_BlurXTexture.Sample(ClampSampler, vTexcoord);
|
||||
}
|
||||
|
||||
Out.vBackBuffer += vColor;
|
||||
|
||||
return Out;
|
||||
}
|
||||
|
||||
PS_OUT_BACKBUFFER PS_MAIN_MROCOMBINED(PS_IN In)
|
||||
{
|
||||
PS_OUT_BACKBUFFER Out;
|
||||
|
||||
vector vDiffuse = g_DiffuseTexture.Sample(DefaultSampler, In.vTexcoord);
|
||||
|
||||
if (0.f == vDiffuse.a)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
|
||||
vector vShade = g_ShadeTexture.Sample(DefaultSampler, In.vTexcoord);
|
||||
|
||||
vector vSpecular = g_SpecularTexture.Sample(DefaultSampler, In.vTexcoord);
|
||||
|
||||
Out.vBackBuffer = vDiffuse * vShade + vSpecular;
|
||||
|
||||
vector vDepthDesc = g_DepthTexture.Sample(DefaultSampler, In.vTexcoord);
|
||||
|
||||
|
||||
float fViewZ = vDepthDesc.y * g_fFar;
|
||||
|
||||
|
||||
vector vPosition, vPreShadowPosition;
|
||||
|
||||
/* (로컬위치 * 월드 * 뷰 * 투영 / w) -> (로컬위치 * 월드) */
|
||||
vPosition.x = In.vTexcoord.x * 2.f - 1.f;
|
||||
vPosition.y = In.vTexcoord.y * -2.f + 1.f;
|
||||
vPosition.z = vDepthDesc.x;
|
||||
vPosition.w = 1.f;
|
||||
|
||||
vPosition = vPosition * fViewZ;
|
||||
|
||||
vPosition = mul(vPosition, g_invmatProj);
|
||||
vPosition = mul(vPosition, g_invMatView);
|
||||
vPreShadowPosition = vPosition;
|
||||
/* (로컬위치 * 월드) -> (로컬위치 * 월드 * 광원의 뷰 * 광원의 투영 ) */
|
||||
vPosition = mul(vPosition, g_LightViewMatrix);
|
||||
vPosition = mul(vPosition, g_LightProjMatrix);
|
||||
@@ -478,7 +495,7 @@ PS_OUT_BLUR_X PS_MAIN_BLUR_X(PS_IN In)
|
||||
vColor += g_fWeights[i + 15] * g_BlurTexture.Sample(ClampSampler, vTexcoord);
|
||||
}
|
||||
|
||||
Out.vBlurX = vColor;
|
||||
Out.vBlurX = vColor;
|
||||
|
||||
return Out;
|
||||
}
|
||||
@@ -486,7 +503,7 @@ PS_OUT_BLUR_X PS_MAIN_BLUR_X(PS_IN In)
|
||||
|
||||
technique11 DefaultTechnique
|
||||
{
|
||||
pass DebugPass
|
||||
pass DebugPass // 0
|
||||
{
|
||||
SetRasterizerState(RS_Default);
|
||||
SetDepthStencilState(DSS_Default, 0);
|
||||
@@ -496,7 +513,7 @@ technique11 DefaultTechnique
|
||||
PixelShader = compile ps_5_0 PS_MAIN_DEBUG();
|
||||
}
|
||||
|
||||
pass DirectionalPass
|
||||
pass DirectionalPass // 1
|
||||
{
|
||||
SetRasterizerState(RS_Default);
|
||||
SetDepthStencilState(DSS_None, 0);
|
||||
@@ -506,7 +523,7 @@ technique11 DefaultTechnique
|
||||
PixelShader = compile ps_5_0 PS_MAIN_DIRECTIONAL();
|
||||
}
|
||||
|
||||
pass PointPass
|
||||
pass PointPass // 2
|
||||
{
|
||||
SetRasterizerState(RS_Default);
|
||||
SetDepthStencilState(DSS_None, 0);
|
||||
@@ -516,7 +533,7 @@ technique11 DefaultTechnique
|
||||
PixelShader = compile ps_5_0 PS_MAIN_POINT();
|
||||
}
|
||||
|
||||
pass CombinedPass
|
||||
pass CombinedPass // 3
|
||||
{
|
||||
SetRasterizerState(RS_Default);
|
||||
SetDepthStencilState(DSS_None, 0);
|
||||
@@ -526,7 +543,7 @@ technique11 DefaultTechnique
|
||||
PixelShader = compile ps_5_0 PS_MAIN_COMBINED();
|
||||
}
|
||||
|
||||
pass BlurPass
|
||||
pass BlurPass // 4
|
||||
{
|
||||
SetRasterizerState(RS_Default);
|
||||
SetDepthStencilState(DSS_None, 0);
|
||||
@@ -536,7 +553,7 @@ technique11 DefaultTechnique
|
||||
PixelShader = compile ps_5_0 PS_MAIN_BLUR_X();
|
||||
}
|
||||
|
||||
pass SpotPass
|
||||
pass SpotPass // 5
|
||||
{
|
||||
SetRasterizerState(RS_Default);
|
||||
SetDepthStencilState(DSS_None, 0);
|
||||
@@ -545,13 +562,4 @@ technique11 DefaultTechnique
|
||||
GeometryShader = NULL;
|
||||
PixelShader = compile ps_5_0 PS_MAIN_SPOT();
|
||||
}
|
||||
pass MROCombinedPass
|
||||
{
|
||||
SetRasterizerState(RS_Default);
|
||||
SetDepthStencilState(DSS_None, 0);
|
||||
SetBlendState(BS_None, float4(0.f, 0.f, 0.f, 0.f), 0xffffffff);
|
||||
VertexShader = compile vs_5_0 VS_MAIN();
|
||||
GeometryShader = NULL;
|
||||
PixelShader = compile ps_5_0 PS_MAIN_MROCOMBINED();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ namespace Client {
|
||||
#define FX_POSTEX TEXT("FX_POSTEX")
|
||||
#define FX_NORTEX TEXT("FX_NORTEX")
|
||||
#define FX_CELL TEXT("FX_CELL")
|
||||
#define FX_DEFERRED TEXT("FX_DEFFERED")
|
||||
#define FX_PARTICLE TEXT("FX_PARTICLE")
|
||||
#define FX_UIEDITOR TEXT("FX_UIEDITOR")
|
||||
|
||||
@@ -58,4 +57,4 @@ namespace Client {
|
||||
#pragma region MACRO_EXTRA
|
||||
|
||||
#pragma endregion
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,47 @@
|
||||
#ifndef ENGINE_SHADER_CONSTANTS_HLSLI
|
||||
#define ENGINE_SHADER_CONSTANTS_HLSLI
|
||||
|
||||
static const vector g_vMtrlDiffuse = 1.f;
|
||||
static const vector g_vMtrlAmbient = 1.f;
|
||||
static const vector g_vMtrlSpecular = 1.f;
|
||||
|
||||
static const float PI = 3.14159265359;
|
||||
static const float PI2 = 6.28318530718;
|
||||
|
||||
static const float FLT_EPSILON7 = 1.192092896e-07;
|
||||
static const float FLT_EPSILON5 = 1.192092896e-05;
|
||||
static const float FLT_EPSILON3 = 1.192092896e-03;
|
||||
|
||||
|
||||
static const float AI_TEXTURE_TYPE_NONE = 0.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_DIFFUSE = 1.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_SPECULAR = 2.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_AMBIENT = 3.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_EMISSIVE = 4.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_HEIGHT = 5.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_NORMALS = 6.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_SHININESS = 7.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_OPACITY = 8.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_DISPLACEMENT = 9.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_LIGHTMAP = 10.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_REFLECTION = 11.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_BASE_COLOR = 12.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_NORMAL_CAMERA = 13.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_EMISSION_COLOR = 14.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_METALNESS = 15.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_DIFFUSE_ROUGHNESS = 16.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_AMBIENT_OCCLUSION = 17.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_UNKNOWN = 18.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_SHEEN = 19.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_CLEARCOAT = 20.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_TRANSMISSION = 21.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_MAYA_BASE = 22.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_MAYA_SPECULAR = 23.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_MAYA_SPECULAR_COLOR = 24.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_MAYA_SPECULAR_ROUGHNESS = 25.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_ANISOTROPY = 26.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_GLTF_METALLIC_ROUGHNESS = 27.f / 27.f;
|
||||
|
||||
|
||||
|
||||
#endif // ENGINE_SHADER_CONSTANTS_HLSLI
|
||||
@@ -1,362 +1,10 @@
|
||||
#ifndef ENGINE_SHADER_DEFINES_HLSLI
|
||||
#define ENGINE_SHADER_DEFINES_HLSLI
|
||||
|
||||
vector g_vMtrlDiffuse = 1.f;
|
||||
vector g_vMtrlAmbient = 1.f;
|
||||
vector g_vMtrlSpecular = 1.f;
|
||||
#include "Engine_Shader_Constants.hlsli"
|
||||
#include "Engine_Shader_Structures.hlsli"
|
||||
#include "Engine_Shader_Samplers.hlsli"
|
||||
#include "Engine_Shader_States.hlsli"
|
||||
#include "Engine_Shader_Functions.hlsli"
|
||||
|
||||
float PI = 3.14592;
|
||||
|
||||
sampler DefaultSampler = sampler_state
|
||||
{
|
||||
Filter = MIN_MAG_MIP_LINEAR;
|
||||
AddressU = wrap;
|
||||
AddressV = wrap;
|
||||
};
|
||||
|
||||
sampler ClampSampler = sampler_state
|
||||
{
|
||||
Filter = MIN_MAG_MIP_POINT;
|
||||
AddressU = clamp;
|
||||
AddressV = clamp;
|
||||
};
|
||||
|
||||
sampler MirrorSampler = sampler_state
|
||||
{
|
||||
Filter = MIN_MAG_MIP_LINEAR;
|
||||
AddressU = mirror;
|
||||
AddressV = mirror;
|
||||
};
|
||||
|
||||
sampler BorderZeroSampler = sampler_state
|
||||
{
|
||||
Filter = MIN_MAG_MIP_POINT;
|
||||
AddressU = Border;
|
||||
AddressV = Border;
|
||||
BorderColor = float4(0, 0, 0, 0);
|
||||
};
|
||||
|
||||
sampler PointSampler = sampler_state
|
||||
{
|
||||
Filter = MIN_MAG_MIP_POINT;
|
||||
AddressU = wrap;
|
||||
AddressV = wrap;
|
||||
};
|
||||
|
||||
RasterizerState RS_Default
|
||||
{
|
||||
FillMode = Solid;
|
||||
CullMode = Back;
|
||||
};
|
||||
|
||||
RasterizerState RS_Nocull
|
||||
{
|
||||
FillMode = Solid;
|
||||
CullMode = None;
|
||||
FrontCounterClockwise = false;
|
||||
DepthClipEnable = false;
|
||||
};
|
||||
|
||||
RasterizerState RS_Nocull_Wireframe
|
||||
{
|
||||
FillMode = Wireframe;
|
||||
CullMode = None;
|
||||
FrontCounterClockwise = false;
|
||||
DepthBias = 0;
|
||||
SlopeScaledDepthBias = 0.f;
|
||||
DepthBiasClamp = 0.f;
|
||||
DepthClipEnable = false;
|
||||
ScissorEnable = false;
|
||||
MultisampleEnable = false;
|
||||
AntialiasedLineEnable = false;
|
||||
};
|
||||
|
||||
RasterizerState RS_Scissor
|
||||
{
|
||||
FillMode = Solid;
|
||||
CullMode = Back;
|
||||
FrontCounterClockwise = false;
|
||||
ScissorEnable = true;
|
||||
};
|
||||
|
||||
DepthStencilState DSS_Default
|
||||
{
|
||||
DepthEnable = true;
|
||||
DepthWriteMask = all;
|
||||
DepthFunc = less_equal;
|
||||
};
|
||||
|
||||
DepthStencilState DSS_None
|
||||
{
|
||||
DepthEnable = false;
|
||||
DepthWriteMask = zero;
|
||||
};
|
||||
|
||||
DepthStencilState DSS_Effect
|
||||
{
|
||||
DepthEnable = true;
|
||||
DepthWriteMask = zero;
|
||||
DepthFunc = less_equal;
|
||||
StencilEnable = false;
|
||||
};
|
||||
|
||||
BlendState BS_None
|
||||
{
|
||||
BlendEnable[0] = false;
|
||||
};
|
||||
|
||||
BlendState BS_AlphaBlend // ALPHA_BLEND
|
||||
{
|
||||
BlendEnable[0] = true;
|
||||
BlendEnable[1] = true;
|
||||
BlendEnable[2] = true;
|
||||
BlendEnable[3] = true;
|
||||
BlendEnable[4] = true;
|
||||
BlendEnable[5] = true;
|
||||
BlendEnable[6] = true;
|
||||
BlendEnable[7] = true;
|
||||
|
||||
// Ac * Aa + Bc * (1 - Aa);
|
||||
SrcBlend = Src_Alpha;
|
||||
DestBlend = Inv_Src_Alpha;
|
||||
BlendOp = Add;
|
||||
};
|
||||
|
||||
BlendState BS_Blend // ADDITIVE_BLEND
|
||||
{
|
||||
BlendEnable[0] = true;
|
||||
BlendEnable[1] = true;
|
||||
BlendEnable[2] = true;
|
||||
BlendEnable[3] = true;
|
||||
BlendEnable[4] = true;
|
||||
BlendEnable[5] = true;
|
||||
BlendEnable[6] = true;
|
||||
BlendEnable[7] = true;
|
||||
|
||||
// Ac * (1) + Bc * (1);
|
||||
SrcBlend = one;
|
||||
DestBlend = one;
|
||||
BlendOp = Add;
|
||||
};
|
||||
|
||||
BlendState BS_UIBlend
|
||||
{
|
||||
BlendEnable[0] = true;
|
||||
BlendEnable[1] = true;
|
||||
BlendEnable[2] = true;
|
||||
BlendEnable[3] = true;
|
||||
BlendEnable[4] = true;
|
||||
BlendEnable[5] = true;
|
||||
BlendEnable[6] = true;
|
||||
BlendEnable[7] = true;
|
||||
|
||||
SrcBlend = Src_Alpha;
|
||||
DestBlend = Inv_Src_Alpha;
|
||||
BlendOp = Add;
|
||||
|
||||
SrcBlendAlpha = One;
|
||||
DestBlendAlpha = Zero;
|
||||
BlendOpAlpha = Add;
|
||||
|
||||
RenderTargetWriteMask[0] = 0x0F; // RGBA 모두 출력
|
||||
};
|
||||
|
||||
BlendState BS_WB_Acc
|
||||
{
|
||||
BlendEnable[0] = true;
|
||||
BlendEnable[1] = true;
|
||||
BlendEnable[2] = true;
|
||||
BlendEnable[3] = true;
|
||||
BlendEnable[4] = true;
|
||||
BlendEnable[5] = true;
|
||||
BlendEnable[6] = true;
|
||||
BlendEnable[7] = true;
|
||||
|
||||
SrcBlend[0] = one;
|
||||
DestBlend[0] = one;
|
||||
BlendOp[0] = Add;
|
||||
|
||||
SrcBlend[1] = Zero;
|
||||
DestBlend[1] = Inv_Src_Alpha;
|
||||
BlendOp[1] = Add;
|
||||
|
||||
|
||||
SrcBlend[2] = one;
|
||||
DestBlend[2] = one;
|
||||
BlendOp[2] = Add;
|
||||
};
|
||||
|
||||
BlendState BS_WeightBlend
|
||||
{
|
||||
BlendEnable[0] = true;
|
||||
BlendEnable[1] = true;
|
||||
BlendEnable[2] = true;
|
||||
BlendEnable[3] = true;
|
||||
BlendEnable[4] = true;
|
||||
BlendEnable[5] = true;
|
||||
BlendEnable[6] = true;
|
||||
BlendEnable[7] = true;
|
||||
|
||||
|
||||
SrcBlend[0] = Src_Alpha;
|
||||
DestBlend[0] = Inv_Src_Alpha;
|
||||
|
||||
BlendOp[0] = Add;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
float ShadowVisibility_hwPCF(Texture2D ShadowMap, float4 vLightClip, float2 vShadowMapSize, float bias)
|
||||
{
|
||||
float2 uv = float2(vLightClip.x / vLightClip.w, -vLightClip.y / vLightClip.w) * 0.5f + 0.5f;
|
||||
float fDepthCenter = saturate(vLightClip.z / vLightClip.w);
|
||||
float2 vTexel = 1.f / vShadowMapSize;
|
||||
|
||||
float fVisibility = 0.f;
|
||||
for (int v = -1; v <= 1; ++v)
|
||||
{
|
||||
for (int u = -1; u <= 1; ++u)
|
||||
{
|
||||
float2 vOffset = float2(u, v) * vTexel;
|
||||
float fDepth = ShadowMap.Sample(DefaultSampler, uv + vOffset).x;
|
||||
fVisibility += (fDepthCenter - bias > fDepth) ? 0.f : 1.f;
|
||||
}
|
||||
}
|
||||
return fVisibility / 9.f;
|
||||
}
|
||||
|
||||
float GetRimLight(float3 vCamPosition, float3 vPosition, float3 vNormal, float fRimPower, float fRimStrength)
|
||||
{
|
||||
float fRimLight = (1 - dot(normalize(vCamPosition - vPosition), vNormal));
|
||||
fRimLight = pow(fRimLight, fRimPower);
|
||||
fRimLight = fRimLight * fRimStrength;
|
||||
return fRimLight;
|
||||
}
|
||||
|
||||
float2 Get_MovedUV(float2 vOriginalUV, float fDeltaU, float fDeltaV, uint iIndexU, uint iIndexV)
|
||||
{
|
||||
float2 vDelta = float2(fDeltaU, fDeltaV);
|
||||
float2 vOffset = float2(iIndexU * fDeltaU, iIndexV * fDeltaV);
|
||||
return vOriginalUV * vDelta + vOffset;
|
||||
}
|
||||
|
||||
float2 UV_Cutting(float2 vUV, float2 vUVCutting, int iCurrentFrame)
|
||||
{
|
||||
float2 UV = vUV; // 이미지의 UV값
|
||||
|
||||
int iTotalFrame = vUVCutting.x * vUVCutting.y; // 이미지의 최대 프레임 (몇 곱하기 몇인지)
|
||||
|
||||
int iFrameX = iCurrentFrame % (int) vUVCutting.x; // 현재 x축의 위치(현재 이미지의 몇번째 칸을 보여줄 지)
|
||||
int iFrameY = iCurrentFrame / (int) vUVCutting.x; // 현재 y축의 위치(현재 이미지의 몇번째 줄을 보여줄 지)
|
||||
|
||||
float fFreamWidth = 1.0 / vUVCutting.x; // 1.0 나누기 이미지 갯수를 해서 한칸에 얼마나 갈지 정해준다.
|
||||
float fFreamHeight = 1.0 / vUVCutting.y; // 1.0 나누기 이미지 갯수를 해서 한줄에 얼마나 갈지 정해준다.
|
||||
|
||||
UV.x = UV.x * fFreamWidth + iFrameX * fFreamWidth; // 먼저 uv를 0~1이 아닌 0~fFrameWidth로 만든 다음에 한칸씩 옆으로 밀어준다.
|
||||
UV.y = UV.y * fFreamHeight + iFrameY * fFreamHeight; // 먼저 uv를 0~1이 아닌 0~fFrameHeight로 만든 다음에 한줄씩 밑으로 내려준다.
|
||||
|
||||
return UV;
|
||||
}
|
||||
|
||||
struct PBR_LIGHT_OUT
|
||||
{
|
||||
float3 vShade;
|
||||
float3 vSpecular;
|
||||
};
|
||||
|
||||
// (Kd F(Lambert)) + (Ks F(cook-torrance))
|
||||
|
||||
//float LambertDiffuse(float c)
|
||||
//{
|
||||
// return c / PI;
|
||||
//}
|
||||
|
||||
// F(cook-torrance)
|
||||
// DFG / (4 (Wo dot N) (Wi dot N))
|
||||
|
||||
// D(distribution, NormalDistribution function), 표면의 거칠기에 영향을 받는 halfWay vector
|
||||
// G(Geometry, GeometryFunc), 에너지 보존법칙 적용
|
||||
// F(Fresnel-Fresnel equation), 표면 각도에 따른 반사율
|
||||
|
||||
// F->D
|
||||
float NDF_ggxtr(float3 vNormal, float3 vHalfWayVector, float fAlpha) // NormalDistributionGGXTR, (H, halfWay vector), (A, Roughness), (N, Normal)
|
||||
{
|
||||
float a2 = fAlpha * fAlpha;
|
||||
float NdotH = saturate(dot(vNormal, vHalfWayVector));
|
||||
float NdotH2 = NdotH * NdotH;
|
||||
|
||||
float nom = a2;
|
||||
float denom = (NdotH2 * (a2 - 1.f) + 1.f);
|
||||
|
||||
denom = PI * denom * denom;
|
||||
return (nom / denom);
|
||||
}
|
||||
|
||||
// F->G
|
||||
// GschlickGGX(n, v, k)
|
||||
// k는 이하 두개 조명 조건에 따라 가변적임
|
||||
// Direct // Kdir -> ((a + 1) * (a + 1)) / 8 // direct lighting 추천
|
||||
// IBL Lighting // Kibl -> a * a / 2 // 이미지 기반 조명기법
|
||||
|
||||
float Geometry_SchlickGGX(float NdotV, float fK)
|
||||
{
|
||||
return NdotV / (NdotV * (1.0f - fK) + fK);
|
||||
}
|
||||
|
||||
float Geometry_Smith(float3 vNormal, float3 vFromView, float3 vFromLight, float k)
|
||||
{
|
||||
// Geometry Obstruction
|
||||
// 철이 있는, 주로 튀어나온 장애물
|
||||
float NdotV = saturate(dot(vNormal, vFromView));
|
||||
|
||||
// Geometry Shadowing
|
||||
// 요가 있는, 주로 음푹 들어간 장애물 (그래서 셰도잉)
|
||||
float NdotL = saturate(dot(vNormal, vFromLight));
|
||||
|
||||
// 요철이 골고루 있다고 가정하고 적당히 섞음
|
||||
return Geometry_SchlickGGX(NdotV, k) * Geometry_SchlickGGX(NdotL, k);
|
||||
}
|
||||
|
||||
// F -> F
|
||||
float3 Fresnel_Schlick(float cosTheta, float3 F0)
|
||||
{
|
||||
// 모서리 부분의 반사
|
||||
return F0 + (1.0f - F0) * pow(1.0f - cosTheta, 5.0f);
|
||||
}
|
||||
|
||||
PBR_LIGHT_OUT PBR_Lighting(
|
||||
float3 vNormal, float3 vFromView, float3 vFromLight,
|
||||
float3 vAlbedo, float fMetallic, float fRoughness,
|
||||
float3 vLightColor, float fAttenuation, float3 vFO
|
||||
) {
|
||||
PBR_LIGHT_OUT Out;
|
||||
Out.vShade = 0;
|
||||
Out.vSpecular = 0;
|
||||
|
||||
float3 vHalfVector = normalize(vFromView + vFromLight);
|
||||
float NdotL = saturate(dot(vNormal, vFromLight));
|
||||
float NdotV = saturate(dot(vNormal, vFromView));
|
||||
if (NdotL <= 0 || NdotV <= 0)
|
||||
{
|
||||
return Out;
|
||||
}
|
||||
float fAlpha = max(fRoughness * fRoughness, 0.04f);
|
||||
float k = ((fRoughness + 1.f) * (fRoughness + 1.f)) / 8.f;
|
||||
|
||||
float D = NDF_ggxtr(vNormal, vHalfVector, fAlpha);
|
||||
float G = Geometry_Smith(vNormal, vFromView, vFromLight, k);
|
||||
float3 F = Fresnel_Schlick(saturate(dot(vHalfVector, vFromView)), vFO);
|
||||
|
||||
float3 vNumerator = D * G * F;
|
||||
float fDenom = max(4.f * NdotL * NdotV, 1e-7);
|
||||
float3 specularBRDF = vNumerator / fDenom;
|
||||
|
||||
float3 kS = F;
|
||||
float3 kD = (1.f - kS) * (1.f -fMetallic);
|
||||
|
||||
//Out.vShade = float(1.f, 1.f, 1. 1.f);
|
||||
Out.vShade = (kD / PI) * (NdotL * fAttenuation) * vLightColor;
|
||||
|
||||
Out.vSpecular = specularBRDF * vLightColor * fAttenuation * NdotL;
|
||||
|
||||
return Out;
|
||||
}
|
||||
#endif // ENGINE_SHADER_DEFINES_HLSLI
|
||||
|
||||
@@ -0,0 +1,184 @@
|
||||
#ifndef ENGINE_SHADER_FUNCTIONS_HLSLI
|
||||
#define ENGINE_SHADER_FUNCTIONS_HLSLI
|
||||
|
||||
#include "Engine_Shader_Constants.hlsli"
|
||||
#include "Engine_Shader_Structures.hlsli"
|
||||
#include "Engine_Shader_Samplers.hlsli"
|
||||
|
||||
bool AlmostEqual7(float fA, float fB)
|
||||
{
|
||||
return abs(fA - fB) < FLT_EPSILON7;
|
||||
}
|
||||
bool AlmostEqual5(float fA, float fB)
|
||||
{
|
||||
return abs(fA - fB) < FLT_EPSILON5;
|
||||
}
|
||||
bool AlmostEqual3(float fA, float fB)
|
||||
{
|
||||
return abs(fA - fB) < FLT_EPSILON3;
|
||||
}
|
||||
|
||||
float ShadowVisibility_hwPCF(Texture2D ShadowMap, float4 vLightClip, float2 vShadowMapSize, float bias)
|
||||
{
|
||||
float2 uv = float2(vLightClip.x / vLightClip.w, -vLightClip.y / vLightClip.w) * 0.5f + 0.5f;
|
||||
float fDepthCenter = saturate(vLightClip.z / vLightClip.w);
|
||||
float2 vTexel = 1.f / vShadowMapSize;
|
||||
|
||||
float fVisibility = 0.f;
|
||||
for (int v = -1; v <= 1; ++v)
|
||||
{
|
||||
for (int u = -1; u <= 1; ++u)
|
||||
{
|
||||
float2 vOffset = float2(u, v) * vTexel;
|
||||
float fDepth = ShadowMap.Sample(DefaultSampler, uv + vOffset).x;
|
||||
fVisibility += (fDepthCenter - bias > fDepth) ? 0.f : 1.f;
|
||||
}
|
||||
}
|
||||
return fVisibility / 9.f;
|
||||
}
|
||||
|
||||
float GetRimLight(float3 vCamPosition, float3 vPosition, float3 vNormal, float fRimPower, float fRimStrength)
|
||||
{
|
||||
float fRimLight = (1 - dot(normalize(vCamPosition - vPosition), vNormal));
|
||||
fRimLight = pow(fRimLight, fRimPower);
|
||||
fRimLight = fRimLight * fRimStrength;
|
||||
return fRimLight;
|
||||
}
|
||||
|
||||
float2 Get_MovedUV(float2 vOriginalUV, float fDeltaU, float fDeltaV, uint iIndexU, uint iIndexV)
|
||||
{
|
||||
float2 vDelta = float2(fDeltaU, fDeltaV);
|
||||
float2 vOffset = float2(iIndexU * fDeltaU, iIndexV * fDeltaV);
|
||||
return vOriginalUV * vDelta + vOffset;
|
||||
}
|
||||
|
||||
float2 UV_Cutting(float2 vUV, float2 vUVCutting, int iCurrentFrame)
|
||||
{
|
||||
float2 UV = vUV; // 이미지의 UV값
|
||||
|
||||
int iTotalFrame = vUVCutting.x * vUVCutting.y; // 이미지의 최대 프레임 (몇 곱하기 몇인지)
|
||||
|
||||
int iFrameX = iCurrentFrame % (int) vUVCutting.x; // 현재 x축의 위치(현재 이미지의 몇번째 칸을 보여줄 지)
|
||||
int iFrameY = iCurrentFrame / (int) vUVCutting.x; // 현재 y축의 위치(현재 이미지의 몇번째 줄을 보여줄 지)
|
||||
|
||||
float fFreamWidth = 1.0 / vUVCutting.x; // 1.0 나누기 이미지 갯수를 해서 한칸에 얼마나 갈지 정해준다.
|
||||
float fFreamHeight = 1.0 / vUVCutting.y; // 1.0 나누기 이미지 갯수를 해서 한줄에 얼마나 갈지 정해준다.
|
||||
|
||||
UV.x = UV.x * fFreamWidth + iFrameX * fFreamWidth; // 먼저 uv를 0~1이 아닌 0~fFrameWidth로 만든 다음에 한칸씩 옆으로 밀어준다.
|
||||
UV.y = UV.y * fFreamHeight + iFrameY * fFreamHeight; // 먼저 uv를 0~1이 아닌 0~fFrameHeight로 만든 다음에 한줄씩 밑으로 내려준다.
|
||||
|
||||
return UV;
|
||||
}
|
||||
|
||||
// (Kd F(Lambert)) + (Ks F(cook-torrance))
|
||||
|
||||
//float LambertDiffuse(float c)
|
||||
//{
|
||||
// return c / PI;
|
||||
//}
|
||||
|
||||
// F(cook-torrance)
|
||||
// DFG / (4 (Wo dot N) (Wi dot N))
|
||||
|
||||
// D(distribution, NormalDistribution function), 표면의 거칠기에 영향을 받는 halfWay vector
|
||||
// G(Geometry, GeometryFunc), 에너지 보존법칙 적용
|
||||
// F(Fresnel-Fresnel equation), 표면 각도에 따른 반사율
|
||||
|
||||
// F->D
|
||||
float NDF_ggxtr(float3 vNormal, float3 vHalfWayVector, float fAlpha) // NormalDistributionGGXTR, (H, halfWay vector), (A, Roughness), (N, Normal)
|
||||
{
|
||||
float a2 = fAlpha * fAlpha;
|
||||
float NdotH = saturate(dot(vNormal, vHalfWayVector));
|
||||
float NdotH2 = NdotH * NdotH;
|
||||
|
||||
float nom = a2;
|
||||
float denom = (NdotH2 * (a2 - 1.f) + 1.f);
|
||||
|
||||
denom = PI * denom * denom;
|
||||
return (nom / denom);
|
||||
}
|
||||
|
||||
// F->G
|
||||
// GschlickGGX(n, v, k)
|
||||
// k는 이하 두개 조명 조건에 따라 가변적임
|
||||
// Direct // Kdir -> ((a + 1) * (a + 1)) / 8 // direct lighting 추천
|
||||
// IBL Lighting // Kibl -> a * a / 2 // 이미지 기반 조명기법
|
||||
|
||||
float Geometry_SchlickGGX(float NdotV, float fK)
|
||||
{
|
||||
return NdotV / (NdotV * (1.0f - fK) + fK);
|
||||
}
|
||||
|
||||
float Geometry_Smith(float3 vNormal, float3 vFromView, float3 vFromLight, float k)
|
||||
{
|
||||
// Geometry Obstruction
|
||||
// 철이 있는, 주로 튀어나온 장애물
|
||||
float NdotV = saturate(dot(vNormal, vFromView));
|
||||
|
||||
// Geometry Shadowing
|
||||
// 요가 있는, 주로 음푹 들어간 장애물 (그래서 셰도잉)
|
||||
float NdotL = saturate(dot(vNormal, vFromLight));
|
||||
|
||||
// 요철이 골고루 있다고 가정하고 적당히 섞음
|
||||
return Geometry_SchlickGGX(NdotV, k) * Geometry_SchlickGGX(NdotL, k);
|
||||
}
|
||||
|
||||
// F -> F
|
||||
float3 Fresnel_Schlick(float cosTheta, float3 F0)
|
||||
{
|
||||
// 모서리 부분의 반사
|
||||
return F0 + (1.0f - F0) * pow(1.0f - cosTheta, 5.0f);
|
||||
}
|
||||
|
||||
PBR_LIGHT_OUT PBR_Lighting(
|
||||
float3 vNormal, float3 vFromView, float3 vFromLight,
|
||||
float3 vAlbedo, float fMetallic, float fRoughness,
|
||||
float3 vLightColor, float fAttenuation, float3 vFO
|
||||
) {
|
||||
PBR_LIGHT_OUT Out;
|
||||
Out.vShade = 0;
|
||||
Out.vSpecular = 0;
|
||||
|
||||
float3 vHalfVector = normalize(vFromView + vFromLight);
|
||||
float NdotL = saturate(dot(vNormal, vFromLight));
|
||||
float NdotV = saturate(dot(vNormal, vFromView));
|
||||
if (NdotL <= 0 || NdotV <= 0)
|
||||
{
|
||||
return Out;
|
||||
}
|
||||
float fAlpha = max(fRoughness * fRoughness, 0.04f);
|
||||
float k = ((fRoughness + 1.f) * (fRoughness + 1.f)) / 8.f;
|
||||
|
||||
float D = NDF_ggxtr(vNormal, vHalfVector, fAlpha);
|
||||
float G = Geometry_Smith(vNormal, vFromView, vFromLight, k);
|
||||
float3 F = Fresnel_Schlick(saturate(dot(vHalfVector, vFromView)), vFO);
|
||||
|
||||
float3 vNumerator = D * G * F;
|
||||
float fDenom = max(4.f * NdotL * NdotV, 1e-7);
|
||||
float3 specularBRDF = vNumerator / fDenom;
|
||||
|
||||
float3 kS = F;
|
||||
float3 kD = (1.f - kS) * (1.f -fMetallic);
|
||||
|
||||
//Out.vShade = float(1.f, 1.f, 1. 1.f);
|
||||
Out.vShade = (kD / PI) * (NdotL * fAttenuation) * vLightColor;
|
||||
|
||||
Out.vSpecular = specularBRDF * vLightColor * fAttenuation * NdotL;
|
||||
|
||||
return Out;
|
||||
}
|
||||
|
||||
float3 DecodeNormalFromRG(Texture2D NormalMap, SamplerState Samp, float2 uv)
|
||||
{
|
||||
float2 vSampledRG = (NormalMap.Sample(Samp, uv).rg * 2.f - 1.f);
|
||||
|
||||
float z2 = 1.0f - saturate(dot(vSampledRG, vSampledRG));
|
||||
float z = sqrt(max(z2, 0.0f));
|
||||
|
||||
float3 n = float3(vSampledRG, z);
|
||||
|
||||
return normalize(n);
|
||||
}
|
||||
|
||||
|
||||
#endif // ENGINE_SHADER_FUNCTIONS_HLSLI
|
||||
@@ -0,0 +1,40 @@
|
||||
#ifndef ENGINE_SHADER_SAMPLERS_HLSLI
|
||||
#define ENGINE_SHADER_SAMPLERS_HLSLI
|
||||
|
||||
sampler DefaultSampler = sampler_state
|
||||
{
|
||||
Filter = MIN_MAG_MIP_LINEAR;
|
||||
AddressU = wrap;
|
||||
AddressV = wrap;
|
||||
};
|
||||
|
||||
sampler ClampSampler = sampler_state
|
||||
{
|
||||
Filter = MIN_MAG_MIP_POINT;
|
||||
AddressU = clamp;
|
||||
AddressV = clamp;
|
||||
};
|
||||
|
||||
sampler MirrorSampler = sampler_state
|
||||
{
|
||||
Filter = MIN_MAG_MIP_LINEAR;
|
||||
AddressU = mirror;
|
||||
AddressV = mirror;
|
||||
};
|
||||
|
||||
sampler BorderZeroSampler = sampler_state
|
||||
{
|
||||
Filter = MIN_MAG_MIP_POINT;
|
||||
AddressU = Border;
|
||||
AddressV = Border;
|
||||
BorderColor = float4(0, 0, 0, 0);
|
||||
};
|
||||
|
||||
sampler PointSampler = sampler_state
|
||||
{
|
||||
Filter = MIN_MAG_MIP_POINT;
|
||||
AddressU = wrap;
|
||||
AddressV = wrap;
|
||||
};
|
||||
|
||||
#endif // ENGINE_SHADER_SAMPLERS_HLSLI
|
||||
@@ -0,0 +1,168 @@
|
||||
#ifndef ENGINE_SHADER_STATES_HLSLI
|
||||
#define ENGINE_SHADER_STATES_HLSLI
|
||||
|
||||
RasterizerState RS_Default
|
||||
{
|
||||
FillMode = Solid;
|
||||
CullMode = Back;
|
||||
};
|
||||
|
||||
RasterizerState RS_Nocull
|
||||
{
|
||||
FillMode = Solid;
|
||||
CullMode = None;
|
||||
FrontCounterClockwise = false;
|
||||
DepthClipEnable = false;
|
||||
};
|
||||
|
||||
RasterizerState RS_Nocull_Wireframe
|
||||
{
|
||||
FillMode = Wireframe;
|
||||
CullMode = None;
|
||||
FrontCounterClockwise = false;
|
||||
DepthBias = 0;
|
||||
SlopeScaledDepthBias = 0.f;
|
||||
DepthBiasClamp = 0.f;
|
||||
DepthClipEnable = false;
|
||||
ScissorEnable = false;
|
||||
MultisampleEnable = false;
|
||||
AntialiasedLineEnable = false;
|
||||
};
|
||||
|
||||
RasterizerState RS_Scissor
|
||||
{
|
||||
FillMode = Solid;
|
||||
CullMode = Back;
|
||||
FrontCounterClockwise = false;
|
||||
ScissorEnable = true;
|
||||
};
|
||||
|
||||
DepthStencilState DSS_Default
|
||||
{
|
||||
DepthEnable = true;
|
||||
DepthWriteMask = all;
|
||||
DepthFunc = less_equal;
|
||||
};
|
||||
|
||||
DepthStencilState DSS_None
|
||||
{
|
||||
DepthEnable = false;
|
||||
DepthWriteMask = zero;
|
||||
};
|
||||
|
||||
DepthStencilState DSS_Effect
|
||||
{
|
||||
DepthEnable = true;
|
||||
DepthWriteMask = zero;
|
||||
DepthFunc = less_equal;
|
||||
StencilEnable = false;
|
||||
};
|
||||
|
||||
BlendState BS_None
|
||||
{
|
||||
BlendEnable[0] = false;
|
||||
};
|
||||
|
||||
BlendState BS_AlphaBlend // ALPHA_BLEND
|
||||
{
|
||||
BlendEnable[0] = true;
|
||||
BlendEnable[1] = true;
|
||||
BlendEnable[2] = true;
|
||||
BlendEnable[3] = true;
|
||||
BlendEnable[4] = true;
|
||||
BlendEnable[5] = true;
|
||||
BlendEnable[6] = true;
|
||||
BlendEnable[7] = true;
|
||||
|
||||
// Ac * Aa + Bc * (1 - Aa);
|
||||
SrcBlend = Src_Alpha;
|
||||
DestBlend = Inv_Src_Alpha;
|
||||
BlendOp = Add;
|
||||
};
|
||||
|
||||
BlendState BS_Blend // ADDITIVE_BLEND
|
||||
{
|
||||
BlendEnable[0] = true;
|
||||
BlendEnable[1] = true;
|
||||
BlendEnable[2] = true;
|
||||
BlendEnable[3] = true;
|
||||
BlendEnable[4] = true;
|
||||
BlendEnable[5] = true;
|
||||
BlendEnable[6] = true;
|
||||
BlendEnable[7] = true;
|
||||
|
||||
// Ac * (1) + Bc * (1);
|
||||
SrcBlend = one;
|
||||
DestBlend = one;
|
||||
BlendOp = Add;
|
||||
};
|
||||
|
||||
BlendState BS_UIBlend
|
||||
{
|
||||
BlendEnable[0] = true;
|
||||
BlendEnable[1] = true;
|
||||
BlendEnable[2] = true;
|
||||
BlendEnable[3] = true;
|
||||
BlendEnable[4] = true;
|
||||
BlendEnable[5] = true;
|
||||
BlendEnable[6] = true;
|
||||
BlendEnable[7] = true;
|
||||
|
||||
SrcBlend = Src_Alpha;
|
||||
DestBlend = Inv_Src_Alpha;
|
||||
BlendOp = Add;
|
||||
|
||||
SrcBlendAlpha = One;
|
||||
DestBlendAlpha = Zero;
|
||||
BlendOpAlpha = Add;
|
||||
|
||||
RenderTargetWriteMask[0] = 0x0F; // RGBA 모두 출력
|
||||
};
|
||||
|
||||
BlendState BS_WB_Acc
|
||||
{
|
||||
BlendEnable[0] = true;
|
||||
BlendEnable[1] = true;
|
||||
BlendEnable[2] = true;
|
||||
BlendEnable[3] = true;
|
||||
BlendEnable[4] = true;
|
||||
BlendEnable[5] = true;
|
||||
BlendEnable[6] = true;
|
||||
BlendEnable[7] = true;
|
||||
|
||||
SrcBlend[0] = one;
|
||||
DestBlend[0] = one;
|
||||
BlendOp[0] = Add;
|
||||
|
||||
SrcBlend[1] = Zero;
|
||||
DestBlend[1] = Inv_Src_Alpha;
|
||||
BlendOp[1] = Add;
|
||||
|
||||
|
||||
SrcBlend[2] = one;
|
||||
DestBlend[2] = one;
|
||||
BlendOp[2] = Add;
|
||||
};
|
||||
|
||||
BlendState BS_WeightBlend
|
||||
{
|
||||
BlendEnable[0] = true;
|
||||
BlendEnable[1] = true;
|
||||
BlendEnable[2] = true;
|
||||
BlendEnable[3] = true;
|
||||
BlendEnable[4] = true;
|
||||
BlendEnable[5] = true;
|
||||
BlendEnable[6] = true;
|
||||
BlendEnable[7] = true;
|
||||
|
||||
|
||||
SrcBlend[0] = Src_Alpha;
|
||||
DestBlend[0] = Inv_Src_Alpha;
|
||||
|
||||
BlendOp[0] = Add;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // ENGINE_SHADER_STATES_HLSLI
|
||||
@@ -0,0 +1,10 @@
|
||||
#ifndef ENGINE_SHADER_STRUCTURES_HLSLI
|
||||
#define ENGINE_SHADER_STRUCTURES_HLSLI
|
||||
|
||||
struct PBR_LIGHT_OUT
|
||||
{
|
||||
float3 vShade;
|
||||
float3 vSpecular;
|
||||
};
|
||||
|
||||
#endif // ENGINE_SHADER_STRUCTURES_HLSLI
|
||||
@@ -35,14 +35,13 @@ Texture2D g_BlurTexture;
|
||||
Texture2D g_BlurXTexture;
|
||||
Texture2D g_BlurWeightTexture;
|
||||
|
||||
Texture2D g_SurfaceTexture;
|
||||
|
||||
|
||||
vector g_vLightDiffuse;
|
||||
vector g_vLightAmbient;
|
||||
vector g_vLightSpecular;
|
||||
|
||||
|
||||
|
||||
struct VS_IN
|
||||
{
|
||||
float3 vPosition : POSITION;
|
||||
@@ -56,9 +55,9 @@ struct VS_OUT
|
||||
};
|
||||
VS_OUT VS_MAIN(VS_IN In)
|
||||
{
|
||||
VS_OUT Out;
|
||||
VS_OUT Out;
|
||||
|
||||
matrix matWV, matWVP;
|
||||
matrix matWV, matWVP;
|
||||
|
||||
matWV = mul(g_WorldMatrix, g_ViewMatrix);
|
||||
matWVP = mul(matWV, g_ProjMatrix);
|
||||
@@ -66,7 +65,7 @@ VS_OUT VS_MAIN(VS_IN In)
|
||||
Out.vPosition = mul(vector(In.vPosition, 1.f), matWVP);
|
||||
Out.vTexcoord = In.vTexcoord;
|
||||
|
||||
return Out;
|
||||
return Out;
|
||||
}
|
||||
|
||||
struct PS_IN
|
||||
@@ -99,41 +98,77 @@ PS_OUT_LIGHT PS_MAIN_DIRECTIONAL(PS_IN In)
|
||||
{
|
||||
PS_OUT_LIGHT Out;
|
||||
|
||||
vector vNormalDesc = g_NormalTexture.Sample(DefaultSampler, In.vTexcoord);
|
||||
float2 uv = In.vTexcoord;
|
||||
|
||||
float4 vNormal = vector(vNormalDesc.xyz * 2.f - 1.f, 0.0f);
|
||||
// float3 vNormal = normalize(g_NormalTexture.Sample(DefaultSampler, uv).xyz * 2.f - 1);
|
||||
float3 vNormal = DecodeNormalFromRG(g_NormalTexture, DefaultSampler, uv);
|
||||
|
||||
Out.vShade = g_vLightDiffuse * saturate(max(dot(normalize(g_vLightDir) * -1.f, vNormal), 0.f) + (g_vLightAmbient * g_vMtrlAmbient));
|
||||
float4 vDepth = g_DepthTexture.Sample(DefaultSampler, uv);
|
||||
|
||||
vector vDepthDesc = g_DepthTexture.Sample(DefaultSampler, In.vTexcoord);
|
||||
float fViewZ = vDepth.y * g_fFar;
|
||||
|
||||
float fViewZ = vDepthDesc.y * g_fFar;
|
||||
float4 vWorldPosition;
|
||||
{
|
||||
vWorldPosition.x = uv.x * 2 - 1;
|
||||
vWorldPosition.y = uv.y * -2 + 1;
|
||||
vWorldPosition.z = vDepth.x;
|
||||
vWorldPosition.w = 1.f;
|
||||
vWorldPosition *= fViewZ;
|
||||
vWorldPosition = mul(vWorldPosition, g_invmatProj);
|
||||
vWorldPosition = mul(vWorldPosition, g_invMatView);
|
||||
}
|
||||
|
||||
vector vPosition;
|
||||
float3 vF0;
|
||||
float fMetallic;
|
||||
float fRoughness;
|
||||
float fOcclusion;
|
||||
float fAttenuation;
|
||||
|
||||
{ // vDepthDesc과 vTexcoord.xy로부터 World Position의 추론
|
||||
/* 직육면체의 NDC */
|
||||
/* LocalPos * World * View * Proj * ( 1 / w ) */
|
||||
vPosition.x = In.vTexcoord.x * 2.f - 1.f;
|
||||
vPosition.y = In.vTexcoord.y * -2.f + 1.f;
|
||||
vPosition.z = vDepthDesc.x;
|
||||
vPosition.w = 1.f;
|
||||
float3 vWPos = vWorldPosition.xyz;
|
||||
float3 vFromView = normalize(vWPos - g_vCamPosition.xyz); // 카메라에서 픽셀로 가는 방향
|
||||
float3 vFromLight = normalize(g_vLightDir.xyz); // 라이트에서 오는 라이트 벡터
|
||||
|
||||
/* [* (1 / w)] 소거*/
|
||||
/* z나누기를 되돌림 */
|
||||
vPosition = vPosition * fViewZ;
|
||||
// vPosition.x = In.vTexcoord.x * 2.f - 1.f * Far;
|
||||
// vPosition.y = In.vTexcoord.y * -2.f + 1.f * Far;
|
||||
// vPosition.z = vDepthDesc.x * Far;
|
||||
// vPosition.w = Far;
|
||||
float3 vAlbedo = g_DiffuseTexture.Sample(DefaultSampler, uv).rgb;
|
||||
|
||||
vPosition = mul(vPosition, g_invmatProj);
|
||||
vPosition = mul(vPosition, g_invMatView);
|
||||
}
|
||||
vector vLook = vPosition - g_vCamPosition;
|
||||
vector vReflect = reflect(normalize(g_vLightDir), vNormal);
|
||||
if (true == AlmostEqual3(vDepth.b, AI_TEXTURE_TYPE_METALNESS)) // Metallic
|
||||
{
|
||||
float3 vMRO = g_SurfaceTexture.Sample(DefaultSampler, uv).rgb;
|
||||
fMetallic = vMRO.r;
|
||||
fRoughness = vMRO.g;
|
||||
fOcclusion = vMRO.b;
|
||||
|
||||
vF0 = lerp(float3(0.04f, 0.04f, 0.04f), vAlbedo, fMetallic);
|
||||
}
|
||||
else if (true == AlmostEqual3(vDepth.b, AI_TEXTURE_TYPE_SPECULAR)) // Specular
|
||||
{
|
||||
float3 vSRO = g_SurfaceTexture.Sample(DefaultSampler, uv).rgb;
|
||||
float3 vSpec = vSRO.r;
|
||||
|
||||
fMetallic = 0.f;
|
||||
fRoughness = vSRO.g;
|
||||
fOcclusion = vSRO.b;
|
||||
|
||||
|
||||
vF0 = vSpec.xxx;
|
||||
}
|
||||
else
|
||||
{
|
||||
fMetallic = 0.f;
|
||||
fRoughness = 0.5f;
|
||||
fOcclusion = 1.f;
|
||||
vF0 = float3(0.04f, 0.04f, 0.04f);
|
||||
}
|
||||
|
||||
Out.vSpecular = (g_vLightSpecular * g_vMtrlSpecular) * pow(max(dot(normalize(vLook) * -1.f, normalize(vReflect)), 0.f), 50.f);
|
||||
fAttenuation = 1.f;
|
||||
|
||||
float fDiffuseAOStrength = lerp(0.3f, 1.f, fOcclusion);
|
||||
|
||||
PBR_LIGHT_OUT PBR_Out = PBR_Lighting(vNormal, vFromView, vFromLight, vAlbedo, fMetallic, fRoughness, g_vLightDiffuse.rgb, fAttenuation, vF0);
|
||||
|
||||
PBR_Out.vShade *= fDiffuseAOStrength;
|
||||
|
||||
Out.vShade = float4(PBR_Out.vShade, 1.f);
|
||||
Out.vSpecular = float4(PBR_Out.vSpecular, 1.f);
|
||||
|
||||
return Out;
|
||||
}
|
||||
@@ -142,38 +177,81 @@ PS_OUT_LIGHT PS_MAIN_POINT(PS_IN In)
|
||||
{
|
||||
PS_OUT_LIGHT Out;
|
||||
|
||||
vector vNormalDesc = g_NormalTexture.Sample(DefaultSampler, In.vTexcoord);
|
||||
float2 uv = In.vTexcoord;
|
||||
|
||||
float4 vNormal = vector(vNormalDesc.xyz * 2.f - 1.f, 0.f);
|
||||
float3 vNormal = DecodeNormalFromRG(g_NormalTexture, DefaultSampler, uv);
|
||||
|
||||
vector vDepthDesc = g_DepthTexture.Sample(DefaultSampler, In.vTexcoord);
|
||||
float fViewZ = vDepthDesc.y * g_fFar;
|
||||
float4 vDepth = g_DepthTexture.Sample(DefaultSampler, uv);
|
||||
|
||||
vector vPosition;
|
||||
/* 0 ~ 1 에서 -1 ~ 1 */
|
||||
vPosition.x = In.vTexcoord.x * 2.f - 1.f;
|
||||
vPosition.y = In.vTexcoord.y * -2.f + 1.f;
|
||||
vPosition.z = vDepthDesc.x;
|
||||
vPosition.w = 1.f;
|
||||
vPosition = vPosition * fViewZ;
|
||||
vPosition = mul(vPosition, g_invmatProj);
|
||||
vPosition = mul(vPosition, g_invMatView);
|
||||
float fViewZ = vDepth.y * g_fFar;
|
||||
|
||||
vector vLightDir = vPosition - (g_vLightPos + g_vLightPosOffset);
|
||||
float fDistance = length(vLightDir);
|
||||
float fAttenuation = saturate((g_fLightRange - fDistance) / g_fLightRange);
|
||||
if (fAttenuation <= 0.f)
|
||||
float4 vWorldPosition;
|
||||
{
|
||||
discard;
|
||||
vWorldPosition.x = uv.x * 2 - 1;
|
||||
vWorldPosition.y = uv.y * -2 + 1;
|
||||
vWorldPosition.z = vDepth.x;
|
||||
vWorldPosition.w = 1.f;
|
||||
vWorldPosition *= fViewZ;
|
||||
vWorldPosition = mul(vWorldPosition, g_invmatProj);
|
||||
vWorldPosition = mul(vWorldPosition, g_invMatView);
|
||||
}
|
||||
vLightDir = normalize(vLightDir);
|
||||
|
||||
Out.vShade = fAttenuation * (g_vLightDiffuse * saturate(max(dot(vLightDir * -1.f, vNormal), 0.f) + (g_vLightAmbient * g_vMtrlAmbient)));
|
||||
float3 vWPos = vWorldPosition.xyz;
|
||||
float3 vFromView = normalize(vWPos - g_vCamPosition.xyz); // 카메라에서 픽셀로 가는 방향
|
||||
float3 vFromLight = normalize(g_vLightDir.xyz); // 라이트에서 오는 라이트 벡터
|
||||
|
||||
vector vLook = vPosition - g_vCamPosition;
|
||||
vector vReflect = reflect(vLightDir, vNormal);
|
||||
float3 vF0;
|
||||
float fMetallic;
|
||||
float fRoughness;
|
||||
float fOcclusion;
|
||||
float fAttenuation;
|
||||
|
||||
Out.vSpecular = fAttenuation * ((g_vLightSpecular * g_vMtrlSpecular) * pow(max(dot(normalize(vLook) * -1.f, normalize(vReflect)), 0.f), 50.f));
|
||||
{
|
||||
float fDistance = length(vFromLight);
|
||||
fAttenuation = saturate((g_fLightRange - fDistance) / g_fLightRange);
|
||||
if (fAttenuation <= 0.f)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
}
|
||||
|
||||
float3 vAlbedo = g_DiffuseTexture.Sample(DefaultSampler, uv).rgb;
|
||||
|
||||
if (true == AlmostEqual3(vDepth.b, AI_TEXTURE_TYPE_METALNESS)) // Metallic
|
||||
{
|
||||
float3 vMRO = g_SurfaceTexture.Sample(DefaultSampler, uv).rgb;
|
||||
fMetallic = vMRO.r;
|
||||
fRoughness = vMRO.g;
|
||||
fOcclusion = vMRO.b;
|
||||
|
||||
vF0 = lerp(float3(0.04f, 0.04f, 0.04f), vAlbedo, fMetallic);
|
||||
}
|
||||
else if (true == AlmostEqual3(vDepth.b, AI_TEXTURE_TYPE_SPECULAR)) // Specular
|
||||
{
|
||||
float3 vSRO = g_SurfaceTexture.Sample(DefaultSampler, uv).rgb;
|
||||
float3 vSpec = vSRO.r;
|
||||
|
||||
fMetallic = 0.f;
|
||||
fRoughness = vSRO.g;
|
||||
fOcclusion = vSRO.b;
|
||||
|
||||
|
||||
vF0 = vSpec.xxx;
|
||||
}
|
||||
else
|
||||
{
|
||||
fMetallic = 0.f;
|
||||
fRoughness = 0.5f;
|
||||
fOcclusion = 1.f;
|
||||
vF0 = float3(0.04f, 0.04f, 0.04f);
|
||||
}
|
||||
|
||||
PBR_LIGHT_OUT PBR_Out = PBR_Lighting(vNormal, vFromView, vFromLight,
|
||||
vAlbedo, fMetallic, fRoughness,
|
||||
g_vLightDiffuse.rgb, fAttenuation, vF0);
|
||||
|
||||
Out.vShade = float4(PBR_Out.vShade, 1.f);
|
||||
Out.vSpecular = float4(PBR_Out.vSpecular, 1.f);
|
||||
|
||||
return Out;
|
||||
}
|
||||
@@ -182,46 +260,85 @@ PS_OUT_LIGHT PS_MAIN_SPOT(PS_IN In)
|
||||
{
|
||||
PS_OUT_LIGHT Out;
|
||||
|
||||
vector vNormalDesc = g_NormalTexture.Sample(DefaultSampler, In.vTexcoord);
|
||||
float2 uv = In.vTexcoord;
|
||||
|
||||
float4 vNormal = vector(vNormalDesc.xyz * 2.f - 1.f, 0.f);
|
||||
float3 vNormal = DecodeNormalFromRG(g_NormalTexture, DefaultSampler, uv);
|
||||
|
||||
vector vDepthDesc = g_DepthTexture.Sample(DefaultSampler, In.vTexcoord);
|
||||
float fViewZ = vDepthDesc.y * g_fFar;
|
||||
float4 vDepth = g_DepthTexture.Sample(DefaultSampler, uv);
|
||||
|
||||
vector vPosition;
|
||||
/* 0 ~ 1 에서 -1 ~ 1 */
|
||||
vPosition.x = In.vTexcoord.x * 2.f - 1.f;
|
||||
vPosition.y = In.vTexcoord.y * -2.f + 1.f;
|
||||
vPosition.z = vDepthDesc.x;
|
||||
vPosition.w = 1.f;
|
||||
vPosition = vPosition * fViewZ;
|
||||
vPosition = mul(vPosition, g_invmatProj);
|
||||
vPosition = mul(vPosition, g_invMatView);
|
||||
float fViewZ = vDepth.y * g_fFar;
|
||||
|
||||
vector vLightDir = vPosition - g_vLightPos;
|
||||
float fDistance = length(vLightDir);
|
||||
float fAttenuation = saturate((g_fLightRange - fDistance) / g_fLightRange);
|
||||
if (fAttenuation <= 0.f)
|
||||
float4 vWorldPosition;
|
||||
{
|
||||
discard;
|
||||
vWorldPosition.x = uv.x * 2 - 1;
|
||||
vWorldPosition.y = uv.y * -2 + 1;
|
||||
vWorldPosition.z = vDepth.x;
|
||||
vWorldPosition.w = 1.f;
|
||||
vWorldPosition *= fViewZ;
|
||||
vWorldPosition = mul(vWorldPosition, g_invmatProj);
|
||||
vWorldPosition = mul(vWorldPosition, g_invMatView);
|
||||
}
|
||||
vLightDir = normalize(vLightDir);
|
||||
vector vSpotDir = normalize(g_vLightDir);
|
||||
float fCosAngle = dot(vLightDir, vSpotDir);
|
||||
|
||||
float3 vWPos = vWorldPosition.xyz;
|
||||
float3 vFromView = normalize(vWPos - g_vCamPosition.xyz); // 카메라에서 픽셀로 가는 방향
|
||||
float3 vFromLight = normalize(g_vLightDir.xyz); // 라이트에서 오는 라이트 벡터
|
||||
|
||||
float3 vF0;
|
||||
float fMetallic;
|
||||
float fRoughness;
|
||||
float fOcclusion;
|
||||
float fAttenuation;
|
||||
{
|
||||
float fDistance = length(vFromLight);
|
||||
fAttenuation = saturate((g_fLightRange - fDistance) / g_fLightRange);
|
||||
if (fAttenuation <= 0.f)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
}
|
||||
float fCosAngle = dot(vFromLight, g_vLightDir.xyz);
|
||||
if (fCosAngle < g_fSpotOuterAngle)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
float fSpotAttenenuation = saturate((fCosAngle - g_fSpotInnerAngle) / (g_fSpotInnerAngle - g_fSpotOuterAngle));
|
||||
float fSpotAttenenuation = saturate((fCosAngle - g_fSpotInnerAngle) / (g_fSpotInnerAngle - g_fSpotOuterAngle));
|
||||
fAttenuation *= fSpotAttenenuation;
|
||||
|
||||
Out.vShade = fAttenuation * (g_vLightDiffuse * saturate(max(dot(vLightDir * -1.f, vNormal), 0.f) + (g_vLightAmbient * g_vMtrlAmbient)));
|
||||
float3 vAlbedo = g_DiffuseTexture.Sample(DefaultSampler, uv).rgb;
|
||||
|
||||
vector vLook = vPosition - g_vCamPosition;
|
||||
vector vReflect = reflect(vLightDir, vNormal);
|
||||
if (true == AlmostEqual3(vDepth.b, AI_TEXTURE_TYPE_METALNESS)) // Metallic
|
||||
{
|
||||
float3 vMRO = g_SurfaceTexture.Sample(DefaultSampler, uv).rgb;
|
||||
fMetallic = vMRO.r;
|
||||
fRoughness = vMRO.g;
|
||||
fOcclusion = vMRO.b;
|
||||
|
||||
vF0 = lerp(float3(0.04f, 0.04f, 0.04f), vAlbedo, fMetallic);
|
||||
}
|
||||
else if (true == AlmostEqual3(vDepth.b, AI_TEXTURE_TYPE_SPECULAR)) // Specular
|
||||
{
|
||||
float3 vSRO = g_SurfaceTexture.Sample(DefaultSampler, uv).rgb;
|
||||
float3 vSpec = vSRO.r;
|
||||
|
||||
fMetallic = 0.f;
|
||||
fRoughness = vSRO.g;
|
||||
fOcclusion = vSRO.b;
|
||||
|
||||
|
||||
vF0 = vSpec.xxx;
|
||||
}
|
||||
else
|
||||
{
|
||||
fMetallic = 0.f;
|
||||
fRoughness = 0.5f;
|
||||
fOcclusion = 1.f;
|
||||
vF0 = float3(0.04f, 0.04f, 0.04f);
|
||||
}
|
||||
|
||||
Out.vSpecular = fAttenuation * ((g_vLightSpecular * g_vMtrlSpecular) * pow(max(dot(normalize(vLook) * -1.f, normalize(vReflect)), 0.f), 50.f));
|
||||
PBR_LIGHT_OUT PBR_Out = PBR_Lighting(vNormal, vFromView, vFromLight, vAlbedo, fMetallic, fRoughness, g_vLightDiffuse.rgb, fAttenuation, vF0);
|
||||
|
||||
Out.vShade = float4(PBR_Out.vShade, 1.f);
|
||||
Out.vSpecular = float4(PBR_Out.vSpecular, 1.f);
|
||||
|
||||
return Out;
|
||||
}
|
||||
@@ -271,107 +388,7 @@ PS_OUT_BACKBUFFER PS_MAIN_COMBINED(PS_IN In)
|
||||
vPosition = mul(vPosition, g_invmatProj);
|
||||
vPosition = mul(vPosition, g_invMatView);
|
||||
vPreShadowPosition = vPosition;
|
||||
/* (로컬위치 * 월드) -> (로컬위치 * 월드 * 광원의 뷰 * 광원의 투영 ) */
|
||||
vPosition = mul(vPosition, g_LightViewMatrix);
|
||||
vPosition = mul(vPosition, g_LightProjMatrix);
|
||||
vPreShadowPosition = mul(vPreShadowPosition, g_PreShadowLightViewMatrix);
|
||||
vPreShadowPosition = mul(vPreShadowPosition, g_PreShadowLightProjMatrix);
|
||||
|
||||
/* (로컬위치 * 월드 * 광원의 뷰 * 광원의 투영 ) -> (로컬위치 * 월드 * 광원의 뷰 * 광원의 투영 * (/w) */
|
||||
float2 vTexcoord, vPreShadowTexcoord;
|
||||
vTexcoord.x = (vPosition.x / vPosition.w) * 0.5f + 0.5f;
|
||||
vTexcoord.y = (vPosition.y / vPosition.w) * -0.5f + 0.5f;
|
||||
vPreShadowTexcoord.x = (vPreShadowPosition.x / vPreShadowPosition.w) * 0.5f + 0.5f;
|
||||
vPreShadowTexcoord.y = (vPreShadowPosition.y / vPreShadowPosition.w) * -0.5f + 0.5f;
|
||||
|
||||
/* 광원의 NDC에서 샘플링 */
|
||||
float fVisibility_Dynamic = ShadowVisibility_hwPCF(g_ShadowTexture, vPosition, float2(g_iMaxShadowWidth, g_iMaxShadowHeight), 0.0005f);
|
||||
float fVisibility_Static = ShadowVisibility_hwPCF(g_PreShadowTexture, vPreShadowPosition, float2(g_iMaxShadowWidth, g_iMaxShadowHeight), 0.0005f);
|
||||
|
||||
Out.vBackBuffer.rgb *= lerp(0.5f, 1.f, min(fVisibility_Dynamic, fVisibility_Static));
|
||||
//float fShadowDepth = g_ShadowTexture.Sample(DefaultSampler, vTexcoord).x;
|
||||
//float fPreShadowDepth = g_PreShadowTexture.Sample(DefaultSampler, vPreShadowTexcoord).x;
|
||||
//bool IsShadow = { false };
|
||||
//if (vPosition.z - 0.0005f > fShadowDepth)
|
||||
//{
|
||||
// IsShadow = true;
|
||||
//}
|
||||
//if (vPreShadowPosition.z - 0.0005f > fPreShadowDepth)
|
||||
//{
|
||||
// IsShadow = true;
|
||||
//}
|
||||
//if (true == IsShadow)
|
||||
//{
|
||||
// Out.vBackBuffer *= 0.5f;
|
||||
//}
|
||||
float4 vColor = 0.f;
|
||||
|
||||
//int iBlurWeight = g_BlurWeightTexture.Sample(ClampSampler, In.vTexcoord).r * 32.f;
|
||||
|
||||
//int iBlurMin;
|
||||
//int iBlurMax;
|
||||
|
||||
//if (iBlurWeight % 2 == 0)
|
||||
//{
|
||||
// iBlurMin = -1 * iBlurWeight / 2;
|
||||
// iBlurMax = iBlurWeight / 2;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// iBlurMin = -iBlurWeight / 2;
|
||||
// iBlurMax = iBlurWeight / 2 + 1;
|
||||
//}
|
||||
|
||||
//[loop] // 변수로 루프돌리려면 반드시 필요함
|
||||
for (int i = -15; i < 16; ++i)
|
||||
{
|
||||
vTexcoord.x = In.vTexcoord.x;
|
||||
vTexcoord.y = In.vTexcoord.y + (float) i / g_vResolution.y;
|
||||
|
||||
vColor += g_fWeights[i + 15] * g_BlurXTexture.Sample(ClampSampler, vTexcoord);
|
||||
}
|
||||
|
||||
Out.vBackBuffer += vColor;
|
||||
|
||||
return Out;
|
||||
}
|
||||
|
||||
PS_OUT_BACKBUFFER PS_MAIN_MROCOMBINED(PS_IN In)
|
||||
{
|
||||
PS_OUT_BACKBUFFER Out;
|
||||
|
||||
vector vDiffuse = g_DiffuseTexture.Sample(DefaultSampler, In.vTexcoord);
|
||||
|
||||
if (0.f == vDiffuse.a)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
|
||||
vector vShade = g_ShadeTexture.Sample(DefaultSampler, In.vTexcoord);
|
||||
|
||||
vector vSpecular = g_SpecularTexture.Sample(DefaultSampler, In.vTexcoord);
|
||||
|
||||
Out.vBackBuffer = vDiffuse * vShade + vSpecular;
|
||||
|
||||
vector vDepthDesc = g_DepthTexture.Sample(DefaultSampler, In.vTexcoord);
|
||||
|
||||
|
||||
float fViewZ = vDepthDesc.y * g_fFar;
|
||||
|
||||
|
||||
vector vPosition, vPreShadowPosition;
|
||||
|
||||
/* (로컬위치 * 월드 * 뷰 * 투영 / w) -> (로컬위치 * 월드) */
|
||||
vPosition.x = In.vTexcoord.x * 2.f - 1.f;
|
||||
vPosition.y = In.vTexcoord.y * -2.f + 1.f;
|
||||
vPosition.z = vDepthDesc.x;
|
||||
vPosition.w = 1.f;
|
||||
|
||||
vPosition = vPosition * fViewZ;
|
||||
|
||||
vPosition = mul(vPosition, g_invmatProj);
|
||||
vPosition = mul(vPosition, g_invMatView);
|
||||
vPreShadowPosition = vPosition;
|
||||
/* (로컬위치 * 월드) -> (로컬위치 * 월드 * 광원의 뷰 * 광원의 투영 ) */
|
||||
vPosition = mul(vPosition, g_LightViewMatrix);
|
||||
vPosition = mul(vPosition, g_LightProjMatrix);
|
||||
@@ -478,7 +495,7 @@ PS_OUT_BLUR_X PS_MAIN_BLUR_X(PS_IN In)
|
||||
vColor += g_fWeights[i + 15] * g_BlurTexture.Sample(ClampSampler, vTexcoord);
|
||||
}
|
||||
|
||||
Out.vBlurX = vColor;
|
||||
Out.vBlurX = vColor;
|
||||
|
||||
return Out;
|
||||
}
|
||||
@@ -486,7 +503,7 @@ PS_OUT_BLUR_X PS_MAIN_BLUR_X(PS_IN In)
|
||||
|
||||
technique11 DefaultTechnique
|
||||
{
|
||||
pass DebugPass
|
||||
pass DebugPass // 0
|
||||
{
|
||||
SetRasterizerState(RS_Default);
|
||||
SetDepthStencilState(DSS_Default, 0);
|
||||
@@ -496,7 +513,7 @@ technique11 DefaultTechnique
|
||||
PixelShader = compile ps_5_0 PS_MAIN_DEBUG();
|
||||
}
|
||||
|
||||
pass DirectionalPass
|
||||
pass DirectionalPass // 1
|
||||
{
|
||||
SetRasterizerState(RS_Default);
|
||||
SetDepthStencilState(DSS_None, 0);
|
||||
@@ -506,7 +523,7 @@ technique11 DefaultTechnique
|
||||
PixelShader = compile ps_5_0 PS_MAIN_DIRECTIONAL();
|
||||
}
|
||||
|
||||
pass PointPass
|
||||
pass PointPass // 2
|
||||
{
|
||||
SetRasterizerState(RS_Default);
|
||||
SetDepthStencilState(DSS_None, 0);
|
||||
@@ -516,7 +533,7 @@ technique11 DefaultTechnique
|
||||
PixelShader = compile ps_5_0 PS_MAIN_POINT();
|
||||
}
|
||||
|
||||
pass CombinedPass
|
||||
pass CombinedPass // 3
|
||||
{
|
||||
SetRasterizerState(RS_Default);
|
||||
SetDepthStencilState(DSS_None, 0);
|
||||
@@ -526,7 +543,7 @@ technique11 DefaultTechnique
|
||||
PixelShader = compile ps_5_0 PS_MAIN_COMBINED();
|
||||
}
|
||||
|
||||
pass BlurPass
|
||||
pass BlurPass // 4
|
||||
{
|
||||
SetRasterizerState(RS_Default);
|
||||
SetDepthStencilState(DSS_None, 0);
|
||||
@@ -536,7 +553,7 @@ technique11 DefaultTechnique
|
||||
PixelShader = compile ps_5_0 PS_MAIN_BLUR_X();
|
||||
}
|
||||
|
||||
pass SpotPass
|
||||
pass SpotPass // 5
|
||||
{
|
||||
SetRasterizerState(RS_Default);
|
||||
SetDepthStencilState(DSS_None, 0);
|
||||
@@ -545,13 +562,4 @@ technique11 DefaultTechnique
|
||||
GeometryShader = NULL;
|
||||
PixelShader = compile ps_5_0 PS_MAIN_SPOT();
|
||||
}
|
||||
pass MROCombinedPass
|
||||
{
|
||||
SetRasterizerState(RS_Default);
|
||||
SetDepthStencilState(DSS_None, 0);
|
||||
SetBlendState(BS_None, float4(0.f, 0.f, 0.f, 0.f), 0xffffffff);
|
||||
VertexShader = compile vs_5_0 VS_MAIN();
|
||||
GeometryShader = NULL;
|
||||
PixelShader = compile ps_5_0 PS_MAIN_MROCOMBINED();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ Texture2D g_DiffuseTexture;
|
||||
Texture2D g_NormalTexture;
|
||||
Texture2D g_DAOTexture;
|
||||
Texture2D g_THVTexture;
|
||||
Texture2D g_SurfaceParamsTexture;
|
||||
|
||||
float3 g_RootColor;
|
||||
float3 g_TipColor;
|
||||
@@ -25,6 +26,7 @@ float3 g_DyeColor;
|
||||
|
||||
float g_DyeOpacity;
|
||||
float g_HairRoughness;
|
||||
float g_fUsingSurfaceParams;
|
||||
|
||||
|
||||
matrix g_BoneMatrices[512];
|
||||
@@ -156,10 +158,10 @@ VS_OUT_SHADOW VS_MAIN_SHADOW(VS_IN In)
|
||||
|
||||
float fWeightW = 1.f - (In.vBlendWeight.x + In.vBlendWeight.y + In.vBlendWeight.z);
|
||||
|
||||
matrix BoneMatrix = g_BoneMatrices[In.vBlendIndex.x] * In.vBlendWeight.x +
|
||||
g_BoneMatrices[In.vBlendIndex.y] * In.vBlendWeight.y +
|
||||
g_BoneMatrices[In.vBlendIndex.z] * In.vBlendWeight.z +
|
||||
g_BoneMatrices[In.vBlendIndex.w] * fWeightW;
|
||||
matrix BoneMatrix = mul(g_BoneMatrices[In.vBlendIndex.x], In.vBlendWeight.x) +
|
||||
mul(g_BoneMatrices[In.vBlendIndex.y], In.vBlendWeight.y) +
|
||||
mul(g_BoneMatrices[In.vBlendIndex.z], In.vBlendWeight.z) +
|
||||
mul(g_BoneMatrices[In.vBlendIndex.w], fWeightW);
|
||||
|
||||
/* ?ㅽ궎??*/
|
||||
vector vPosition = mul(vector(In.vPosition, 1.f), BoneMatrix);
|
||||
@@ -188,9 +190,11 @@ struct PS_IN
|
||||
|
||||
struct PS_OUT
|
||||
{
|
||||
float4 vDiffuse : SV_TARGET0;
|
||||
float4 vAlbedo : SV_TARGET0;
|
||||
float4 vNormal : SV_TARGET1;
|
||||
float4 vDepth : SV_TARGET2;
|
||||
float4 vColor : SV_Target3;
|
||||
float4 vSurface : SV_Target4;
|
||||
};
|
||||
|
||||
PS_OUT PS_MAIN(PS_IN In)
|
||||
@@ -213,11 +217,14 @@ PS_OUT PS_MAIN(PS_IN In)
|
||||
float fRimLight = GetRimLight(g_vCamPosition.xyz, In.vWorldPos.xyz, vNormal, g_fRimPower, g_fRimStrength);
|
||||
vMtrlDiffuse.xyz = (vMtrlDiffuse.xyz * (1 - fRimLight)) + g_vRimColor * fRimLight;
|
||||
}
|
||||
vector vSurface = g_SurfaceParamsTexture.Sample(DefaultSampler, In.vTexcoord);
|
||||
|
||||
|
||||
Out.vDiffuse = vMtrlDiffuse;
|
||||
Out.vAlbedo = vMtrlDiffuse;
|
||||
Out.vNormal = float4(vNormal * 0.5f + 0.5f, 0.f);
|
||||
Out.vDepth = float4(In.vProjPos.z / In.vProjPos.w, In.vProjPos.w / g_fFar, 0.0f, 1.f);
|
||||
Out.vDepth = float4(In.vProjPos.z / In.vProjPos.w, In.vProjPos.w / g_fFar, g_fUsingSurfaceParams, 1.f);
|
||||
Out.vColor = float4(0.f, 0.f, 0.f, 1.f);
|
||||
Out.vSurface = vSurface;
|
||||
|
||||
|
||||
return Out;
|
||||
@@ -313,7 +320,7 @@ PS_OUT PS_HAIR(PS_IN In)
|
||||
baseColor = lerp(baseColor, g_vRimColor.rgb, fRim);
|
||||
}
|
||||
|
||||
Out.vDiffuse = float4(baseColor, alpha);
|
||||
Out.vAlbedo = float4(baseColor, alpha);
|
||||
Out.vNormal = float4(normal * 0.5f + 0.5f, 0.f);
|
||||
Out.vDepth = float4(In.vProjPos.z / In.vProjPos.w, In.vProjPos.w / g_fFar, 0.0f, 1.f);
|
||||
|
||||
@@ -342,7 +349,7 @@ PS_OUT PS_EYELASH(PS_IN In)
|
||||
}
|
||||
|
||||
|
||||
Out.vDiffuse = float4(vMtrlDiffuse.rgb, vMtrlDiffuse.g);
|
||||
Out.vAlbedo = float4(vMtrlDiffuse.rgb, vMtrlDiffuse.g);
|
||||
Out.vNormal = float4(vNormal * 0.5f + 0.5f, 0.f);
|
||||
Out.vDepth = float4(In.vProjPos.z / In.vProjPos.w, In.vProjPos.w / g_fFar, 0.0f, 1.f);
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ matrix g_WorldMatrix, g_ViewMatrix, g_ProjMatrix;
|
||||
|
||||
bool g_bUVTargetDiffuse;
|
||||
bool g_bAdditiveDisolve;
|
||||
|
||||
float g_LifeRatio;
|
||||
float g_fFar;
|
||||
float g_fTime;
|
||||
@@ -14,6 +15,7 @@ uint g_iIndexU;
|
||||
uint g_iIndexV;
|
||||
|
||||
float g_fDisolveRatio;
|
||||
float g_fUsingSurfaceParams;
|
||||
|
||||
float2 g_vClipBoxSize;
|
||||
float2 g_vClipBoxLTPos;
|
||||
@@ -24,7 +26,7 @@ Texture2D g_ClippingTexture;
|
||||
Texture2D g_DisolveTexture;
|
||||
Texture2D g_NormalTexture;
|
||||
Texture2D g_GlowTexture;
|
||||
Texture2D g_MROTexture;
|
||||
Texture2D g_SurfaceParamsTexture;
|
||||
|
||||
struct VS_IN
|
||||
{
|
||||
@@ -156,10 +158,11 @@ struct PS_IN
|
||||
|
||||
struct PS_OUT
|
||||
{
|
||||
float4 vDiffuse : SV_TARGET0;
|
||||
float4 vAlbedo : SV_TARGET0;
|
||||
float4 vNormal : SV_TARGET1;
|
||||
float4 vDepth : SV_TARGET2;
|
||||
|
||||
float4 vColor : SV_Target3;
|
||||
float4 vSurface : SV_Target4;
|
||||
};
|
||||
PS_OUT PS_MAIN(PS_IN In)
|
||||
{
|
||||
@@ -175,49 +178,17 @@ PS_OUT PS_MAIN(PS_IN In)
|
||||
float3x3 WorldMatrix = float3x3(In.vTangent, In.vBinormal * -1.f, In.vNormal);
|
||||
|
||||
float3 vNormal = mul(vNormalDesc.xyz * 2.f - 1.f, WorldMatrix);
|
||||
vector vSurface = g_SurfaceParamsTexture.Sample(DefaultSampler, In.vTexcoord);
|
||||
|
||||
Out.vDiffuse = vMtrlDiffuse;
|
||||
Out.vAlbedo = vMtrlDiffuse;
|
||||
Out.vNormal = float4(vNormal * 0.5f + 0.5f, 0.f);
|
||||
Out.vDepth = float4(In.vProjPos.z / In.vProjPos.w, In.vProjPos.w / g_fFar, 0.0f, 1.f);
|
||||
|
||||
return Out;
|
||||
}
|
||||
|
||||
struct PS_PROP_OUT
|
||||
{
|
||||
float4 vDiffuse : SV_TARGET0;
|
||||
float4 vNormal : SV_TARGET1;
|
||||
float4 vDepth : SV_TARGET2;
|
||||
float4 vColor : SV_Target3;
|
||||
float4 vMRO : SV_Target4;
|
||||
};
|
||||
|
||||
PS_PROP_OUT PS_PROP(PS_IN In)
|
||||
{
|
||||
PS_PROP_OUT Out;
|
||||
|
||||
vector vMtrlDiffuse = g_DiffuseTexture.Sample(DefaultSampler, In.vTexcoord);
|
||||
if (vMtrlDiffuse.a < 0.2f)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
|
||||
vector vNormalDesc = g_NormalTexture.Sample(MirrorSampler, In.vTexcoord);
|
||||
float3x3 WorldMatrix = float3x3(In.vTangent, In.vBinormal * -1.f, In.vNormal);
|
||||
|
||||
float3 vNormal = mul(vNormalDesc.xyz * 2.f - 1.f, WorldMatrix);
|
||||
|
||||
vector vMRO = g_MROTexture.Sample(DefaultSampler, In.vTexcoord);
|
||||
|
||||
|
||||
Out.vDiffuse = vMtrlDiffuse;
|
||||
Out.vNormal = float4(vNormal * 0.5f + 0.5f, 0.f);
|
||||
Out.vDepth = float4(In.vProjPos.z / In.vProjPos.w, In.vProjPos.w / g_fFar, 1, 1.f);
|
||||
Out.vDepth = float4(In.vProjPos.z / In.vProjPos.w, In.vProjPos.w / g_fFar, g_fUsingSurfaceParams, 1.f);
|
||||
Out.vColor = float4(0.f, 0.f, 0.f, 1.f);
|
||||
Out.vMRO = vMRO;
|
||||
Out.vSurface = vSurface;
|
||||
|
||||
return Out;
|
||||
}
|
||||
|
||||
PS_OUT PS_MAIN_SELECT(PS_IN In)
|
||||
{
|
||||
PS_OUT Out;
|
||||
@@ -233,7 +204,7 @@ PS_OUT PS_MAIN_SELECT(PS_IN In)
|
||||
|
||||
float3 vNormal = mul(vNormalDesc.xyz * 2.f - 1.f, WorldMatrix);
|
||||
|
||||
Out.vDiffuse = vMtrlDiffuse * float4(0.f, 1.f, 1.f, 0.3f);
|
||||
Out.vAlbedo = vMtrlDiffuse * float4(0.f, 1.f, 1.f, 0.3f);
|
||||
Out.vNormal = float4(vNormal * 0.5f + 0.5f, 0.f);
|
||||
Out.vDepth = float4(In.vProjPos.z / In.vProjPos.w, In.vProjPos.w / g_fFar, 0.0f, 1.f);
|
||||
return Out;
|
||||
@@ -250,7 +221,7 @@ PS_OUT PS_GLASS(PS_IN In)
|
||||
|
||||
float3 vNormal = mul(vNormalDesc.xyz * 2.f - 1.f, WorldMatrix);
|
||||
|
||||
Out.vDiffuse = lerp(vMtrlDiffuse, float4(1.f, 1.f, 1.f, 1.f), 0.5f);
|
||||
Out.vAlbedo = lerp(vMtrlDiffuse, float4(1.f, 1.f, 1.f, 1.f), 0.5f);
|
||||
float4(vMtrlDiffuse.xyz, 1.f);
|
||||
Out.vNormal = float4(vNormal * 0.5f + 0.5f, 0.f);
|
||||
Out.vDepth = float4(In.vProjPos.z / In.vProjPos.w, In.vProjPos.w / g_fFar, 0.0f, 1.f);
|
||||
@@ -516,22 +487,4 @@ technique11 MeshTechnique11
|
||||
GeometryShader = NULL;
|
||||
PixelShader = compile ps_5_0 PS_GLASS();
|
||||
}
|
||||
pass PropPass // 13
|
||||
{
|
||||
SetRasterizerState(RS_Default);
|
||||
SetDepthStencilState(DSS_Default, 0);
|
||||
SetBlendState(BS_None, float4(0.f, 0.f, 0.f, 0.f), 0xffffffff);
|
||||
VertexShader = compile vs_5_0 VS_MAIN();
|
||||
GeometryShader = NULL;
|
||||
PixelShader = compile ps_5_0 PS_PROP();
|
||||
}
|
||||
pass NoMROPropPass // 14
|
||||
{
|
||||
SetRasterizerState(RS_Default);
|
||||
SetDepthStencilState(DSS_Default, 0);
|
||||
SetBlendState(BS_None, float4(0.f, 0.f, 0.f, 0.f), 0xffffffff);
|
||||
VertexShader = compile vs_5_0 VS_MAIN();
|
||||
GeometryShader = NULL;
|
||||
PixelShader = compile ps_5_0 PS_MAIN();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,13 +63,9 @@ HRESULT CBroom::Render()
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom, "g_DiffuseTexture", aiTextureType_DIFFUSE, 0))) {
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom, "g_NormalTexture", aiTextureType_NORMALS, 0))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (FAILED(m_pShaderCom->Begin(ENUM_CLASS(SHADER_PASS_ANIM::DEFAULT)))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
@@ -72,10 +72,7 @@ HRESULT CDummyObject::Render()
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom, "g_DiffuseTexture", aiTextureType_DIFFUSE, 0))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom, "g_NormalTexture", aiTextureType_NORMALS, 0))) {
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
|
||||
@@ -59,10 +59,7 @@ HRESULT CDummySkyBox::Render()
|
||||
|
||||
for (_uint i = 0; i < iNumMeshes; i++)
|
||||
{
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom, "g_DiffuseTexture", aiTextureType_DIFFUSE, 0))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom, "g_NormalTexture", aiTextureType_NORMALS, 0))) {
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
|
||||
@@ -58,10 +58,7 @@ HRESULT CDummy_Cube::Render()
|
||||
|
||||
for (_uint i = 0; i < iNumMeshes; i++)
|
||||
{
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom, "g_DiffuseTexture", aiTextureType_DIFFUSE, 0))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom, "g_NormalTexture", aiTextureType_NORMALS, 0))) {
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
|
||||
@@ -58,27 +58,12 @@ HRESULT CDummy_Globe::Render()
|
||||
|
||||
for (_uint i = 0; i < iNumMeshes; i++)
|
||||
{
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom, "g_DiffuseTexture", aiTextureType_DIFFUSE, 0))) {
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom, "g_NormalTexture", aiTextureType_NORMALS, 0))) {
|
||||
if (FAILED(m_pShaderCom->Begin(ENUM_CLASS(SHADER_PASS_MESH::DEFAULT)))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom, "g_MROTexture", aiTextureType_SHININESS, 0))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (true == m_bMRO) {
|
||||
if (FAILED(m_pShaderCom->Begin(ENUM_CLASS(SHADER_PASS_MESH::PROP)))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (FAILED(m_pShaderCom->Begin(ENUM_CLASS(SHADER_PASS_MESH::NOMROPROP)))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
if (FAILED(m_pModelCom->Render(i))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
@@ -90,12 +75,13 @@ HRESULT CDummy_Globe::Render()
|
||||
|
||||
HRESULT CDummy_Globe::Ready_Components(void* pArg)
|
||||
{
|
||||
if (FAILED(__super::Ready_Components(pArg))) {
|
||||
if (FAILED(__super::Ready_Components(nullptr))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
GLOBE_DESC* pDesc = static_cast<GLOBE_DESC*>(pArg);
|
||||
|
||||
/* Com_Model */
|
||||
if (FAILED(__super::Add_Asset_Component(g_iStaticLevel, TEXT("Desc_Globe"),
|
||||
if (FAILED(__super::Add_Asset_Component(g_iStaticLevel, pDesc->wstrKey,
|
||||
reinterpret_cast<CComponent**>(&m_pModelCom)))){
|
||||
return E_FAIL;
|
||||
}
|
||||
@@ -105,7 +91,8 @@ HRESULT CDummy_Globe::Ready_Components(void* pArg)
|
||||
reinterpret_cast<CComponent**>(&m_pShaderCom)))){
|
||||
return E_FAIL;
|
||||
}
|
||||
m_bMRO = true;
|
||||
|
||||
m_pTransformCom->Set_State(STATE::POSITION, XMVectorSetW(XMLoadFloat3(&pDesc->vPos), 1.f));
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
@@ -124,6 +111,7 @@ HRESULT CDummy_Globe::Bind_ShaderResources()
|
||||
if (FAILED(m_pShaderCom->Bind_RawValue("g_fFar", m_pGameInstance->Get_CurrentCameraFar(), sizeof(_float)))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ HRESULT CDummy_PhysXBox::Render()
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (FAILED(m_pModelCom->Bind_Material(0, m_pShaderCom, "g_DiffuseTexture", aiTextureType_DIFFUSE, 0))) {
|
||||
if (FAILED(m_pModelCom->Bind_Material(0, m_pShaderCom))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (FAILED(m_pShaderCom->Begin(ENUM_CLASS(SHADER_PASS_MESH::DEFAULT)))) {
|
||||
|
||||
@@ -58,13 +58,9 @@ HRESULT CDummy_PhysXMesh::Render()
|
||||
|
||||
for (_uint i = 0; i < iNumMeshes; i++)
|
||||
{
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom, "g_DiffuseTexture", aiTextureType_DIFFUSE, 0))) {
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom, "g_NormalTexture", aiTextureType_NORMALS, 0))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (FAILED(m_pShaderCom->Begin(ENUM_CLASS(SHADER_PASS_MESH::DEFAULT)))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
@@ -60,10 +60,10 @@ HRESULT CDummy_Plane::Render()
|
||||
|
||||
for (_uint i = 0; i < iNumMeshes; i++)
|
||||
{
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom, "g_DiffuseTexture", aiTextureType_DIFFUSE, 0))) {
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom, "g_NormalTexture", aiTextureType_NORMALS, 0))) {
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
|
||||
@@ -61,10 +61,7 @@ HRESULT CGoblin::Render()
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom, "g_DiffuseTexture", aiTextureType_DIFFUSE, 0))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom, "g_NormalTexture", aiTextureType_NORMALS, 0))) {
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
|
||||
@@ -65,10 +65,7 @@ HRESULT CHead::Render()
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom, "g_DiffuseTexture", aiTextureType_DIFFUSE, 0))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom, "g_NormalTexture", aiTextureType_NORMALS, 0))) {
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,13 +44,9 @@ HRESULT CLand::Render()
|
||||
|
||||
for (_uint i = 0; i < iNumMeshes; i++)
|
||||
{
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom, "g_DiffuseTexture", aiTextureType_DIFFUSE, 0))) {
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom, "g_NormalTexture", aiTextureType_NORMALS, 0))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (FAILED(m_pShaderCom->Begin(ENUM_CLASS(SHADER_PASS_MESH::DEFAULT)))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
@@ -29,10 +29,32 @@ HRESULT CLevel_BloomViewer::Initialize()
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (FAILED(m_pGameInstance->Add_GameObject_ToLayer<CDummy_Globe>(g_iStaticLevel, NEXT_LEVEL, LAYER_CUBE))){
|
||||
return E_FAIL;
|
||||
{
|
||||
CDummy_Globe::GLOBE_DESC Desc{};
|
||||
Desc.wstrKey = TEXT("Prototype_GameObject_SM_DragonGlobe");
|
||||
Desc.vPos = { 0.f, 0.f, 0.f };
|
||||
if (FAILED(m_pGameInstance->Add_GameObject_ToLayer<CDummy_Globe>(g_iStaticLevel, NEXT_LEVEL, LAYER_CUBE, &Desc))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
CDummy_Globe::GLOBE_DESC Desc{};
|
||||
Desc.wstrKey = TEXT("Desc_Globe");
|
||||
Desc.vPos = { 3.f, 0.f, 0.f };
|
||||
if (FAILED(m_pGameInstance->Add_GameObject_ToLayer<CDummy_Globe>(g_iStaticLevel, NEXT_LEVEL, LAYER_CUBE, &Desc))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
CDummy_Globe::GLOBE_DESC Desc{};
|
||||
Desc.wstrKey = TEXT("Desc_Globe2");
|
||||
Desc.vPos = { 6.f, 0.f, 0.f };
|
||||
if (FAILED(m_pGameInstance->Add_GameObject_ToLayer<CDummy_Globe>(g_iStaticLevel, NEXT_LEVEL, LAYER_CUBE, &Desc))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
}
|
||||
//if (FAILED(m_pGameInstance->Add_GameObject_ToLayer<CDummy_Cube>(g_iStaticLevel, NEXT_LEVEL, LAYER_CUBE))){
|
||||
// return E_FAIL;
|
||||
//}
|
||||
|
||||
@@ -929,10 +929,24 @@ HRESULT CLoader::Loading_For_Bloom()
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (FAILED(m_pGameInstance->Add_Prototype<CDummy_Globe>(g_iStaticLevel, CDummy_Globe::Create(m_pDevice, m_pContext)))){
|
||||
if (FAILED(m_pGameInstance->Add_Asset_Prototype(g_iStaticLevel, TEXT("Desc_Globe2"),
|
||||
CModel::Create(m_pDevice, m_pContext, MODEL::NONANIM, "../Bin/Resources/Models/Object/DragonGlobe2/DragonGlobe.fbx", XMMatrixScaling(0.01f, 0.01f, 0.01f) * XMMatrixIdentity())))){
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
vector<_wstring> ModelPrototypeTags = {};
|
||||
vector<filesystem::path> ModelPrototypePath = {};
|
||||
|
||||
/* Hog_Props */
|
||||
if (FAILED(MapFolderLoad("C:\\Users\\kimnuri\\Desktop\\MeshTable\\Game\\Environment\\Hogwarts\\Meshes\\Props",
|
||||
".fbx", true, ModelPrototypeTags, ModelPrototypePath))){
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (FAILED(m_pGameInstance->Add_Prototype<CDummy_Globe>(g_iStaticLevel, CDummy_Globe::Create(m_pDevice, m_pContext)))){
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (FAILED(m_pGameInstance->Add_Prototype<CDummy_Cube>(g_iStaticLevel, CDummy_Cube::Create(m_pDevice, m_pContext)))){
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
@@ -89,10 +89,7 @@ HRESULT CMapElement_Interactable::Render()
|
||||
|
||||
for (_uint i = 0; i < iNumMeshes; i++)
|
||||
{
|
||||
if (FAILED(m_pModelComs[0]->Bind_Material(i, m_pShaderCom, "g_DiffuseTexture", aiTextureType_DIFFUSE, 0))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (FAILED(m_pModelComs[0]->Bind_Material(i, m_pShaderCom, "g_NormalTexture", aiTextureType_NORMALS, 0))) {
|
||||
if (FAILED(m_pModelComs[0]->Bind_Material(i, m_pShaderCom))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (m_bSelected)
|
||||
|
||||
@@ -90,10 +90,7 @@ HRESULT CMapElement_Static::Render()
|
||||
|
||||
for (_uint i = 0; i < iNumMeshes; i++)
|
||||
{
|
||||
if (FAILED(m_pModelComs[0]->Bind_Material(i, m_pShaderCom, "g_DiffuseTexture", aiTextureType_DIFFUSE, 0))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (FAILED(m_pModelComs[0]->Bind_Material(i, m_pShaderCom, "g_NormalTexture", aiTextureType_NORMALS, 0))) {
|
||||
if (FAILED(m_pModelComs[0]->Bind_Material(i, m_pShaderCom))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (m_bSelected)
|
||||
|
||||
@@ -64,7 +64,7 @@ HRESULT CMapObject_Collision::Render()
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (FAILED(m_pModelComs[0]->Bind_Material(i, m_pShaderCom, "g_NormalTexture", aiTextureType_NORMALS, 0))) {
|
||||
if (FAILED(m_pModelComs[0]->Bind_Material(i, m_pShaderCom))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (m_bSelected)
|
||||
|
||||
@@ -125,14 +125,10 @@ HRESULT CMapObject_LOD::Render()
|
||||
|
||||
for (_uint i = 0; i < iNumMeshes; i++)
|
||||
{
|
||||
if (FAILED(m_pModelComs[0]->Bind_Material(i, m_pShaderCom, "g_DiffuseTexture", aiTextureType_DIFFUSE, 0))) {
|
||||
if (FAILED(m_pModelComs[0]->Bind_Material(i, m_pShaderCom))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (FAILED(m_pModelComs[0]->Bind_Material(i, m_pShaderCom, "g_NormalTexture", aiTextureType_NORMALS, 0))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (m_bSelected)
|
||||
{
|
||||
if (FAILED(m_pShaderCom->Begin(ENUM_CLASS(SHADER_PASS_MESH::MAPTOOL)))) {
|
||||
|
||||
@@ -70,13 +70,9 @@ HRESULT CModelParts::Render()
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom, "g_DiffuseTexture", aiTextureType_DIFFUSE, 0))) {
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom, "g_NormalTexture", aiTextureType_NORMALS, 0))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (FAILED(m_pShaderCom->Begin(ENUM_CLASS(SHADER_PASS_ANIM::DEFAULT)))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
@@ -92,13 +92,9 @@ HRESULT CPlayer::Render()
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom, "g_DiffuseTexture", aiTextureType_DIFFUSE, 0))) {
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom, "g_NormalTexture", aiTextureType_NORMALS, 0))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (FAILED(m_pShaderCom->Begin(ENUM_CLASS(SHADER_PASS_ANIM::DEFAULT)))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,11 @@ NS_BEGIN(Editor)
|
||||
|
||||
class CDummy_Globe final : public CGameObject
|
||||
{
|
||||
public:
|
||||
typedef struct tagGlobeDesc {
|
||||
_wstring wstrKey = {};
|
||||
_float3 vPos = {};
|
||||
}GLOBE_DESC;
|
||||
private:
|
||||
CDummy_Globe(ID3D11Device* pDevice, ID3D11DeviceContext* pContext);
|
||||
CDummy_Globe(const CDummy_Globe& rhs);
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Editor
|
||||
|
||||
enum class SHADER_PASS_ANIM { DEFAULT, SHADOW, CAPTURE, BLUR, END };
|
||||
enum class SHADER_PASS_CUBE { DEFAULT, SHADOW, BLUR, END };
|
||||
enum class SHADER_PASS_MESH { DEFAULT, SHADOW, SKYBOX, ALPHABLEND, EFFECT_ALPHABLEND, EFFECT_BLEND, EFFECT_ALPHABLEND_CULL, EFFECT_BLEND_CULL, CAPTURE, BLUR, EFFECT_ALPHABLEND_UVMOVE, MAPTOOL, GLASS, PROP, NOMROPROP, END };
|
||||
enum class SHADER_PASS_MESH { DEFAULT, SHADOW, SKYBOX, ALPHABLEND, EFFECT_ALPHABLEND, EFFECT_BLEND, EFFECT_ALPHABLEND_CULL, EFFECT_BLEND_CULL, CAPTURE, BLUR, EFFECT_ALPHABLEND_UVMOVE, MAPTOOL, GLASS, END };
|
||||
enum class SHADER_PASS_NORTEX { DEFAULT, TERRAIN, END };
|
||||
enum class SHADER_PASS_PARTICLE { EXPLOSION, END };
|
||||
enum class SHADER_PASS_POSTEX { DEFAULT, SCISSOR, UI, UVMOVE, TRAIL, END };
|
||||
|
||||
@@ -15,7 +15,6 @@ namespace Editor {
|
||||
#define FX_POSTEX TEXT("FX_POSTEX")
|
||||
#define FX_NORTEX TEXT("FX_NORTEX")
|
||||
#define FX_CELL TEXT("FX_CELL")
|
||||
#define FX_DEFERRED TEXT("FX_DEFFERED")
|
||||
#define FX_PARTICLE TEXT("FX_PARTICLE")
|
||||
#define FX_INSTANCE_MODEL TEXT("FX_INSTANCE_MODEL")
|
||||
#define FX_UIEDITOR TEXT("FX_UIEDITOR")
|
||||
@@ -63,4 +62,4 @@ namespace Editor {
|
||||
|
||||
|
||||
#pragma endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
#ifndef ENGINE_SHADER_CONSTANTS_HLSLI
|
||||
#define ENGINE_SHADER_CONSTANTS_HLSLI
|
||||
|
||||
static const vector g_vMtrlDiffuse = 1.f;
|
||||
static const vector g_vMtrlAmbient = 1.f;
|
||||
static const vector g_vMtrlSpecular = 1.f;
|
||||
|
||||
static const float PI = 3.14159265359;
|
||||
static const float PI2 = 6.28318530718;
|
||||
|
||||
static const float FLT_EPSILON7 = 1.192092896e-07;
|
||||
static const float FLT_EPSILON5 = 1.192092896e-05;
|
||||
static const float FLT_EPSILON3 = 1.192092896e-03;
|
||||
|
||||
|
||||
static const float AI_TEXTURE_TYPE_NONE = 0.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_DIFFUSE = 1.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_SPECULAR = 2.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_AMBIENT = 3.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_EMISSIVE = 4.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_HEIGHT = 5.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_NORMALS = 6.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_SHININESS = 7.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_OPACITY = 8.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_DISPLACEMENT = 9.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_LIGHTMAP = 10.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_REFLECTION = 11.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_BASE_COLOR = 12.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_NORMAL_CAMERA = 13.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_EMISSION_COLOR = 14.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_METALNESS = 15.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_DIFFUSE_ROUGHNESS = 16.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_AMBIENT_OCCLUSION = 17.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_UNKNOWN = 18.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_SHEEN = 19.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_CLEARCOAT = 20.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_TRANSMISSION = 21.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_MAYA_BASE = 22.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_MAYA_SPECULAR = 23.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_MAYA_SPECULAR_COLOR = 24.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_MAYA_SPECULAR_ROUGHNESS = 25.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_ANISOTROPY = 26.f / 27.f;
|
||||
static const float AI_TEXTURE_TYPE_GLTF_METALLIC_ROUGHNESS = 27.f / 27.f;
|
||||
|
||||
|
||||
|
||||
#endif // ENGINE_SHADER_CONSTANTS_HLSLI
|
||||
@@ -1,362 +1,10 @@
|
||||
#ifndef ENGINE_SHADER_DEFINES_HLSLI
|
||||
#define ENGINE_SHADER_DEFINES_HLSLI
|
||||
|
||||
vector g_vMtrlDiffuse = 1.f;
|
||||
vector g_vMtrlAmbient = 1.f;
|
||||
vector g_vMtrlSpecular = 1.f;
|
||||
#include "Engine_Shader_Constants.hlsli"
|
||||
#include "Engine_Shader_Structures.hlsli"
|
||||
#include "Engine_Shader_Samplers.hlsli"
|
||||
#include "Engine_Shader_States.hlsli"
|
||||
#include "Engine_Shader_Functions.hlsli"
|
||||
|
||||
float PI = 3.14592;
|
||||
|
||||
sampler DefaultSampler = sampler_state
|
||||
{
|
||||
Filter = MIN_MAG_MIP_LINEAR;
|
||||
AddressU = wrap;
|
||||
AddressV = wrap;
|
||||
};
|
||||
|
||||
sampler ClampSampler = sampler_state
|
||||
{
|
||||
Filter = MIN_MAG_MIP_POINT;
|
||||
AddressU = clamp;
|
||||
AddressV = clamp;
|
||||
};
|
||||
|
||||
sampler MirrorSampler = sampler_state
|
||||
{
|
||||
Filter = MIN_MAG_MIP_LINEAR;
|
||||
AddressU = mirror;
|
||||
AddressV = mirror;
|
||||
};
|
||||
|
||||
sampler BorderZeroSampler = sampler_state
|
||||
{
|
||||
Filter = MIN_MAG_MIP_POINT;
|
||||
AddressU = Border;
|
||||
AddressV = Border;
|
||||
BorderColor = float4(0, 0, 0, 0);
|
||||
};
|
||||
|
||||
sampler PointSampler = sampler_state
|
||||
{
|
||||
Filter = MIN_MAG_MIP_POINT;
|
||||
AddressU = wrap;
|
||||
AddressV = wrap;
|
||||
};
|
||||
|
||||
RasterizerState RS_Default
|
||||
{
|
||||
FillMode = Solid;
|
||||
CullMode = Back;
|
||||
};
|
||||
|
||||
RasterizerState RS_Nocull
|
||||
{
|
||||
FillMode = Solid;
|
||||
CullMode = None;
|
||||
FrontCounterClockwise = false;
|
||||
DepthClipEnable = false;
|
||||
};
|
||||
|
||||
RasterizerState RS_Nocull_Wireframe
|
||||
{
|
||||
FillMode = Wireframe;
|
||||
CullMode = None;
|
||||
FrontCounterClockwise = false;
|
||||
DepthBias = 0;
|
||||
SlopeScaledDepthBias = 0.f;
|
||||
DepthBiasClamp = 0.f;
|
||||
DepthClipEnable = false;
|
||||
ScissorEnable = false;
|
||||
MultisampleEnable = false;
|
||||
AntialiasedLineEnable = false;
|
||||
};
|
||||
|
||||
RasterizerState RS_Scissor
|
||||
{
|
||||
FillMode = Solid;
|
||||
CullMode = Back;
|
||||
FrontCounterClockwise = false;
|
||||
ScissorEnable = true;
|
||||
};
|
||||
|
||||
DepthStencilState DSS_Default
|
||||
{
|
||||
DepthEnable = true;
|
||||
DepthWriteMask = all;
|
||||
DepthFunc = less_equal;
|
||||
};
|
||||
|
||||
DepthStencilState DSS_None
|
||||
{
|
||||
DepthEnable = false;
|
||||
DepthWriteMask = zero;
|
||||
};
|
||||
|
||||
DepthStencilState DSS_Effect
|
||||
{
|
||||
DepthEnable = true;
|
||||
DepthWriteMask = zero;
|
||||
DepthFunc = less_equal;
|
||||
StencilEnable = false;
|
||||
};
|
||||
|
||||
BlendState BS_None
|
||||
{
|
||||
BlendEnable[0] = false;
|
||||
};
|
||||
|
||||
BlendState BS_AlphaBlend // ALPHA_BLEND
|
||||
{
|
||||
BlendEnable[0] = true;
|
||||
BlendEnable[1] = true;
|
||||
BlendEnable[2] = true;
|
||||
BlendEnable[3] = true;
|
||||
BlendEnable[4] = true;
|
||||
BlendEnable[5] = true;
|
||||
BlendEnable[6] = true;
|
||||
BlendEnable[7] = true;
|
||||
|
||||
// Ac * Aa + Bc * (1 - Aa);
|
||||
SrcBlend = Src_Alpha;
|
||||
DestBlend = Inv_Src_Alpha;
|
||||
BlendOp = Add;
|
||||
};
|
||||
|
||||
BlendState BS_Blend // ADDITIVE_BLEND
|
||||
{
|
||||
BlendEnable[0] = true;
|
||||
BlendEnable[1] = true;
|
||||
BlendEnable[2] = true;
|
||||
BlendEnable[3] = true;
|
||||
BlendEnable[4] = true;
|
||||
BlendEnable[5] = true;
|
||||
BlendEnable[6] = true;
|
||||
BlendEnable[7] = true;
|
||||
|
||||
// Ac * (1) + Bc * (1);
|
||||
SrcBlend = one;
|
||||
DestBlend = one;
|
||||
BlendOp = Add;
|
||||
};
|
||||
|
||||
BlendState BS_UIBlend
|
||||
{
|
||||
BlendEnable[0] = true;
|
||||
BlendEnable[1] = true;
|
||||
BlendEnable[2] = true;
|
||||
BlendEnable[3] = true;
|
||||
BlendEnable[4] = true;
|
||||
BlendEnable[5] = true;
|
||||
BlendEnable[6] = true;
|
||||
BlendEnable[7] = true;
|
||||
|
||||
SrcBlend = Src_Alpha;
|
||||
DestBlend = Inv_Src_Alpha;
|
||||
BlendOp = Add;
|
||||
|
||||
SrcBlendAlpha = One;
|
||||
DestBlendAlpha = Zero;
|
||||
BlendOpAlpha = Add;
|
||||
|
||||
RenderTargetWriteMask[0] = 0x0F; // RGBA 모두 출력
|
||||
};
|
||||
|
||||
BlendState BS_WB_Acc
|
||||
{
|
||||
BlendEnable[0] = true;
|
||||
BlendEnable[1] = true;
|
||||
BlendEnable[2] = true;
|
||||
BlendEnable[3] = true;
|
||||
BlendEnable[4] = true;
|
||||
BlendEnable[5] = true;
|
||||
BlendEnable[6] = true;
|
||||
BlendEnable[7] = true;
|
||||
|
||||
SrcBlend[0] = one;
|
||||
DestBlend[0] = one;
|
||||
BlendOp[0] = Add;
|
||||
|
||||
SrcBlend[1] = Zero;
|
||||
DestBlend[1] = Inv_Src_Alpha;
|
||||
BlendOp[1] = Add;
|
||||
|
||||
|
||||
SrcBlend[2] = one;
|
||||
DestBlend[2] = one;
|
||||
BlendOp[2] = Add;
|
||||
};
|
||||
|
||||
BlendState BS_WeightBlend
|
||||
{
|
||||
BlendEnable[0] = true;
|
||||
BlendEnable[1] = true;
|
||||
BlendEnable[2] = true;
|
||||
BlendEnable[3] = true;
|
||||
BlendEnable[4] = true;
|
||||
BlendEnable[5] = true;
|
||||
BlendEnable[6] = true;
|
||||
BlendEnable[7] = true;
|
||||
|
||||
|
||||
SrcBlend[0] = Src_Alpha;
|
||||
DestBlend[0] = Inv_Src_Alpha;
|
||||
|
||||
BlendOp[0] = Add;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
float ShadowVisibility_hwPCF(Texture2D ShadowMap, float4 vLightClip, float2 vShadowMapSize, float bias)
|
||||
{
|
||||
float2 uv = float2(vLightClip.x / vLightClip.w, -vLightClip.y / vLightClip.w) * 0.5f + 0.5f;
|
||||
float fDepthCenter = saturate(vLightClip.z / vLightClip.w);
|
||||
float2 vTexel = 1.f / vShadowMapSize;
|
||||
|
||||
float fVisibility = 0.f;
|
||||
for (int v = -1; v <= 1; ++v)
|
||||
{
|
||||
for (int u = -1; u <= 1; ++u)
|
||||
{
|
||||
float2 vOffset = float2(u, v) * vTexel;
|
||||
float fDepth = ShadowMap.Sample(DefaultSampler, uv + vOffset).x;
|
||||
fVisibility += (fDepthCenter - bias > fDepth) ? 0.f : 1.f;
|
||||
}
|
||||
}
|
||||
return fVisibility / 9.f;
|
||||
}
|
||||
|
||||
float GetRimLight(float3 vCamPosition, float3 vPosition, float3 vNormal, float fRimPower, float fRimStrength)
|
||||
{
|
||||
float fRimLight = (1 - dot(normalize(vCamPosition - vPosition), vNormal));
|
||||
fRimLight = pow(fRimLight, fRimPower);
|
||||
fRimLight = fRimLight * fRimStrength;
|
||||
return fRimLight;
|
||||
}
|
||||
|
||||
float2 Get_MovedUV(float2 vOriginalUV, float fDeltaU, float fDeltaV, uint iIndexU, uint iIndexV)
|
||||
{
|
||||
float2 vDelta = float2(fDeltaU, fDeltaV);
|
||||
float2 vOffset = float2(iIndexU * fDeltaU, iIndexV * fDeltaV);
|
||||
return vOriginalUV * vDelta + vOffset;
|
||||
}
|
||||
|
||||
float2 UV_Cutting(float2 vUV, float2 vUVCutting, int iCurrentFrame)
|
||||
{
|
||||
float2 UV = vUV; // 이미지의 UV값
|
||||
|
||||
int iTotalFrame = vUVCutting.x * vUVCutting.y; // 이미지의 최대 프레임 (몇 곱하기 몇인지)
|
||||
|
||||
int iFrameX = iCurrentFrame % (int) vUVCutting.x; // 현재 x축의 위치(현재 이미지의 몇번째 칸을 보여줄 지)
|
||||
int iFrameY = iCurrentFrame / (int) vUVCutting.x; // 현재 y축의 위치(현재 이미지의 몇번째 줄을 보여줄 지)
|
||||
|
||||
float fFreamWidth = 1.0 / vUVCutting.x; // 1.0 나누기 이미지 갯수를 해서 한칸에 얼마나 갈지 정해준다.
|
||||
float fFreamHeight = 1.0 / vUVCutting.y; // 1.0 나누기 이미지 갯수를 해서 한줄에 얼마나 갈지 정해준다.
|
||||
|
||||
UV.x = UV.x * fFreamWidth + iFrameX * fFreamWidth; // 먼저 uv를 0~1이 아닌 0~fFrameWidth로 만든 다음에 한칸씩 옆으로 밀어준다.
|
||||
UV.y = UV.y * fFreamHeight + iFrameY * fFreamHeight; // 먼저 uv를 0~1이 아닌 0~fFrameHeight로 만든 다음에 한줄씩 밑으로 내려준다.
|
||||
|
||||
return UV;
|
||||
}
|
||||
|
||||
struct PBR_LIGHT_OUT
|
||||
{
|
||||
float3 vShade;
|
||||
float3 vSpecular;
|
||||
};
|
||||
|
||||
// (Kd F(Lambert)) + (Ks F(cook-torrance))
|
||||
|
||||
//float LambertDiffuse(float c)
|
||||
//{
|
||||
// return c / PI;
|
||||
//}
|
||||
|
||||
// F(cook-torrance)
|
||||
// DFG / (4 (Wo dot N) (Wi dot N))
|
||||
|
||||
// D(distribution, NormalDistribution function), 표면의 거칠기에 영향을 받는 halfWay vector
|
||||
// G(Geometry, GeometryFunc), 에너지 보존법칙 적용
|
||||
// F(Fresnel-Fresnel equation), 표면 각도에 따른 반사율
|
||||
|
||||
// F->D
|
||||
float NDF_ggxtr(float3 vNormal, float3 vHalfWayVector, float fAlpha) // NormalDistributionGGXTR, (H, halfWay vector), (A, Roughness), (N, Normal)
|
||||
{
|
||||
float a2 = fAlpha * fAlpha;
|
||||
float NdotH = saturate(dot(vNormal, vHalfWayVector));
|
||||
float NdotH2 = NdotH * NdotH;
|
||||
|
||||
float nom = a2;
|
||||
float denom = (NdotH2 * (a2 - 1.f) + 1.f);
|
||||
|
||||
denom = PI * denom * denom;
|
||||
return (nom / denom);
|
||||
}
|
||||
|
||||
// F->G
|
||||
// GschlickGGX(n, v, k)
|
||||
// k는 이하 두개 조명 조건에 따라 가변적임
|
||||
// Direct // Kdir -> ((a + 1) * (a + 1)) / 8 // direct lighting 추천
|
||||
// IBL Lighting // Kibl -> a * a / 2 // 이미지 기반 조명기법
|
||||
|
||||
float Geometry_SchlickGGX(float NdotV, float fK)
|
||||
{
|
||||
return NdotV / (NdotV * (1.0f - fK) + fK);
|
||||
}
|
||||
|
||||
float Geometry_Smith(float3 vNormal, float3 vFromView, float3 vFromLight, float k)
|
||||
{
|
||||
// Geometry Obstruction
|
||||
// 철이 있는, 주로 튀어나온 장애물
|
||||
float NdotV = saturate(dot(vNormal, vFromView));
|
||||
|
||||
// Geometry Shadowing
|
||||
// 요가 있는, 주로 음푹 들어간 장애물 (그래서 셰도잉)
|
||||
float NdotL = saturate(dot(vNormal, vFromLight));
|
||||
|
||||
// 요철이 골고루 있다고 가정하고 적당히 섞음
|
||||
return Geometry_SchlickGGX(NdotV, k) * Geometry_SchlickGGX(NdotL, k);
|
||||
}
|
||||
|
||||
// F -> F
|
||||
float3 Fresnel_Schlick(float cosTheta, float3 F0)
|
||||
{
|
||||
// 모서리 부분의 반사
|
||||
return F0 + (1.0f - F0) * pow(1.0f - cosTheta, 5.0f);
|
||||
}
|
||||
|
||||
PBR_LIGHT_OUT PBR_Lighting(
|
||||
float3 vNormal, float3 vFromView, float3 vFromLight,
|
||||
float3 vAlbedo, float fMetallic, float fRoughness,
|
||||
float3 vLightColor, float fAttenuation, float3 vFO
|
||||
) {
|
||||
PBR_LIGHT_OUT Out;
|
||||
Out.vShade = 0;
|
||||
Out.vSpecular = 0;
|
||||
|
||||
float3 vHalfVector = normalize(vFromView + vFromLight);
|
||||
float NdotL = saturate(dot(vNormal, vFromLight));
|
||||
float NdotV = saturate(dot(vNormal, vFromView));
|
||||
if (NdotL <= 0 || NdotV <= 0)
|
||||
{
|
||||
return Out;
|
||||
}
|
||||
float fAlpha = max(fRoughness * fRoughness, 0.04f);
|
||||
float k = ((fRoughness + 1.f) * (fRoughness + 1.f)) / 8.f;
|
||||
|
||||
float D = NDF_ggxtr(vNormal, vHalfVector, fAlpha);
|
||||
float G = Geometry_Smith(vNormal, vFromView, vFromLight, k);
|
||||
float3 F = Fresnel_Schlick(saturate(dot(vHalfVector, vFromView)), vFO);
|
||||
|
||||
float3 vNumerator = D * G * F;
|
||||
float fDenom = max(4.f * NdotL * NdotV, 1e-7);
|
||||
float3 specularBRDF = vNumerator / fDenom;
|
||||
|
||||
float3 kS = F;
|
||||
float3 kD = (1.f - kS) * (1.f -fMetallic);
|
||||
|
||||
//Out.vShade = float(1.f, 1.f, 1. 1.f);
|
||||
Out.vShade = (kD / PI) * (NdotL * fAttenuation) * vLightColor;
|
||||
|
||||
Out.vSpecular = specularBRDF * vLightColor * fAttenuation * NdotL;
|
||||
|
||||
return Out;
|
||||
}
|
||||
#endif // ENGINE_SHADER_DEFINES_HLSLI
|
||||
|
||||
@@ -0,0 +1,184 @@
|
||||
#ifndef ENGINE_SHADER_FUNCTIONS_HLSLI
|
||||
#define ENGINE_SHADER_FUNCTIONS_HLSLI
|
||||
|
||||
#include "Engine_Shader_Constants.hlsli"
|
||||
#include "Engine_Shader_Structures.hlsli"
|
||||
#include "Engine_Shader_Samplers.hlsli"
|
||||
|
||||
bool AlmostEqual7(float fA, float fB)
|
||||
{
|
||||
return abs(fA - fB) < FLT_EPSILON7;
|
||||
}
|
||||
bool AlmostEqual5(float fA, float fB)
|
||||
{
|
||||
return abs(fA - fB) < FLT_EPSILON5;
|
||||
}
|
||||
bool AlmostEqual3(float fA, float fB)
|
||||
{
|
||||
return abs(fA - fB) < FLT_EPSILON3;
|
||||
}
|
||||
|
||||
float ShadowVisibility_hwPCF(Texture2D ShadowMap, float4 vLightClip, float2 vShadowMapSize, float bias)
|
||||
{
|
||||
float2 uv = float2(vLightClip.x / vLightClip.w, -vLightClip.y / vLightClip.w) * 0.5f + 0.5f;
|
||||
float fDepthCenter = saturate(vLightClip.z / vLightClip.w);
|
||||
float2 vTexel = 1.f / vShadowMapSize;
|
||||
|
||||
float fVisibility = 0.f;
|
||||
for (int v = -1; v <= 1; ++v)
|
||||
{
|
||||
for (int u = -1; u <= 1; ++u)
|
||||
{
|
||||
float2 vOffset = float2(u, v) * vTexel;
|
||||
float fDepth = ShadowMap.Sample(DefaultSampler, uv + vOffset).x;
|
||||
fVisibility += (fDepthCenter - bias > fDepth) ? 0.f : 1.f;
|
||||
}
|
||||
}
|
||||
return fVisibility / 9.f;
|
||||
}
|
||||
|
||||
float GetRimLight(float3 vCamPosition, float3 vPosition, float3 vNormal, float fRimPower, float fRimStrength)
|
||||
{
|
||||
float fRimLight = (1 - dot(normalize(vCamPosition - vPosition), vNormal));
|
||||
fRimLight = pow(fRimLight, fRimPower);
|
||||
fRimLight = fRimLight * fRimStrength;
|
||||
return fRimLight;
|
||||
}
|
||||
|
||||
float2 Get_MovedUV(float2 vOriginalUV, float fDeltaU, float fDeltaV, uint iIndexU, uint iIndexV)
|
||||
{
|
||||
float2 vDelta = float2(fDeltaU, fDeltaV);
|
||||
float2 vOffset = float2(iIndexU * fDeltaU, iIndexV * fDeltaV);
|
||||
return vOriginalUV * vDelta + vOffset;
|
||||
}
|
||||
|
||||
float2 UV_Cutting(float2 vUV, float2 vUVCutting, int iCurrentFrame)
|
||||
{
|
||||
float2 UV = vUV; // 이미지의 UV값
|
||||
|
||||
int iTotalFrame = vUVCutting.x * vUVCutting.y; // 이미지의 최대 프레임 (몇 곱하기 몇인지)
|
||||
|
||||
int iFrameX = iCurrentFrame % (int) vUVCutting.x; // 현재 x축의 위치(현재 이미지의 몇번째 칸을 보여줄 지)
|
||||
int iFrameY = iCurrentFrame / (int) vUVCutting.x; // 현재 y축의 위치(현재 이미지의 몇번째 줄을 보여줄 지)
|
||||
|
||||
float fFreamWidth = 1.0 / vUVCutting.x; // 1.0 나누기 이미지 갯수를 해서 한칸에 얼마나 갈지 정해준다.
|
||||
float fFreamHeight = 1.0 / vUVCutting.y; // 1.0 나누기 이미지 갯수를 해서 한줄에 얼마나 갈지 정해준다.
|
||||
|
||||
UV.x = UV.x * fFreamWidth + iFrameX * fFreamWidth; // 먼저 uv를 0~1이 아닌 0~fFrameWidth로 만든 다음에 한칸씩 옆으로 밀어준다.
|
||||
UV.y = UV.y * fFreamHeight + iFrameY * fFreamHeight; // 먼저 uv를 0~1이 아닌 0~fFrameHeight로 만든 다음에 한줄씩 밑으로 내려준다.
|
||||
|
||||
return UV;
|
||||
}
|
||||
|
||||
// (Kd F(Lambert)) + (Ks F(cook-torrance))
|
||||
|
||||
//float LambertDiffuse(float c)
|
||||
//{
|
||||
// return c / PI;
|
||||
//}
|
||||
|
||||
// F(cook-torrance)
|
||||
// DFG / (4 (Wo dot N) (Wi dot N))
|
||||
|
||||
// D(distribution, NormalDistribution function), 표면의 거칠기에 영향을 받는 halfWay vector
|
||||
// G(Geometry, GeometryFunc), 에너지 보존법칙 적용
|
||||
// F(Fresnel-Fresnel equation), 표면 각도에 따른 반사율
|
||||
|
||||
// F->D
|
||||
float NDF_ggxtr(float3 vNormal, float3 vHalfWayVector, float fAlpha) // NormalDistributionGGXTR, (H, halfWay vector), (A, Roughness), (N, Normal)
|
||||
{
|
||||
float a2 = fAlpha * fAlpha;
|
||||
float NdotH = saturate(dot(vNormal, vHalfWayVector));
|
||||
float NdotH2 = NdotH * NdotH;
|
||||
|
||||
float nom = a2;
|
||||
float denom = (NdotH2 * (a2 - 1.f) + 1.f);
|
||||
|
||||
denom = PI * denom * denom;
|
||||
return (nom / denom);
|
||||
}
|
||||
|
||||
// F->G
|
||||
// GschlickGGX(n, v, k)
|
||||
// k는 이하 두개 조명 조건에 따라 가변적임
|
||||
// Direct // Kdir -> ((a + 1) * (a + 1)) / 8 // direct lighting 추천
|
||||
// IBL Lighting // Kibl -> a * a / 2 // 이미지 기반 조명기법
|
||||
|
||||
float Geometry_SchlickGGX(float NdotV, float fK)
|
||||
{
|
||||
return NdotV / (NdotV * (1.0f - fK) + fK);
|
||||
}
|
||||
|
||||
float Geometry_Smith(float3 vNormal, float3 vFromView, float3 vFromLight, float k)
|
||||
{
|
||||
// Geometry Obstruction
|
||||
// 철이 있는, 주로 튀어나온 장애물
|
||||
float NdotV = saturate(dot(vNormal, vFromView));
|
||||
|
||||
// Geometry Shadowing
|
||||
// 요가 있는, 주로 음푹 들어간 장애물 (그래서 셰도잉)
|
||||
float NdotL = saturate(dot(vNormal, vFromLight));
|
||||
|
||||
// 요철이 골고루 있다고 가정하고 적당히 섞음
|
||||
return Geometry_SchlickGGX(NdotV, k) * Geometry_SchlickGGX(NdotL, k);
|
||||
}
|
||||
|
||||
// F -> F
|
||||
float3 Fresnel_Schlick(float cosTheta, float3 F0)
|
||||
{
|
||||
// 모서리 부분의 반사
|
||||
return F0 + (1.0f - F0) * pow(1.0f - cosTheta, 5.0f);
|
||||
}
|
||||
|
||||
PBR_LIGHT_OUT PBR_Lighting(
|
||||
float3 vNormal, float3 vFromView, float3 vFromLight,
|
||||
float3 vAlbedo, float fMetallic, float fRoughness,
|
||||
float3 vLightColor, float fAttenuation, float3 vFO
|
||||
) {
|
||||
PBR_LIGHT_OUT Out;
|
||||
Out.vShade = 0;
|
||||
Out.vSpecular = 0;
|
||||
|
||||
float3 vHalfVector = normalize(vFromView + vFromLight);
|
||||
float NdotL = saturate(dot(vNormal, vFromLight));
|
||||
float NdotV = saturate(dot(vNormal, vFromView));
|
||||
if (NdotL <= 0 || NdotV <= 0)
|
||||
{
|
||||
return Out;
|
||||
}
|
||||
float fAlpha = max(fRoughness * fRoughness, 0.04f);
|
||||
float k = ((fRoughness + 1.f) * (fRoughness + 1.f)) / 8.f;
|
||||
|
||||
float D = NDF_ggxtr(vNormal, vHalfVector, fAlpha);
|
||||
float G = Geometry_Smith(vNormal, vFromView, vFromLight, k);
|
||||
float3 F = Fresnel_Schlick(saturate(dot(vHalfVector, vFromView)), vFO);
|
||||
|
||||
float3 vNumerator = D * G * F;
|
||||
float fDenom = max(4.f * NdotL * NdotV, 1e-7);
|
||||
float3 specularBRDF = vNumerator / fDenom;
|
||||
|
||||
float3 kS = F;
|
||||
float3 kD = (1.f - kS) * (1.f -fMetallic);
|
||||
|
||||
//Out.vShade = float(1.f, 1.f, 1. 1.f);
|
||||
Out.vShade = (kD / PI) * (NdotL * fAttenuation) * vLightColor;
|
||||
|
||||
Out.vSpecular = specularBRDF * vLightColor * fAttenuation * NdotL;
|
||||
|
||||
return Out;
|
||||
}
|
||||
|
||||
float3 DecodeNormalFromRG(Texture2D NormalMap, SamplerState Samp, float2 uv)
|
||||
{
|
||||
float2 vSampledRG = (NormalMap.Sample(Samp, uv).rg * 2.f - 1.f);
|
||||
|
||||
float z2 = 1.0f - saturate(dot(vSampledRG, vSampledRG));
|
||||
float z = sqrt(max(z2, 0.0f));
|
||||
|
||||
float3 n = float3(vSampledRG, z);
|
||||
|
||||
return normalize(n);
|
||||
}
|
||||
|
||||
|
||||
#endif // ENGINE_SHADER_FUNCTIONS_HLSLI
|
||||
@@ -0,0 +1,40 @@
|
||||
#ifndef ENGINE_SHADER_SAMPLERS_HLSLI
|
||||
#define ENGINE_SHADER_SAMPLERS_HLSLI
|
||||
|
||||
sampler DefaultSampler = sampler_state
|
||||
{
|
||||
Filter = MIN_MAG_MIP_LINEAR;
|
||||
AddressU = wrap;
|
||||
AddressV = wrap;
|
||||
};
|
||||
|
||||
sampler ClampSampler = sampler_state
|
||||
{
|
||||
Filter = MIN_MAG_MIP_POINT;
|
||||
AddressU = clamp;
|
||||
AddressV = clamp;
|
||||
};
|
||||
|
||||
sampler MirrorSampler = sampler_state
|
||||
{
|
||||
Filter = MIN_MAG_MIP_LINEAR;
|
||||
AddressU = mirror;
|
||||
AddressV = mirror;
|
||||
};
|
||||
|
||||
sampler BorderZeroSampler = sampler_state
|
||||
{
|
||||
Filter = MIN_MAG_MIP_POINT;
|
||||
AddressU = Border;
|
||||
AddressV = Border;
|
||||
BorderColor = float4(0, 0, 0, 0);
|
||||
};
|
||||
|
||||
sampler PointSampler = sampler_state
|
||||
{
|
||||
Filter = MIN_MAG_MIP_POINT;
|
||||
AddressU = wrap;
|
||||
AddressV = wrap;
|
||||
};
|
||||
|
||||
#endif // ENGINE_SHADER_SAMPLERS_HLSLI
|
||||
@@ -0,0 +1,168 @@
|
||||
#ifndef ENGINE_SHADER_STATES_HLSLI
|
||||
#define ENGINE_SHADER_STATES_HLSLI
|
||||
|
||||
RasterizerState RS_Default
|
||||
{
|
||||
FillMode = Solid;
|
||||
CullMode = Back;
|
||||
};
|
||||
|
||||
RasterizerState RS_Nocull
|
||||
{
|
||||
FillMode = Solid;
|
||||
CullMode = None;
|
||||
FrontCounterClockwise = false;
|
||||
DepthClipEnable = false;
|
||||
};
|
||||
|
||||
RasterizerState RS_Nocull_Wireframe
|
||||
{
|
||||
FillMode = Wireframe;
|
||||
CullMode = None;
|
||||
FrontCounterClockwise = false;
|
||||
DepthBias = 0;
|
||||
SlopeScaledDepthBias = 0.f;
|
||||
DepthBiasClamp = 0.f;
|
||||
DepthClipEnable = false;
|
||||
ScissorEnable = false;
|
||||
MultisampleEnable = false;
|
||||
AntialiasedLineEnable = false;
|
||||
};
|
||||
|
||||
RasterizerState RS_Scissor
|
||||
{
|
||||
FillMode = Solid;
|
||||
CullMode = Back;
|
||||
FrontCounterClockwise = false;
|
||||
ScissorEnable = true;
|
||||
};
|
||||
|
||||
DepthStencilState DSS_Default
|
||||
{
|
||||
DepthEnable = true;
|
||||
DepthWriteMask = all;
|
||||
DepthFunc = less_equal;
|
||||
};
|
||||
|
||||
DepthStencilState DSS_None
|
||||
{
|
||||
DepthEnable = false;
|
||||
DepthWriteMask = zero;
|
||||
};
|
||||
|
||||
DepthStencilState DSS_Effect
|
||||
{
|
||||
DepthEnable = true;
|
||||
DepthWriteMask = zero;
|
||||
DepthFunc = less_equal;
|
||||
StencilEnable = false;
|
||||
};
|
||||
|
||||
BlendState BS_None
|
||||
{
|
||||
BlendEnable[0] = false;
|
||||
};
|
||||
|
||||
BlendState BS_AlphaBlend // ALPHA_BLEND
|
||||
{
|
||||
BlendEnable[0] = true;
|
||||
BlendEnable[1] = true;
|
||||
BlendEnable[2] = true;
|
||||
BlendEnable[3] = true;
|
||||
BlendEnable[4] = true;
|
||||
BlendEnable[5] = true;
|
||||
BlendEnable[6] = true;
|
||||
BlendEnable[7] = true;
|
||||
|
||||
// Ac * Aa + Bc * (1 - Aa);
|
||||
SrcBlend = Src_Alpha;
|
||||
DestBlend = Inv_Src_Alpha;
|
||||
BlendOp = Add;
|
||||
};
|
||||
|
||||
BlendState BS_Blend // ADDITIVE_BLEND
|
||||
{
|
||||
BlendEnable[0] = true;
|
||||
BlendEnable[1] = true;
|
||||
BlendEnable[2] = true;
|
||||
BlendEnable[3] = true;
|
||||
BlendEnable[4] = true;
|
||||
BlendEnable[5] = true;
|
||||
BlendEnable[6] = true;
|
||||
BlendEnable[7] = true;
|
||||
|
||||
// Ac * (1) + Bc * (1);
|
||||
SrcBlend = one;
|
||||
DestBlend = one;
|
||||
BlendOp = Add;
|
||||
};
|
||||
|
||||
BlendState BS_UIBlend
|
||||
{
|
||||
BlendEnable[0] = true;
|
||||
BlendEnable[1] = true;
|
||||
BlendEnable[2] = true;
|
||||
BlendEnable[3] = true;
|
||||
BlendEnable[4] = true;
|
||||
BlendEnable[5] = true;
|
||||
BlendEnable[6] = true;
|
||||
BlendEnable[7] = true;
|
||||
|
||||
SrcBlend = Src_Alpha;
|
||||
DestBlend = Inv_Src_Alpha;
|
||||
BlendOp = Add;
|
||||
|
||||
SrcBlendAlpha = One;
|
||||
DestBlendAlpha = Zero;
|
||||
BlendOpAlpha = Add;
|
||||
|
||||
RenderTargetWriteMask[0] = 0x0F; // RGBA 모두 출력
|
||||
};
|
||||
|
||||
BlendState BS_WB_Acc
|
||||
{
|
||||
BlendEnable[0] = true;
|
||||
BlendEnable[1] = true;
|
||||
BlendEnable[2] = true;
|
||||
BlendEnable[3] = true;
|
||||
BlendEnable[4] = true;
|
||||
BlendEnable[5] = true;
|
||||
BlendEnable[6] = true;
|
||||
BlendEnable[7] = true;
|
||||
|
||||
SrcBlend[0] = one;
|
||||
DestBlend[0] = one;
|
||||
BlendOp[0] = Add;
|
||||
|
||||
SrcBlend[1] = Zero;
|
||||
DestBlend[1] = Inv_Src_Alpha;
|
||||
BlendOp[1] = Add;
|
||||
|
||||
|
||||
SrcBlend[2] = one;
|
||||
DestBlend[2] = one;
|
||||
BlendOp[2] = Add;
|
||||
};
|
||||
|
||||
BlendState BS_WeightBlend
|
||||
{
|
||||
BlendEnable[0] = true;
|
||||
BlendEnable[1] = true;
|
||||
BlendEnable[2] = true;
|
||||
BlendEnable[3] = true;
|
||||
BlendEnable[4] = true;
|
||||
BlendEnable[5] = true;
|
||||
BlendEnable[6] = true;
|
||||
BlendEnable[7] = true;
|
||||
|
||||
|
||||
SrcBlend[0] = Src_Alpha;
|
||||
DestBlend[0] = Inv_Src_Alpha;
|
||||
|
||||
BlendOp[0] = Add;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // ENGINE_SHADER_STATES_HLSLI
|
||||
@@ -0,0 +1,10 @@
|
||||
#ifndef ENGINE_SHADER_STRUCTURES_HLSLI
|
||||
#define ENGINE_SHADER_STRUCTURES_HLSLI
|
||||
|
||||
struct PBR_LIGHT_OUT
|
||||
{
|
||||
float3 vShade;
|
||||
float3 vSpecular;
|
||||
};
|
||||
|
||||
#endif // ENGINE_SHADER_STRUCTURES_HLSLI
|
||||
@@ -35,14 +35,13 @@ Texture2D g_BlurTexture;
|
||||
Texture2D g_BlurXTexture;
|
||||
Texture2D g_BlurWeightTexture;
|
||||
|
||||
Texture2D g_SurfaceTexture;
|
||||
|
||||
|
||||
vector g_vLightDiffuse;
|
||||
vector g_vLightAmbient;
|
||||
vector g_vLightSpecular;
|
||||
|
||||
|
||||
|
||||
struct VS_IN
|
||||
{
|
||||
float3 vPosition : POSITION;
|
||||
@@ -56,9 +55,9 @@ struct VS_OUT
|
||||
};
|
||||
VS_OUT VS_MAIN(VS_IN In)
|
||||
{
|
||||
VS_OUT Out;
|
||||
VS_OUT Out;
|
||||
|
||||
matrix matWV, matWVP;
|
||||
matrix matWV, matWVP;
|
||||
|
||||
matWV = mul(g_WorldMatrix, g_ViewMatrix);
|
||||
matWVP = mul(matWV, g_ProjMatrix);
|
||||
@@ -66,7 +65,7 @@ VS_OUT VS_MAIN(VS_IN In)
|
||||
Out.vPosition = mul(vector(In.vPosition, 1.f), matWVP);
|
||||
Out.vTexcoord = In.vTexcoord;
|
||||
|
||||
return Out;
|
||||
return Out;
|
||||
}
|
||||
|
||||
struct PS_IN
|
||||
@@ -99,41 +98,77 @@ PS_OUT_LIGHT PS_MAIN_DIRECTIONAL(PS_IN In)
|
||||
{
|
||||
PS_OUT_LIGHT Out;
|
||||
|
||||
vector vNormalDesc = g_NormalTexture.Sample(DefaultSampler, In.vTexcoord);
|
||||
float2 uv = In.vTexcoord;
|
||||
|
||||
float4 vNormal = vector(vNormalDesc.xyz * 2.f - 1.f, 0.0f);
|
||||
// float3 vNormal = normalize(g_NormalTexture.Sample(DefaultSampler, uv).xyz * 2.f - 1);
|
||||
float3 vNormal = DecodeNormalFromRG(g_NormalTexture, DefaultSampler, uv);
|
||||
|
||||
Out.vShade = g_vLightDiffuse * saturate(max(dot(normalize(g_vLightDir) * -1.f, vNormal), 0.f) + (g_vLightAmbient * g_vMtrlAmbient));
|
||||
float4 vDepth = g_DepthTexture.Sample(DefaultSampler, uv);
|
||||
|
||||
vector vDepthDesc = g_DepthTexture.Sample(DefaultSampler, In.vTexcoord);
|
||||
float fViewZ = vDepth.y * g_fFar;
|
||||
|
||||
float fViewZ = vDepthDesc.y * g_fFar;
|
||||
float4 vWorldPosition;
|
||||
{
|
||||
vWorldPosition.x = uv.x * 2 - 1;
|
||||
vWorldPosition.y = uv.y * -2 + 1;
|
||||
vWorldPosition.z = vDepth.x;
|
||||
vWorldPosition.w = 1.f;
|
||||
vWorldPosition *= fViewZ;
|
||||
vWorldPosition = mul(vWorldPosition, g_invmatProj);
|
||||
vWorldPosition = mul(vWorldPosition, g_invMatView);
|
||||
}
|
||||
|
||||
vector vPosition;
|
||||
float3 vF0;
|
||||
float fMetallic;
|
||||
float fRoughness;
|
||||
float fOcclusion;
|
||||
float fAttenuation;
|
||||
|
||||
{ // vDepthDesc과 vTexcoord.xy로부터 World Position의 추론
|
||||
/* 직육면체의 NDC */
|
||||
/* LocalPos * World * View * Proj * ( 1 / w ) */
|
||||
vPosition.x = In.vTexcoord.x * 2.f - 1.f;
|
||||
vPosition.y = In.vTexcoord.y * -2.f + 1.f;
|
||||
vPosition.z = vDepthDesc.x;
|
||||
vPosition.w = 1.f;
|
||||
float3 vWPos = vWorldPosition.xyz;
|
||||
float3 vFromView = normalize(vWPos - g_vCamPosition.xyz); // 카메라에서 픽셀로 가는 방향
|
||||
float3 vFromLight = normalize(g_vLightDir.xyz); // 라이트에서 오는 라이트 벡터
|
||||
|
||||
/* [* (1 / w)] 소거*/
|
||||
/* z나누기를 되돌림 */
|
||||
vPosition = vPosition * fViewZ;
|
||||
// vPosition.x = In.vTexcoord.x * 2.f - 1.f * Far;
|
||||
// vPosition.y = In.vTexcoord.y * -2.f + 1.f * Far;
|
||||
// vPosition.z = vDepthDesc.x * Far;
|
||||
// vPosition.w = Far;
|
||||
float3 vAlbedo = g_DiffuseTexture.Sample(DefaultSampler, uv).rgb;
|
||||
|
||||
vPosition = mul(vPosition, g_invmatProj);
|
||||
vPosition = mul(vPosition, g_invMatView);
|
||||
}
|
||||
vector vLook = vPosition - g_vCamPosition;
|
||||
vector vReflect = reflect(normalize(g_vLightDir), vNormal);
|
||||
if (true == AlmostEqual3(vDepth.b, AI_TEXTURE_TYPE_METALNESS)) // Metallic
|
||||
{
|
||||
float3 vMRO = g_SurfaceTexture.Sample(DefaultSampler, uv).rgb;
|
||||
fMetallic = vMRO.r;
|
||||
fRoughness = vMRO.g;
|
||||
fOcclusion = vMRO.b;
|
||||
|
||||
vF0 = lerp(float3(0.04f, 0.04f, 0.04f), vAlbedo, fMetallic);
|
||||
}
|
||||
else if (true == AlmostEqual3(vDepth.b, AI_TEXTURE_TYPE_SPECULAR)) // Specular
|
||||
{
|
||||
float3 vSRO = g_SurfaceTexture.Sample(DefaultSampler, uv).rgb;
|
||||
float3 vSpec = vSRO.r;
|
||||
|
||||
fMetallic = 0.f;
|
||||
fRoughness = vSRO.g;
|
||||
fOcclusion = vSRO.b;
|
||||
|
||||
|
||||
vF0 = vSpec.xxx;
|
||||
}
|
||||
else
|
||||
{
|
||||
fMetallic = 0.f;
|
||||
fRoughness = 0.5f;
|
||||
fOcclusion = 1.f;
|
||||
vF0 = float3(0.04f, 0.04f, 0.04f);
|
||||
}
|
||||
|
||||
Out.vSpecular = (g_vLightSpecular * g_vMtrlSpecular) * pow(max(dot(normalize(vLook) * -1.f, normalize(vReflect)), 0.f), 50.f);
|
||||
fAttenuation = 1.f;
|
||||
|
||||
float fDiffuseAOStrength = lerp(0.3f, 1.f, fOcclusion);
|
||||
|
||||
PBR_LIGHT_OUT PBR_Out = PBR_Lighting(vNormal, vFromView, vFromLight, vAlbedo, fMetallic, fRoughness, g_vLightDiffuse.rgb, fAttenuation, vF0);
|
||||
|
||||
PBR_Out.vShade *= fDiffuseAOStrength;
|
||||
|
||||
Out.vShade = float4(PBR_Out.vShade, 1.f);
|
||||
Out.vSpecular = float4(PBR_Out.vSpecular, 1.f);
|
||||
|
||||
return Out;
|
||||
}
|
||||
@@ -142,38 +177,81 @@ PS_OUT_LIGHT PS_MAIN_POINT(PS_IN In)
|
||||
{
|
||||
PS_OUT_LIGHT Out;
|
||||
|
||||
vector vNormalDesc = g_NormalTexture.Sample(DefaultSampler, In.vTexcoord);
|
||||
float2 uv = In.vTexcoord;
|
||||
|
||||
float4 vNormal = vector(vNormalDesc.xyz * 2.f - 1.f, 0.f);
|
||||
float3 vNormal = DecodeNormalFromRG(g_NormalTexture, DefaultSampler, uv);
|
||||
|
||||
vector vDepthDesc = g_DepthTexture.Sample(DefaultSampler, In.vTexcoord);
|
||||
float fViewZ = vDepthDesc.y * g_fFar;
|
||||
float4 vDepth = g_DepthTexture.Sample(DefaultSampler, uv);
|
||||
|
||||
vector vPosition;
|
||||
/* 0 ~ 1 에서 -1 ~ 1 */
|
||||
vPosition.x = In.vTexcoord.x * 2.f - 1.f;
|
||||
vPosition.y = In.vTexcoord.y * -2.f + 1.f;
|
||||
vPosition.z = vDepthDesc.x;
|
||||
vPosition.w = 1.f;
|
||||
vPosition = vPosition * fViewZ;
|
||||
vPosition = mul(vPosition, g_invmatProj);
|
||||
vPosition = mul(vPosition, g_invMatView);
|
||||
float fViewZ = vDepth.y * g_fFar;
|
||||
|
||||
vector vLightDir = vPosition - (g_vLightPos + g_vLightPosOffset);
|
||||
float fDistance = length(vLightDir);
|
||||
float fAttenuation = saturate((g_fLightRange - fDistance) / g_fLightRange);
|
||||
if (fAttenuation <= 0.f)
|
||||
float4 vWorldPosition;
|
||||
{
|
||||
discard;
|
||||
vWorldPosition.x = uv.x * 2 - 1;
|
||||
vWorldPosition.y = uv.y * -2 + 1;
|
||||
vWorldPosition.z = vDepth.x;
|
||||
vWorldPosition.w = 1.f;
|
||||
vWorldPosition *= fViewZ;
|
||||
vWorldPosition = mul(vWorldPosition, g_invmatProj);
|
||||
vWorldPosition = mul(vWorldPosition, g_invMatView);
|
||||
}
|
||||
vLightDir = normalize(vLightDir);
|
||||
|
||||
Out.vShade = fAttenuation * (g_vLightDiffuse * saturate(max(dot(vLightDir * -1.f, vNormal), 0.f) + (g_vLightAmbient * g_vMtrlAmbient)));
|
||||
float3 vWPos = vWorldPosition.xyz;
|
||||
float3 vFromView = normalize(vWPos - g_vCamPosition.xyz); // 카메라에서 픽셀로 가는 방향
|
||||
float3 vFromLight = normalize(g_vLightDir.xyz); // 라이트에서 오는 라이트 벡터
|
||||
|
||||
vector vLook = vPosition - g_vCamPosition;
|
||||
vector vReflect = reflect(vLightDir, vNormal);
|
||||
float3 vF0;
|
||||
float fMetallic;
|
||||
float fRoughness;
|
||||
float fOcclusion;
|
||||
float fAttenuation;
|
||||
|
||||
Out.vSpecular = fAttenuation * ((g_vLightSpecular * g_vMtrlSpecular) * pow(max(dot(normalize(vLook) * -1.f, normalize(vReflect)), 0.f), 50.f));
|
||||
{
|
||||
float fDistance = length(vFromLight);
|
||||
fAttenuation = saturate((g_fLightRange - fDistance) / g_fLightRange);
|
||||
if (fAttenuation <= 0.f)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
}
|
||||
|
||||
float3 vAlbedo = g_DiffuseTexture.Sample(DefaultSampler, uv).rgb;
|
||||
|
||||
if (true == AlmostEqual3(vDepth.b, AI_TEXTURE_TYPE_METALNESS)) // Metallic
|
||||
{
|
||||
float3 vMRO = g_SurfaceTexture.Sample(DefaultSampler, uv).rgb;
|
||||
fMetallic = vMRO.r;
|
||||
fRoughness = vMRO.g;
|
||||
fOcclusion = vMRO.b;
|
||||
|
||||
vF0 = lerp(float3(0.04f, 0.04f, 0.04f), vAlbedo, fMetallic);
|
||||
}
|
||||
else if (true == AlmostEqual3(vDepth.b, AI_TEXTURE_TYPE_SPECULAR)) // Specular
|
||||
{
|
||||
float3 vSRO = g_SurfaceTexture.Sample(DefaultSampler, uv).rgb;
|
||||
float3 vSpec = vSRO.r;
|
||||
|
||||
fMetallic = 0.f;
|
||||
fRoughness = vSRO.g;
|
||||
fOcclusion = vSRO.b;
|
||||
|
||||
|
||||
vF0 = vSpec.xxx;
|
||||
}
|
||||
else
|
||||
{
|
||||
fMetallic = 0.f;
|
||||
fRoughness = 0.5f;
|
||||
fOcclusion = 1.f;
|
||||
vF0 = float3(0.04f, 0.04f, 0.04f);
|
||||
}
|
||||
|
||||
PBR_LIGHT_OUT PBR_Out = PBR_Lighting(vNormal, vFromView, vFromLight,
|
||||
vAlbedo, fMetallic, fRoughness,
|
||||
g_vLightDiffuse.rgb, fAttenuation, vF0);
|
||||
|
||||
Out.vShade = float4(PBR_Out.vShade, 1.f);
|
||||
Out.vSpecular = float4(PBR_Out.vSpecular, 1.f);
|
||||
|
||||
return Out;
|
||||
}
|
||||
@@ -182,46 +260,85 @@ PS_OUT_LIGHT PS_MAIN_SPOT(PS_IN In)
|
||||
{
|
||||
PS_OUT_LIGHT Out;
|
||||
|
||||
vector vNormalDesc = g_NormalTexture.Sample(DefaultSampler, In.vTexcoord);
|
||||
float2 uv = In.vTexcoord;
|
||||
|
||||
float4 vNormal = vector(vNormalDesc.xyz * 2.f - 1.f, 0.f);
|
||||
float3 vNormal = DecodeNormalFromRG(g_NormalTexture, DefaultSampler, uv);
|
||||
|
||||
vector vDepthDesc = g_DepthTexture.Sample(DefaultSampler, In.vTexcoord);
|
||||
float fViewZ = vDepthDesc.y * g_fFar;
|
||||
float4 vDepth = g_DepthTexture.Sample(DefaultSampler, uv);
|
||||
|
||||
vector vPosition;
|
||||
/* 0 ~ 1 에서 -1 ~ 1 */
|
||||
vPosition.x = In.vTexcoord.x * 2.f - 1.f;
|
||||
vPosition.y = In.vTexcoord.y * -2.f + 1.f;
|
||||
vPosition.z = vDepthDesc.x;
|
||||
vPosition.w = 1.f;
|
||||
vPosition = vPosition * fViewZ;
|
||||
vPosition = mul(vPosition, g_invmatProj);
|
||||
vPosition = mul(vPosition, g_invMatView);
|
||||
float fViewZ = vDepth.y * g_fFar;
|
||||
|
||||
vector vLightDir = vPosition - g_vLightPos;
|
||||
float fDistance = length(vLightDir);
|
||||
float fAttenuation = saturate((g_fLightRange - fDistance) / g_fLightRange);
|
||||
if (fAttenuation <= 0.f)
|
||||
float4 vWorldPosition;
|
||||
{
|
||||
discard;
|
||||
vWorldPosition.x = uv.x * 2 - 1;
|
||||
vWorldPosition.y = uv.y * -2 + 1;
|
||||
vWorldPosition.z = vDepth.x;
|
||||
vWorldPosition.w = 1.f;
|
||||
vWorldPosition *= fViewZ;
|
||||
vWorldPosition = mul(vWorldPosition, g_invmatProj);
|
||||
vWorldPosition = mul(vWorldPosition, g_invMatView);
|
||||
}
|
||||
vLightDir = normalize(vLightDir);
|
||||
vector vSpotDir = normalize(g_vLightDir);
|
||||
float fCosAngle = dot(vLightDir, vSpotDir);
|
||||
|
||||
float3 vWPos = vWorldPosition.xyz;
|
||||
float3 vFromView = normalize(vWPos - g_vCamPosition.xyz); // 카메라에서 픽셀로 가는 방향
|
||||
float3 vFromLight = normalize(g_vLightDir.xyz); // 라이트에서 오는 라이트 벡터
|
||||
|
||||
float3 vF0;
|
||||
float fMetallic;
|
||||
float fRoughness;
|
||||
float fOcclusion;
|
||||
float fAttenuation;
|
||||
{
|
||||
float fDistance = length(vFromLight);
|
||||
fAttenuation = saturate((g_fLightRange - fDistance) / g_fLightRange);
|
||||
if (fAttenuation <= 0.f)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
}
|
||||
float fCosAngle = dot(vFromLight, g_vLightDir.xyz);
|
||||
if (fCosAngle < g_fSpotOuterAngle)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
float fSpotAttenenuation = saturate((fCosAngle - g_fSpotInnerAngle) / (g_fSpotInnerAngle - g_fSpotOuterAngle));
|
||||
float fSpotAttenenuation = saturate((fCosAngle - g_fSpotInnerAngle) / (g_fSpotInnerAngle - g_fSpotOuterAngle));
|
||||
fAttenuation *= fSpotAttenenuation;
|
||||
|
||||
Out.vShade = fAttenuation * (g_vLightDiffuse * saturate(max(dot(vLightDir * -1.f, vNormal), 0.f) + (g_vLightAmbient * g_vMtrlAmbient)));
|
||||
float3 vAlbedo = g_DiffuseTexture.Sample(DefaultSampler, uv).rgb;
|
||||
|
||||
vector vLook = vPosition - g_vCamPosition;
|
||||
vector vReflect = reflect(vLightDir, vNormal);
|
||||
if (true == AlmostEqual3(vDepth.b, AI_TEXTURE_TYPE_METALNESS)) // Metallic
|
||||
{
|
||||
float3 vMRO = g_SurfaceTexture.Sample(DefaultSampler, uv).rgb;
|
||||
fMetallic = vMRO.r;
|
||||
fRoughness = vMRO.g;
|
||||
fOcclusion = vMRO.b;
|
||||
|
||||
vF0 = lerp(float3(0.04f, 0.04f, 0.04f), vAlbedo, fMetallic);
|
||||
}
|
||||
else if (true == AlmostEqual3(vDepth.b, AI_TEXTURE_TYPE_SPECULAR)) // Specular
|
||||
{
|
||||
float3 vSRO = g_SurfaceTexture.Sample(DefaultSampler, uv).rgb;
|
||||
float3 vSpec = vSRO.r;
|
||||
|
||||
fMetallic = 0.f;
|
||||
fRoughness = vSRO.g;
|
||||
fOcclusion = vSRO.b;
|
||||
|
||||
|
||||
vF0 = vSpec.xxx;
|
||||
}
|
||||
else
|
||||
{
|
||||
fMetallic = 0.f;
|
||||
fRoughness = 0.5f;
|
||||
fOcclusion = 1.f;
|
||||
vF0 = float3(0.04f, 0.04f, 0.04f);
|
||||
}
|
||||
|
||||
Out.vSpecular = fAttenuation * ((g_vLightSpecular * g_vMtrlSpecular) * pow(max(dot(normalize(vLook) * -1.f, normalize(vReflect)), 0.f), 50.f));
|
||||
PBR_LIGHT_OUT PBR_Out = PBR_Lighting(vNormal, vFromView, vFromLight, vAlbedo, fMetallic, fRoughness, g_vLightDiffuse.rgb, fAttenuation, vF0);
|
||||
|
||||
Out.vShade = float4(PBR_Out.vShade, 1.f);
|
||||
Out.vSpecular = float4(PBR_Out.vSpecular, 1.f);
|
||||
|
||||
return Out;
|
||||
}
|
||||
@@ -271,107 +388,7 @@ PS_OUT_BACKBUFFER PS_MAIN_COMBINED(PS_IN In)
|
||||
vPosition = mul(vPosition, g_invmatProj);
|
||||
vPosition = mul(vPosition, g_invMatView);
|
||||
vPreShadowPosition = vPosition;
|
||||
/* (로컬위치 * 월드) -> (로컬위치 * 월드 * 광원의 뷰 * 광원의 투영 ) */
|
||||
vPosition = mul(vPosition, g_LightViewMatrix);
|
||||
vPosition = mul(vPosition, g_LightProjMatrix);
|
||||
vPreShadowPosition = mul(vPreShadowPosition, g_PreShadowLightViewMatrix);
|
||||
vPreShadowPosition = mul(vPreShadowPosition, g_PreShadowLightProjMatrix);
|
||||
|
||||
/* (로컬위치 * 월드 * 광원의 뷰 * 광원의 투영 ) -> (로컬위치 * 월드 * 광원의 뷰 * 광원의 투영 * (/w) */
|
||||
float2 vTexcoord, vPreShadowTexcoord;
|
||||
vTexcoord.x = (vPosition.x / vPosition.w) * 0.5f + 0.5f;
|
||||
vTexcoord.y = (vPosition.y / vPosition.w) * -0.5f + 0.5f;
|
||||
vPreShadowTexcoord.x = (vPreShadowPosition.x / vPreShadowPosition.w) * 0.5f + 0.5f;
|
||||
vPreShadowTexcoord.y = (vPreShadowPosition.y / vPreShadowPosition.w) * -0.5f + 0.5f;
|
||||
|
||||
/* 광원의 NDC에서 샘플링 */
|
||||
float fVisibility_Dynamic = ShadowVisibility_hwPCF(g_ShadowTexture, vPosition, float2(g_iMaxShadowWidth, g_iMaxShadowHeight), 0.0005f);
|
||||
float fVisibility_Static = ShadowVisibility_hwPCF(g_PreShadowTexture, vPreShadowPosition, float2(g_iMaxShadowWidth, g_iMaxShadowHeight), 0.0005f);
|
||||
|
||||
Out.vBackBuffer.rgb *= lerp(0.5f, 1.f, min(fVisibility_Dynamic, fVisibility_Static));
|
||||
//float fShadowDepth = g_ShadowTexture.Sample(DefaultSampler, vTexcoord).x;
|
||||
//float fPreShadowDepth = g_PreShadowTexture.Sample(DefaultSampler, vPreShadowTexcoord).x;
|
||||
//bool IsShadow = { false };
|
||||
//if (vPosition.z - 0.0005f > fShadowDepth)
|
||||
//{
|
||||
// IsShadow = true;
|
||||
//}
|
||||
//if (vPreShadowPosition.z - 0.0005f > fPreShadowDepth)
|
||||
//{
|
||||
// IsShadow = true;
|
||||
//}
|
||||
//if (true == IsShadow)
|
||||
//{
|
||||
// Out.vBackBuffer *= 0.5f;
|
||||
//}
|
||||
float4 vColor = 0.f;
|
||||
|
||||
//int iBlurWeight = g_BlurWeightTexture.Sample(ClampSampler, In.vTexcoord).r * 32.f;
|
||||
|
||||
//int iBlurMin;
|
||||
//int iBlurMax;
|
||||
|
||||
//if (iBlurWeight % 2 == 0)
|
||||
//{
|
||||
// iBlurMin = -1 * iBlurWeight / 2;
|
||||
// iBlurMax = iBlurWeight / 2;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// iBlurMin = -iBlurWeight / 2;
|
||||
// iBlurMax = iBlurWeight / 2 + 1;
|
||||
//}
|
||||
|
||||
//[loop] // 변수로 루프돌리려면 반드시 필요함
|
||||
for (int i = -15; i < 16; ++i)
|
||||
{
|
||||
vTexcoord.x = In.vTexcoord.x;
|
||||
vTexcoord.y = In.vTexcoord.y + (float) i / g_vResolution.y;
|
||||
|
||||
vColor += g_fWeights[i + 15] * g_BlurXTexture.Sample(ClampSampler, vTexcoord);
|
||||
}
|
||||
|
||||
Out.vBackBuffer += vColor;
|
||||
|
||||
return Out;
|
||||
}
|
||||
|
||||
PS_OUT_BACKBUFFER PS_MAIN_MROCOMBINED(PS_IN In)
|
||||
{
|
||||
PS_OUT_BACKBUFFER Out;
|
||||
|
||||
vector vDiffuse = g_DiffuseTexture.Sample(DefaultSampler, In.vTexcoord);
|
||||
|
||||
if (0.f == vDiffuse.a)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
|
||||
vector vShade = g_ShadeTexture.Sample(DefaultSampler, In.vTexcoord);
|
||||
|
||||
vector vSpecular = g_SpecularTexture.Sample(DefaultSampler, In.vTexcoord);
|
||||
|
||||
Out.vBackBuffer = vDiffuse * vShade + vSpecular;
|
||||
|
||||
vector vDepthDesc = g_DepthTexture.Sample(DefaultSampler, In.vTexcoord);
|
||||
|
||||
|
||||
float fViewZ = vDepthDesc.y * g_fFar;
|
||||
|
||||
|
||||
vector vPosition, vPreShadowPosition;
|
||||
|
||||
/* (로컬위치 * 월드 * 뷰 * 투영 / w) -> (로컬위치 * 월드) */
|
||||
vPosition.x = In.vTexcoord.x * 2.f - 1.f;
|
||||
vPosition.y = In.vTexcoord.y * -2.f + 1.f;
|
||||
vPosition.z = vDepthDesc.x;
|
||||
vPosition.w = 1.f;
|
||||
|
||||
vPosition = vPosition * fViewZ;
|
||||
|
||||
vPosition = mul(vPosition, g_invmatProj);
|
||||
vPosition = mul(vPosition, g_invMatView);
|
||||
vPreShadowPosition = vPosition;
|
||||
/* (로컬위치 * 월드) -> (로컬위치 * 월드 * 광원의 뷰 * 광원의 투영 ) */
|
||||
vPosition = mul(vPosition, g_LightViewMatrix);
|
||||
vPosition = mul(vPosition, g_LightProjMatrix);
|
||||
@@ -478,7 +495,7 @@ PS_OUT_BLUR_X PS_MAIN_BLUR_X(PS_IN In)
|
||||
vColor += g_fWeights[i + 15] * g_BlurTexture.Sample(ClampSampler, vTexcoord);
|
||||
}
|
||||
|
||||
Out.vBlurX = vColor;
|
||||
Out.vBlurX = vColor;
|
||||
|
||||
return Out;
|
||||
}
|
||||
@@ -486,7 +503,7 @@ PS_OUT_BLUR_X PS_MAIN_BLUR_X(PS_IN In)
|
||||
|
||||
technique11 DefaultTechnique
|
||||
{
|
||||
pass DebugPass
|
||||
pass DebugPass // 0
|
||||
{
|
||||
SetRasterizerState(RS_Default);
|
||||
SetDepthStencilState(DSS_Default, 0);
|
||||
@@ -496,7 +513,7 @@ technique11 DefaultTechnique
|
||||
PixelShader = compile ps_5_0 PS_MAIN_DEBUG();
|
||||
}
|
||||
|
||||
pass DirectionalPass
|
||||
pass DirectionalPass // 1
|
||||
{
|
||||
SetRasterizerState(RS_Default);
|
||||
SetDepthStencilState(DSS_None, 0);
|
||||
@@ -506,7 +523,7 @@ technique11 DefaultTechnique
|
||||
PixelShader = compile ps_5_0 PS_MAIN_DIRECTIONAL();
|
||||
}
|
||||
|
||||
pass PointPass
|
||||
pass PointPass // 2
|
||||
{
|
||||
SetRasterizerState(RS_Default);
|
||||
SetDepthStencilState(DSS_None, 0);
|
||||
@@ -516,7 +533,7 @@ technique11 DefaultTechnique
|
||||
PixelShader = compile ps_5_0 PS_MAIN_POINT();
|
||||
}
|
||||
|
||||
pass CombinedPass
|
||||
pass CombinedPass // 3
|
||||
{
|
||||
SetRasterizerState(RS_Default);
|
||||
SetDepthStencilState(DSS_None, 0);
|
||||
@@ -526,7 +543,7 @@ technique11 DefaultTechnique
|
||||
PixelShader = compile ps_5_0 PS_MAIN_COMBINED();
|
||||
}
|
||||
|
||||
pass BlurPass
|
||||
pass BlurPass // 4
|
||||
{
|
||||
SetRasterizerState(RS_Default);
|
||||
SetDepthStencilState(DSS_None, 0);
|
||||
@@ -536,7 +553,7 @@ technique11 DefaultTechnique
|
||||
PixelShader = compile ps_5_0 PS_MAIN_BLUR_X();
|
||||
}
|
||||
|
||||
pass SpotPass
|
||||
pass SpotPass // 5
|
||||
{
|
||||
SetRasterizerState(RS_Default);
|
||||
SetDepthStencilState(DSS_None, 0);
|
||||
@@ -545,13 +562,4 @@ technique11 DefaultTechnique
|
||||
GeometryShader = NULL;
|
||||
PixelShader = compile ps_5_0 PS_MAIN_SPOT();
|
||||
}
|
||||
pass MROCombinedPass
|
||||
{
|
||||
SetRasterizerState(RS_Default);
|
||||
SetDepthStencilState(DSS_None, 0);
|
||||
SetBlendState(BS_None, float4(0.f, 0.f, 0.f, 0.f), 0xffffffff);
|
||||
VertexShader = compile vs_5_0 VS_MAIN();
|
||||
GeometryShader = NULL;
|
||||
PixelShader = compile ps_5_0 PS_MAIN_MROCOMBINED();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -298,6 +298,7 @@ call Update_Lib.bat
|
||||
<ClCompile Include="..\Private\SoundSrc.cpp" />
|
||||
<ClCompile Include="..\Private\State.cpp" />
|
||||
<ClCompile Include="..\Private\Texture.cpp" />
|
||||
<ClCompile Include="..\Private\ThreadHolder.cpp" />
|
||||
<ClCompile Include="..\Private\Timer.cpp" />
|
||||
<ClCompile Include="..\Private\Timer_Manager.cpp" />
|
||||
<ClCompile Include="..\Private\tinyxml2.cpp">
|
||||
@@ -541,6 +542,7 @@ call Update_Lib.bat
|
||||
<ClInclude Include="..\Public\SoundSrc.h" />
|
||||
<ClInclude Include="..\Public\State.h" />
|
||||
<ClInclude Include="..\Public\Texture.h" />
|
||||
<ClInclude Include="..\Public\ThreadHolder.h" />
|
||||
<ClInclude Include="..\Public\Timer.h" />
|
||||
<ClInclude Include="..\Public\Timer_Manager.h" />
|
||||
<ClInclude Include="..\Public\tinyxml2.h" />
|
||||
@@ -559,9 +561,35 @@ call Update_Lib.bat
|
||||
<ClInclude Include="..\Public\VIBuffer_Terrain.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\Bin\Resources\ShaderFiles\Engine_Shader_Defines.hlsli" />
|
||||
<FxCompile Include="..\Bin\Resources\ShaderFiles\Shader_PBR.hlsl">
|
||||
<FxCompile Include="..\Bin\Resources\ShaderFiles\Engine_Shader_Samplers.hlsli">
|
||||
<FileType>Document</FileType>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
</ExcludedFromBuild>
|
||||
</FxCompile>
|
||||
<FxCompile Include="..\Bin\Resources\ShaderFiles\Engine_Shader_States.hlsli">
|
||||
<FileType>Document</FileType>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
</ExcludedFromBuild>
|
||||
</FxCompile>
|
||||
<FxCompile Include="..\Bin\Resources\ShaderFiles\Engine_Shader_Constants.hlsli">
|
||||
<FileType>Document</FileType>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
</ExcludedFromBuild>
|
||||
</FxCompile>
|
||||
<FxCompile Include="..\Bin\Resources\ShaderFiles\Engine_Shader_Defines.hlsli">
|
||||
<FileType>Document</FileType>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
</ExcludedFromBuild>
|
||||
</FxCompile>
|
||||
<FxCompile Include="..\Bin\Resources\ShaderFiles\Engine_Shader_Functions.hlsli">
|
||||
<FileType>Document</FileType>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
</ExcludedFromBuild>
|
||||
</FxCompile>
|
||||
<FxCompile Include="..\Bin\Resources\ShaderFiles\Engine_Shader_Structures.hlsli">
|
||||
<FileType>Document</FileType>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
</ExcludedFromBuild>
|
||||
</FxCompile>
|
||||
<None Include="..\Public\Assimp\color4.inl" />
|
||||
<None Include="..\Public\Assimp\config.h.in" />
|
||||
|
||||
@@ -277,6 +277,12 @@
|
||||
<Filter Include="02.Element\02.Component\02.VIBuffer\Trail">
|
||||
<UniqueIdentifier>{dae29f0c-1727-4423-a3ca-9ef27460520b}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="99.Define\01.SHADER\Inc">
|
||||
<UniqueIdentifier>{1e10fa90-da5b-4285-a7a3-c4211b4cccbb}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="00.System\02.ThreadHolder">
|
||||
<UniqueIdentifier>{701cf231-2892-4d72-9615-dbe9285c28f4}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\Private\Base.cpp">
|
||||
@@ -525,6 +531,9 @@
|
||||
<ClCompile Include="..\Private\Trail.cpp">
|
||||
<Filter>02.Element\02.Component\02.VIBuffer\Trail</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\Private\ThreadHolder.cpp">
|
||||
<Filter>00.System\02.ThreadHolder</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\Public\Base.h">
|
||||
@@ -1139,6 +1148,9 @@
|
||||
<ClInclude Include="..\Public\Trail.h">
|
||||
<Filter>02.Element\02.Component\02.VIBuffer\Trail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\Public\ThreadHolder.h">
|
||||
<Filter>00.System\02.ThreadHolder</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\Public\Assimp\color4.inl">
|
||||
@@ -1186,9 +1198,6 @@
|
||||
<None Include="..\Public\fMod\fmod_errors.cs">
|
||||
<Filter>99.Define\99.THIRDPARTY\FMOD</Filter>
|
||||
</None>
|
||||
<None Include="..\Bin\Resources\ShaderFiles\Engine_Shader_Defines.hlsli">
|
||||
<Filter>99.Define\01.SHADER</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<FxCompile Include="..\Bin\Resources\ShaderFiles\Shader_Cell.hlsl">
|
||||
@@ -1206,8 +1215,23 @@
|
||||
<FxCompile Include="..\Bin\Resources\ShaderFiles\Shader_WeightBlend.hlsl">
|
||||
<Filter>99.Define\01.SHADER</Filter>
|
||||
</FxCompile>
|
||||
<FxCompile Include="..\Bin\Resources\ShaderFiles\Shader_PBR.hlsl">
|
||||
<Filter>99.Define\01.SHADER</Filter>
|
||||
<FxCompile Include="..\Bin\Resources\ShaderFiles\Engine_Shader_Defines.hlsli">
|
||||
<Filter>99.Define\01.SHADER\Inc</Filter>
|
||||
</FxCompile>
|
||||
<FxCompile Include="..\Bin\Resources\ShaderFiles\Engine_Shader_Constants.hlsli">
|
||||
<Filter>99.Define\01.SHADER\Inc</Filter>
|
||||
</FxCompile>
|
||||
<FxCompile Include="..\Bin\Resources\ShaderFiles\Engine_Shader_Structures.hlsli">
|
||||
<Filter>99.Define\01.SHADER\Inc</Filter>
|
||||
</FxCompile>
|
||||
<FxCompile Include="..\Bin\Resources\ShaderFiles\Engine_Shader_States.hlsli">
|
||||
<Filter>99.Define\01.SHADER\Inc</Filter>
|
||||
</FxCompile>
|
||||
<FxCompile Include="..\Bin\Resources\ShaderFiles\Engine_Shader_Samplers.hlsli">
|
||||
<Filter>99.Define\01.SHADER\Inc</Filter>
|
||||
</FxCompile>
|
||||
<FxCompile Include="..\Bin\Resources\ShaderFiles\Engine_Shader_Functions.hlsli">
|
||||
<Filter>99.Define\01.SHADER\Inc</Filter>
|
||||
</FxCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -12,7 +12,7 @@ CLight::CLight(ID3D11Device* pDevice, ID3D11DeviceContext* pContext)
|
||||
}
|
||||
|
||||
CLight::CLight(const CLight& rhs)
|
||||
: CComponent{ rhs }
|
||||
: CComponent(rhs)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -64,7 +64,7 @@ HRESULT CLight::Render(CShader* pShader, CVIBuffer* pVIBuffer) const
|
||||
if (FAILED(pShader->Bind_RawValue("g_vLightDir", m_LightDesc.pDirection, sizeof(_float4)))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
iPassIndex = ENUM_CLASS(SHADER_PASS_PBR::DIRECTIONAL);
|
||||
iPassIndex = ENUM_CLASS(SHADER_PASS_DEFERRED::DIRECTIONAL);
|
||||
}
|
||||
else if (LIGHT::SPOT == m_LightDesc.eType) {
|
||||
if (FAILED(pShader->Bind_RawValue("g_vLightDir", m_LightDesc.pDirection, sizeof(_float4)))) {
|
||||
@@ -85,7 +85,7 @@ HRESULT CLight::Render(CShader* pShader, CVIBuffer* pVIBuffer) const
|
||||
if (FAILED(pShader->Bind_RawValue("g_fSpotOuterAngle", &m_LightDesc.vSpotAngles.y, sizeof(_float)))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
iPassIndex = ENUM_CLASS(SHADER_PASS_PBR::SPOT);
|
||||
iPassIndex = ENUM_CLASS(SHADER_PASS_DEFERRED::SPOT);
|
||||
}
|
||||
else {
|
||||
if (FAILED(pShader->Bind_RawValue("g_vLightPos", m_LightDesc.pPosition, sizeof(_float4)))) {
|
||||
@@ -97,7 +97,7 @@ HRESULT CLight::Render(CShader* pShader, CVIBuffer* pVIBuffer) const
|
||||
if (FAILED(pShader->Bind_RawValue("g_fLightRange", &m_LightDesc.fRange, sizeof(_float)))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
iPassIndex = ENUM_CLASS(SHADER_PASS_PBR::POINT);
|
||||
iPassIndex = ENUM_CLASS(SHADER_PASS_DEFERRED::POINT);
|
||||
}
|
||||
|
||||
if (FAILED(pShader->Bind_RawValue("g_vLightDiffuse", &m_LightDesc.vDiffuse, sizeof(_float4)))) {
|
||||
|
||||
@@ -220,8 +220,9 @@ HRESULT CMaterial::Read_MaterialFile(const _char* pMaterialFilePath, const _char
|
||||
getline(file, strText);
|
||||
|
||||
// Add Texture
|
||||
if (FAILED(Add_Texture(szTextureFilePath, Type)))
|
||||
if (FAILED(Add_Texture(szTextureFilePath, Type))){
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@@ -250,49 +251,70 @@ HRESULT CMaterial::Add_Texture(const _char* pTextureFolderPath, string& FileType
|
||||
aiTextureType eTexture = {};
|
||||
|
||||
/* Find type */
|
||||
if (!strcmp(FileType.c_str(), "D"))
|
||||
if (!strcmp(FileType.c_str(), "D")){
|
||||
eTexture = aiTextureType::aiTextureType_DIFFUSE;
|
||||
else if (!strcmp(FileType.c_str(), "Diff"))
|
||||
}
|
||||
else if (!strcmp(FileType.c_str(), "Diff")){
|
||||
eTexture = aiTextureType::aiTextureType_DIFFUSE;
|
||||
else if (!strcmp(FileType.c_str(), "d"))
|
||||
}
|
||||
else if (!strcmp(FileType.c_str(), "d")){
|
||||
eTexture = aiTextureType::aiTextureType_DIFFUSE;
|
||||
else if (!strcmp(FileType.c_str(), "N"))
|
||||
}
|
||||
else if (!strcmp(FileType.c_str(), "basecolor")) {
|
||||
eTexture = aiTextureType::aiTextureType_DIFFUSE;
|
||||
}
|
||||
else if (!strcmp(FileType.c_str(), "N")){
|
||||
eTexture = aiTextureType::aiTextureType_NORMALS;
|
||||
else if (!strcmp(FileType.c_str(), "normal"))
|
||||
}
|
||||
else if (!strcmp(FileType.c_str(), "normal")){
|
||||
eTexture = aiTextureType::aiTextureType_NORMALS;
|
||||
else if (!strcmp(FileType.c_str(), "Norm"))
|
||||
}
|
||||
else if (!strcmp(FileType.c_str(), "Norm")){
|
||||
eTexture = aiTextureType::aiTextureType_NORMALS;
|
||||
else if (!strcmp(FileType.c_str(), "n"))
|
||||
}
|
||||
else if (!strcmp(FileType.c_str(), "n")){
|
||||
eTexture = aiTextureType::aiTextureType_NORMALS;
|
||||
else if (!strcmp(FileType.c_str(), "MRO"))
|
||||
}
|
||||
else if (!strcmp(FileType.c_str(), "MRO")){
|
||||
eTexture = aiTextureType::aiTextureType_METALNESS;
|
||||
else if (!strcmp(FileType.c_str(), "3Broom"))
|
||||
}
|
||||
else if (!strcmp(FileType.c_str(), "MROH")){
|
||||
eTexture = aiTextureType::aiTextureType_METALNESS;
|
||||
else if (!strcmp(FileType.c_str(), "MROH"))
|
||||
}
|
||||
else if (!strcmp(FileType.c_str(), "MRAB")){
|
||||
eTexture = aiTextureType::aiTextureType_METALNESS;
|
||||
else if (!strcmp(FileType.c_str(), "MRAB"))
|
||||
}
|
||||
else if (!strcmp(FileType.c_str(), "MROA")){
|
||||
eTexture = aiTextureType::aiTextureType_METALNESS;
|
||||
else if (!strcmp(FileType.c_str(), "MROA"))
|
||||
}
|
||||
else if (!strcmp(FileType.c_str(), "SRO")){
|
||||
eTexture = aiTextureType::aiTextureType_SPECULAR;
|
||||
else if (!strcmp(FileType.c_str(), "SRO"))
|
||||
}
|
||||
else if (!strcmp(FileType.c_str(), "HRO")){
|
||||
eTexture = aiTextureType::aiTextureType_SPECULAR;
|
||||
else if (!strcmp(FileType.c_str(), "HRO"))
|
||||
}
|
||||
else if (!strcmp(FileType.c_str(), "SROH")) {
|
||||
eTexture = aiTextureType::aiTextureType_SPECULAR;
|
||||
else if (!strcmp(FileType.c_str(), "SROH"))
|
||||
eTexture = aiTextureType::aiTextureType_SPECULAR;
|
||||
else if (!strcmp(FileType.c_str(), "SROA"))
|
||||
}
|
||||
else if (!strcmp(FileType.c_str(), "SROA")){
|
||||
eTexture = aiTextureType::aiTextureType_SPECULAR;
|
||||
}
|
||||
else if (!strcmp(FileType.c_str(), "3Broom")) {
|
||||
eTexture = aiTextureType::aiTextureType_UNKNOWN;
|
||||
}
|
||||
else if (!strcmp(FileType.c_str(), "HDR"))
|
||||
return S_OK;
|
||||
else if (!strcmp(FileType.c_str(), "MSK"))
|
||||
else if (!strcmp(FileType.c_str(), "MSK")){
|
||||
eTexture = aiTextureType::aiTextureType_AMBIENT_OCCLUSION;
|
||||
else if (!strcmp(FileType.c_str(), "basecolor"))
|
||||
eTexture = aiTextureType::aiTextureType_DIFFUSE;
|
||||
else if (!strcmp(FileType.c_str(), "E"))
|
||||
}
|
||||
else if (!strcmp(FileType.c_str(), "E")){
|
||||
eTexture = aiTextureType::aiTextureType_EMISSIVE;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifndef 기무리
|
||||
MSG_BOX("Failed to Path Material Texture Type");
|
||||
#endif // !기무리
|
||||
return S_OK;
|
||||
}
|
||||
_char TexturePath[MAX_PATH] = {};
|
||||
@@ -319,8 +341,10 @@ HRESULT CMaterial::Add_Texture(const _char* pTextureFolderPath, string& FileType
|
||||
|
||||
if (FAILED(CreateWICTextureFromFile(m_pDevice, szTextureFilePath_Png, nullptr, &pSRV)))
|
||||
{
|
||||
#ifndef 기무리
|
||||
MSG_BOX("Failed to Load TextureFile");
|
||||
return E_FAIL;
|
||||
#endif // !기무리
|
||||
return S_OK;
|
||||
}
|
||||
strTexturePath = CMyTools::ToString(szTextureFilePath_Png);
|
||||
}
|
||||
@@ -360,25 +384,6 @@ HRESULT CMaterial::Add_Texture(const _char* pTextureFolderPath, string& FileType
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CMaterial::SaveAsBinary(HANDLE hFile, DWORD& dwByte)
|
||||
{
|
||||
// 실제 값을 저장하지 않고 파일이름.확장자명의 문자열을 저장해서 수정하기 편하게 만들기
|
||||
// 대신 리소스를 공유해야함
|
||||
// 텍스쳐를 저장하지 않고
|
||||
// 텍스쳐 경로만 ( "이름.확장자" ) 만 저장함
|
||||
for (int i = 0; i < AI_TEXTURE_TYPE_MAX; ++i) {
|
||||
_uint iNumSrv = (_uint)m_strPath[i].size();
|
||||
WriteFile(hFile, &i, sizeof(_uint), &dwByte, nullptr); // 종류 저장
|
||||
WriteFile(hFile, &iNumSrv, sizeof(_uint), &dwByte, nullptr); // 종류의 갯수 저장
|
||||
for (_uint j = 0; j < iNumSrv; ++j) {
|
||||
m_strPath[i][j].shrink_to_fit();
|
||||
_uint strLength = (_uint)(sizeof(_char) * m_strPath[i][j].length());
|
||||
WriteFile(hFile, &strLength, sizeof(_uint), &dwByte, nullptr); // 사이즈 저장
|
||||
WriteFile(hFile, m_strPath[i][j].data(), strLength, &dwByte, nullptr); // 실제 값 저장
|
||||
}
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
CMaterial* CMaterial::Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, const _char* pModelFilePath, const aiMaterial* pAIMaterial)
|
||||
{
|
||||
CMaterial* pInstance = new CMaterial(pDevice, pContext);
|
||||
@@ -406,15 +411,111 @@ CMaterial* CMaterial::Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContex
|
||||
}
|
||||
#endif
|
||||
|
||||
HRESULT CMaterial::Bind_SRV(CShader* pShader, const _char* pConstantName, _uint iType, _uint iTextureIndex)
|
||||
HRESULT CMaterial::Bind_SRV(CShader* pShader)
|
||||
{
|
||||
if (m_SRVs[iType].empty()) {
|
||||
//assert(false);
|
||||
return S_OK;
|
||||
//if (m_SRVs[iType].empty()) {
|
||||
// //assert(false);
|
||||
// return S_OK;
|
||||
//}
|
||||
|
||||
const _char* pConstantName = "";
|
||||
_float fZero = 0.f;
|
||||
if (FAILED(pShader->Bind_RawValue("g_fUsingSurfaceParams", &fZero, sizeof(_float)))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (FAILED(pShader->Bind_SRV("g_SurfaceParamsTexture", nullptr))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
for (_uint iTextureType = 0; iTextureType < AI_TEXTURE_TYPE_MAX; ++iTextureType) {
|
||||
if (m_SRVs[iTextureType].empty()) {
|
||||
continue;
|
||||
}
|
||||
switch (aiTextureType(iTextureType))
|
||||
{
|
||||
case aiTextureType_NONE:
|
||||
break;
|
||||
case aiTextureType_DIFFUSE:
|
||||
pConstantName = "g_DiffuseTexture";
|
||||
break;
|
||||
case aiTextureType_SPECULAR:
|
||||
{
|
||||
_float fUsingSurfaceParams = ((_float)iTextureType / (_float)AI_TEXTURE_TYPE_MAX);
|
||||
pConstantName = "g_SurfaceParamsTexture";
|
||||
pShader->Bind_RawValue("g_fUsingSurfaceParams", &fUsingSurfaceParams, sizeof(_float));
|
||||
}
|
||||
break;
|
||||
case aiTextureType_AMBIENT:
|
||||
break;
|
||||
case aiTextureType_EMISSIVE:
|
||||
break;
|
||||
case aiTextureType_HEIGHT:
|
||||
break;
|
||||
case aiTextureType_NORMALS:
|
||||
pConstantName = "g_NormalTexture";
|
||||
break;
|
||||
case aiTextureType_SHININESS:
|
||||
{
|
||||
_float fUsingSurfaceParams = ((_float)aiTextureType_METALNESS / (_float)AI_TEXTURE_TYPE_MAX);
|
||||
pConstantName = "g_SurfaceParamsTexture";
|
||||
pShader->Bind_RawValue("g_fUsingSurfaceParams", &fUsingSurfaceParams, sizeof(_float));
|
||||
}
|
||||
break;
|
||||
case aiTextureType_OPACITY:
|
||||
break;
|
||||
case aiTextureType_DISPLACEMENT:
|
||||
break;
|
||||
case aiTextureType_LIGHTMAP:
|
||||
break;
|
||||
case aiTextureType_REFLECTION:
|
||||
break;
|
||||
case aiTextureType_BASE_COLOR:
|
||||
break;
|
||||
case aiTextureType_NORMAL_CAMERA:
|
||||
break;
|
||||
case aiTextureType_EMISSION_COLOR:
|
||||
break;
|
||||
case aiTextureType_METALNESS:
|
||||
{
|
||||
_float fUsingSurfaceParams = ((_float)iTextureType / (_float)AI_TEXTURE_TYPE_MAX);
|
||||
pConstantName = "g_SurfaceParamsTexture";
|
||||
pShader->Bind_RawValue("g_fUsingSurfaceParams", &fUsingSurfaceParams, sizeof(_float));
|
||||
}
|
||||
break;
|
||||
case aiTextureType_DIFFUSE_ROUGHNESS:
|
||||
break;
|
||||
case aiTextureType_AMBIENT_OCCLUSION:
|
||||
break;
|
||||
case aiTextureType_UNKNOWN:
|
||||
break;
|
||||
case aiTextureType_SHEEN:
|
||||
break;
|
||||
case aiTextureType_CLEARCOAT:
|
||||
break;
|
||||
case aiTextureType_TRANSMISSION:
|
||||
break;
|
||||
case aiTextureType_MAYA_BASE:
|
||||
break;
|
||||
case aiTextureType_MAYA_SPECULAR:
|
||||
break;
|
||||
case aiTextureType_MAYA_SPECULAR_COLOR:
|
||||
break;
|
||||
case aiTextureType_MAYA_SPECULAR_ROUGHNESS:
|
||||
break;
|
||||
case aiTextureType_ANISOTROPY:
|
||||
break;
|
||||
case aiTextureType_GLTF_METALLIC_ROUGHNESS:
|
||||
break;
|
||||
case _aiTextureType_Force32Bit:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return pShader->Bind_SRV(pConstantName, m_SRVs[iType][iTextureIndex]);
|
||||
pShader->Bind_SRV(pConstantName, m_SRVs[iTextureType][0]);
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CMaterial::Initialize(const _char* pModelFilePath, const SaveMaterial& _SaveMaterial)
|
||||
@@ -448,8 +549,9 @@ HRESULT CMaterial::Initialize(const _char* pModelFilePath, const SaveMaterial& _
|
||||
hr = CreateWICTextureFromFile(m_pDevice, szPerfectPath, nullptr, &pSRV);
|
||||
}
|
||||
|
||||
if (FAILED(hr))
|
||||
if (FAILED(hr)){
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
m_SRVs[type].push_back(pSRV);
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ void CModel::Change_AnimationIndex(_int iAnimationIndex, _bool bIsLoop, _float f
|
||||
m_pLerpAnim->Begin(m_Bones, LerpStartFrames, LerpEndFrames, fLerpDuration, m_iRootBoneIndex);
|
||||
|
||||
}
|
||||
HRESULT CModel::Bind_Material(_uint iMeshIndex, CShader* pShader, const _char* pConstantName, _uint iType, _uint iTextureIndex)
|
||||
HRESULT CModel::Bind_Material(_uint iMeshIndex, CShader* pShader)
|
||||
{
|
||||
if (iMeshIndex >= m_iNumMeshes) {
|
||||
return E_FAIL;
|
||||
@@ -130,7 +130,7 @@ HRESULT CModel::Bind_Material(_uint iMeshIndex, CShader* pShader, const _char* p
|
||||
if (iMaterialIndex >= m_iNumMaterials) {
|
||||
return E_FAIL;
|
||||
}
|
||||
return m_Materials[iMaterialIndex]->Bind_SRV(pShader, pConstantName, iType, iTextureIndex);
|
||||
return m_Materials[iMaterialIndex]->Bind_SRV(pShader);
|
||||
}
|
||||
|
||||
HRESULT CModel::Bind_BoneMatrices(_uint iMeshIndex, CShader* pShader, const _char* pConstantName)
|
||||
|
||||
@@ -104,24 +104,18 @@ HRESULT CPrototype_Manager::Ready_StaticComponents()
|
||||
|
||||
HRESULT CPrototype_Manager::Ready_EngineAssets()
|
||||
{
|
||||
if (FAILED(Add_Asset_Prototype(g_iStaticLevel, TEXT("FX_DEFERRED"),
|
||||
if (FAILED(Add_Asset_Prototype(g_iStaticLevel, FX_DEFERRED,
|
||||
CShader::Create(m_pDevice, m_pContext, TEXT("../Bin/Resources/ShaderFiles/Shader_Deferred.hlsl"),
|
||||
VTXPOSTEX::Elements, VTXPOSTEX::iNumElements)))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (FAILED(Add_Asset_Prototype(g_iStaticLevel, TEXT("FX_PBR"),
|
||||
CShader::Create(m_pDevice, m_pContext, TEXT("../Bin/Resources/ShaderFiles/Shader_PBR.hlsl"),
|
||||
VTXPOSTEX::Elements, VTXPOSTEX::iNumElements)))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (FAILED(Add_Asset_Prototype(g_iStaticLevel, TEXT("FX_LASTCOLOR"),
|
||||
if (FAILED(Add_Asset_Prototype(g_iStaticLevel, FX_LASTCOLOR,
|
||||
CShader::Create(m_pDevice, m_pContext, TEXT("../Bin/Resources/ShaderFiles/Shader_LastColor.hlsl"),
|
||||
VTXPOSTEX::Elements, VTXPOSTEX::iNumElements)))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (FAILED(Add_Asset_Prototype(g_iStaticLevel, TEXT("FX_WEIGHTBELND"),
|
||||
if (FAILED(Add_Asset_Prototype(g_iStaticLevel, FX_WEIGHTBELND,
|
||||
CShader::Create(m_pDevice, m_pContext, TEXT("../Bin/Resources/ShaderFiles/Shader_WeightBlend.hlsl"),
|
||||
VTXPOSTEX::Elements, VTXPOSTEX::iNumElements)))) {
|
||||
return E_FAIL;
|
||||
|
||||
@@ -185,7 +185,7 @@ void CRenderer::Render_LightAcc()
|
||||
if (FAILED(m_pGameInstance->Bind_RenderTarget(TEXT("Target_Depth"), m_pShader, "g_DepthTexture"))) {
|
||||
return;
|
||||
}
|
||||
if (FAILED(m_pGameInstance->Bind_RenderTarget(TEXT("Target_MRO"), m_pShader, "g_MROTexture"))) {
|
||||
if (FAILED(m_pGameInstance->Bind_RenderTarget(TEXT("Target_Surface"), m_pShader, "g_SurfaceTexture"))) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -270,7 +270,7 @@ void CRenderer::Render_Combined()
|
||||
|
||||
}
|
||||
|
||||
m_pShader->Begin(ENUM_CLASS(SHADER_PASS_PBR::COMBINED));
|
||||
m_pShader->Begin(ENUM_CLASS(SHADER_PASS_DEFERRED::COMBINED));
|
||||
|
||||
m_pVIBuffer->Bind_Resources();
|
||||
m_pVIBuffer->Render();
|
||||
@@ -544,8 +544,8 @@ HRESULT CRenderer::Initialize()
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
/* Target_MRO */
|
||||
if (FAILED(m_pGameInstance->Add_RenderTarget(TEXT("Target_MRO"), (_uint)Viewport.Width, (_uint)Viewport.Height,
|
||||
/* Target_Surface */
|
||||
if (FAILED(m_pGameInstance->Add_RenderTarget(TEXT("Target_Surface"), (_uint)Viewport.Width, (_uint)Viewport.Height,
|
||||
DXGI_FORMAT_R32G32B32A32_FLOAT, _float4(0.0f, 0.f, 0.f, 0.f)))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
@@ -632,7 +632,7 @@ HRESULT CRenderer::Initialize()
|
||||
if (FAILED(m_pGameInstance->Add_MRT(TEXT("MRT_GameObjects"), TEXT("Target_Color")))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
if (FAILED(m_pGameInstance->Add_MRT(TEXT("MRT_GameObjects"), TEXT("Target_MRO")))) {
|
||||
if (FAILED(m_pGameInstance->Add_MRT(TEXT("MRT_GameObjects"), TEXT("Target_Surface")))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
@@ -687,19 +687,19 @@ HRESULT CRenderer::Initialize()
|
||||
|
||||
}
|
||||
|
||||
m_pShader = (CShader*)m_pGameInstance->Clone_Asset_Prototype(g_iStaticLevel, TEXT("FX_PBR"), nullptr, nullptr);
|
||||
m_pShader = (CShader*)m_pGameInstance->Clone_Asset_Prototype(g_iStaticLevel, FX_DEFERRED, nullptr, nullptr);
|
||||
if (nullptr == m_pShader) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
|
||||
m_pLastColorShader = (CShader*)m_pGameInstance->Clone_Asset_Prototype(g_iStaticLevel, TEXT("FX_LASTCOLOR"), nullptr, nullptr);
|
||||
m_pLastColorShader = (CShader*)m_pGameInstance->Clone_Asset_Prototype(g_iStaticLevel, FX_LASTCOLOR, nullptr, nullptr);
|
||||
|
||||
if (nullptr == m_pLastColorShader) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
m_pWeightBlendShader = (CShader*)m_pGameInstance->Clone_Asset_Prototype(g_iStaticLevel, TEXT("FX_WEIGHTBELND"), nullptr, nullptr);
|
||||
m_pWeightBlendShader = (CShader*)m_pGameInstance->Clone_Asset_Prototype(g_iStaticLevel, FX_WEIGHTBELND, nullptr, nullptr);
|
||||
|
||||
if (nullptr == m_pWeightBlendShader) {
|
||||
return E_FAIL;
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
#include "pch.h"
|
||||
|
||||
#include "ThreadHolder.h"
|
||||
|
||||
CThreadHolder::CThreadHolder()
|
||||
{
|
||||
}
|
||||
|
||||
CThreadHolder::~CThreadHolder()
|
||||
{
|
||||
}
|
||||
|
||||
void CThreadHolder::WorkerThread()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
function<void()> job = {};
|
||||
unique_lock<mutex> lock(m_mtxJobQueue);
|
||||
{
|
||||
m_cvJobQueue.wait(lock, [this]() {
|
||||
return !this->m_JobQueue.empty() || m_bStop_All;
|
||||
});
|
||||
if (m_bStop_All && this->m_JobQueue.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
function<void()> job = move(m_JobQueue.front());
|
||||
m_JobQueue.pop();
|
||||
}
|
||||
lock.unlock();
|
||||
|
||||
job();
|
||||
}
|
||||
}
|
||||
|
||||
void CThreadHolder::EnqueueJob(function<void()> job)
|
||||
{
|
||||
if (m_bStop_All) {
|
||||
throw runtime_error("ThreadPool 사용 중지됨");
|
||||
}
|
||||
|
||||
lock_guard<mutex> lock(m_mtxJobQueue);
|
||||
m_JobQueue.push(move(job));
|
||||
|
||||
m_cvJobQueue.notify_one();
|
||||
}
|
||||
|
||||
HRESULT CThreadHolder::Initialize(_uint iSize)
|
||||
{
|
||||
m_bStop_All = false;
|
||||
m_iNumThreads = iSize;
|
||||
m_Workers.reserve(iSize);
|
||||
for (_uint i = 0; i < m_iNumThreads; ++i) {
|
||||
m_Workers.emplace_back([this]() {this->WorkerThread(); });
|
||||
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
CThreadHolder* CThreadHolder::Create(_uint iSize)
|
||||
{
|
||||
CThreadHolder* pInstance = new CThreadHolder();
|
||||
if (FAILED(pInstance->Initialize(iSize))) {
|
||||
SAFE_RELEASE(pInstance);
|
||||
}
|
||||
return pInstance;
|
||||
}
|
||||
|
||||
void CThreadHolder::Free()
|
||||
{
|
||||
__super::Free();
|
||||
}
|
||||
|
||||
void CThreadHolder::Describe_Entity()
|
||||
{
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
---------------------------------------------------------------------------
|
||||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
@@ -35,7 +35,6 @@ enum class NAVI_LINE { AB, BC, CA, END };
|
||||
enum class SHADER_PASS_CELL { DEBUG, END };
|
||||
|
||||
enum class SHADER_PASS_DEFERRED { DEBUG, DIRECTIONAL, POINT, COMBINED, BLUR, SPOT, END };
|
||||
enum class SHADER_PASS_PBR { DEBUG, DIRECTIONAL, POINT, COMBINED, BLUR, SPOT, END };
|
||||
|
||||
enum class QUESTYPE {MAIN, SUB, END};
|
||||
enum class TEXTURE_MOUNT_SLOT0 { NOT_DEFINED, METALLIC, SPECULAR, HEIGHT, END };
|
||||
|
||||
@@ -71,6 +71,11 @@
|
||||
#define PURE = 0
|
||||
#endif
|
||||
|
||||
#define FX_DEFERRED TEXT("FX_DEFERRED")
|
||||
#define FX_LASTCOLOR TEXT("FX_LASTCOLOR")
|
||||
#define FX_WEIGHTBELND TEXT("FX_WEIGHTBELND")
|
||||
|
||||
|
||||
#define SAFE_ADDREF(pInstance) Safe_AddRef(pInstance)
|
||||
#define SAFE_RELEASE(pInstance) Safe_Release(pInstance)
|
||||
|
||||
|
||||
@@ -122,7 +122,7 @@ struct SaveMesh
|
||||
|
||||
struct SaveMaterial
|
||||
{
|
||||
vector<string> Path[27];
|
||||
vector<string> Path[AI_TEXTURE_TYPE_MAX];
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -43,4 +43,4 @@ typedef CXMMATRIX _cmatrix;
|
||||
typedef POINT _point;
|
||||
|
||||
|
||||
NS_END
|
||||
NS_END
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
||||
#include "Base.h"
|
||||
|
||||
@@ -11,7 +11,7 @@ class ENGINE_DLL CMaterial final : public CBase
|
||||
virtual ~CMaterial() = default;
|
||||
|
||||
public:
|
||||
HRESULT Bind_SRV(class CShader* pShader, const _char* pConstantName, _uint iType, _uint iTextureIndex);
|
||||
HRESULT Bind_SRV(class CShader* pShader);
|
||||
SaveMaterial Get_SaveMaterial() { return m_SaveMaterial; }
|
||||
private:
|
||||
class CGameInstance* m_pGameInstance = { nullptr };
|
||||
@@ -25,7 +25,6 @@ class ENGINE_DLL CMaterial final : public CBase
|
||||
public:
|
||||
static CMaterial* Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, const _char* pModelFilePath, const aiMaterial* pAIMaterial);
|
||||
static CMaterial* Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, const _char* pMaterialFilePath, const _char* pTextureFilePath);
|
||||
HRESULT SaveAsBinary(HANDLE hFile, DWORD& dwByte);
|
||||
private:
|
||||
vector<string> m_strPath[AI_TEXTURE_TYPE_MAX];
|
||||
HRESULT Initialize(const _char* pModelFilePath, const aiMaterial* pAIMaterial);
|
||||
@@ -34,15 +33,15 @@ class ENGINE_DLL CMaterial final : public CBase
|
||||
HRESULT Add_Texture(const _char* pTextureFolderPath, string& FileType);
|
||||
#endif // EDITOR_PROJECT
|
||||
|
||||
// 바이너리
|
||||
// 바이너리
|
||||
HRESULT Initialize(const _char* pModelFilePath, const SaveMaterial& _SaveMaterial);
|
||||
//
|
||||
|
||||
public:
|
||||
// 바이너리
|
||||
// 바이너리
|
||||
static CMaterial* Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, const _char* pModelFilePathconst, const SaveMaterial& _SaveMaterial);
|
||||
//
|
||||
virtual void Free() override;
|
||||
};
|
||||
|
||||
NS_END
|
||||
NS_END
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
||||
#include "VIBuffer.h"
|
||||
|
||||
@@ -32,7 +32,7 @@ class ENGINE_DLL CMesh final : public CVIBuffer
|
||||
#endif // EDITOR_PROJECT
|
||||
|
||||
public:
|
||||
//인스턴싱 모델 전용 드로우, 바인딩 함수
|
||||
//인스턴싱 모델 전용 드로우, 바인딩 함수
|
||||
virtual HRESULT Bind_Resources_Instance(ID3D11Buffer* pVBInstance, _uint iInstanceStride, _uint iBufferCount);
|
||||
virtual HRESULT Render_Instance(_uint iNumInstance);
|
||||
|
||||
@@ -41,7 +41,7 @@ class ENGINE_DLL CMesh final : public CVIBuffer
|
||||
virtual HRESULT Initialize(void* pArg) override;
|
||||
HRESULT Ready_VertexBuffer_For_NonAnim(HANDLE hFile, DWORD& dwByte);
|
||||
HRESULT Ready_VertexBuffer_For_Anim(HANDLE hFile, DWORD& dwByte);
|
||||
// 바이너리
|
||||
// 바이너리
|
||||
virtual HRESULT Initialize_Prototype(MODEL eType, const class CModel* pModel, SaveMesh* _SaveMesh, _fmatrix PreTransformMatrix);
|
||||
HRESULT Ready_VertexBuffer_For_NonAnim(SaveMesh* _SaveMesh, _fmatrix PreTransformMatrix);
|
||||
HRESULT Ready_VertexBuffer_For_Anim(const class CModel* pModel, SaveMesh* _SaveMesh);
|
||||
@@ -54,14 +54,14 @@ class ENGINE_DLL CMesh final : public CVIBuffer
|
||||
vector<_int> m_BoneIndices;
|
||||
_float4x4* m_pBoneMatrices = { nullptr };
|
||||
vector<_float4x4> m_offsetMatrices;
|
||||
// 바이너리
|
||||
// 바이너리
|
||||
std::vector<_uint> m_Indices;
|
||||
std::vector<_float3> m_Vertices;
|
||||
//
|
||||
|
||||
public:
|
||||
static CMesh* Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, HANDLE hFile, DWORD& dwByte);
|
||||
// 바이너리
|
||||
// 바이너리
|
||||
static CMesh* Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, MODEL eType, const class CModel* pModel, SaveMesh* _SaveMesh, _fmatrix PreTransformMatrix);
|
||||
//
|
||||
virtual CMesh* Clone(void* pArg, class CGameObject* pOwner = nullptr) override;
|
||||
@@ -69,4 +69,4 @@ class ENGINE_DLL CMesh final : public CVIBuffer
|
||||
void Describe_Entity() override;
|
||||
};
|
||||
|
||||
NS_END
|
||||
NS_END
|
||||
|
||||
@@ -62,7 +62,7 @@ static _int Get_BoneIndex(const _char* pBoneName, vector<class CBone*> Bones); /
|
||||
_matrix Get_BoneMatrix(_uint iBoneIndex);
|
||||
#pragma endregion
|
||||
#pragma region Material
|
||||
HRESULT Bind_Material(_uint iMeshIndex, class CShader* pShader, const _char* pConstantName, _uint iType, _uint iTextureIndex);
|
||||
HRESULT Bind_Material(_uint iMeshIndex, class CShader* pShader);
|
||||
|
||||
#pragma endregion
|
||||
|
||||
|
||||
@@ -27,8 +27,8 @@ class CRenderTarget_Manager final : public CBase
|
||||
|
||||
#ifdef _DEBUG
|
||||
private:
|
||||
_int m_iSizeX = { 100 };
|
||||
_int m_iSizeY = { 100 };
|
||||
_int m_iSizeX = { 200 };
|
||||
_int m_iSizeY = { 200 };
|
||||
#endif // _DEBUG
|
||||
|
||||
private:
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include "Base.h"
|
||||
|
||||
NS_BEGIN(Engine)
|
||||
|
||||
class ENGINE_DLL CThreadHolder final : public CBase
|
||||
{
|
||||
private:
|
||||
CThreadHolder();
|
||||
~CThreadHolder();
|
||||
public:
|
||||
void WorkerThread();
|
||||
void EnqueueJob(function<void()> job);
|
||||
|
||||
private:
|
||||
_uint m_iNumThreads = {};
|
||||
vector<thread> m_Workers = {};
|
||||
|
||||
queue<function<void()>> m_JobQueue = {};
|
||||
condition_variable m_cvJobQueue = {};
|
||||
mutex m_mtxJobQueue = {};
|
||||
|
||||
_bool m_bStop_All = { true };
|
||||
|
||||
private:
|
||||
HRESULT Initialize(_uint iSize);
|
||||
|
||||
|
||||
public:
|
||||
static CThreadHolder* Create(_uint iSize);
|
||||
virtual void Free() override;
|
||||
void Describe_Entity();
|
||||
};
|
||||
|
||||
NS_END
|
||||
@@ -54,6 +54,9 @@ using namespace DirectX;
|
||||
#include <random>
|
||||
#include <fstream>
|
||||
#include <filesystem>
|
||||
#include <Thread>
|
||||
#include <mutex>
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user