objectshaders refactor

This commit is contained in:
turanszkij
2016-02-10 21:54:08 +01:00
parent f33d3b1144
commit 24d6df4dfe
28 changed files with 306 additions and 322 deletions
+13 -15
View File
@@ -843,10 +843,7 @@
<None Include="depthConvertHF.hlsli" />
<None Include="dirLightHF.hlsli" />
<None Include="ditherHF.hlsli" />
<None Include="effectHF_PS.hlsli" />
<None Include="effectHF_PSVS.hlsli" />
<None Include="effectHF_VS.hlsli" />
<None Include="effectInputLayoutHF.hlsli" />
<None Include="objectInputLayoutHF.hlsli" />
<None Include="fogHF.hlsli" />
<None Include="fxaa.hlsli" />
<None Include="gammaHF.hlsli" />
@@ -857,6 +854,7 @@
<None Include="imageHF.hlsli" />
<None Include="lightHF.hlsli" />
<None Include="normalsCompressHF.hlsli" />
<None Include="objectHF.hlsli" />
<None Include="packHF.hlsli" />
<None Include="pointLightHF.hlsli" />
<None Include="postProcessHF.hlsli" />
@@ -1161,7 +1159,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='WinRT|Win32'">
</ExcludedFromBuild>
</FxCompile>
<FxCompile Include="effectDS.hlsl">
<FxCompile Include="objectDS.hlsl">
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">5.0</ShaderModel>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">shaders/%(Filename).cso</ObjectFileOutput>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">5.0</ShaderModel>
@@ -1180,7 +1178,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='WinRT|Win32'">
</ExcludedFromBuild>
</FxCompile>
<FxCompile Include="effectHS.hlsl">
<FxCompile Include="objectHS.hlsl">
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">5.0</ShaderModel>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">shaders/%(Filename).cso</ObjectFileOutput>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">5.0</ShaderModel>
@@ -1199,7 +1197,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='WinRT|Win32'">
</ExcludedFromBuild>
</FxCompile>
<FxCompile Include="effectPS.hlsl">
<FxCompile Include="objectPS.hlsl">
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">4.1</ShaderModel>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">shaders/%(Filename).cso</ObjectFileOutput>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">4.1</ShaderModel>
@@ -1218,7 +1216,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='WinRT|Win32'">
</ExcludedFromBuild>
</FxCompile>
<FxCompile Include="effectPS_blackout.hlsl">
<FxCompile Include="objectPS_blackout.hlsl">
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">4.1</ShaderModel>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">shaders/%(Filename).cso</ObjectFileOutput>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">4.1</ShaderModel>
@@ -1237,7 +1235,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='WinRT|Win32'">
</ExcludedFromBuild>
</FxCompile>
<FxCompile Include="effectPS_forwardSimple.hlsl">
<FxCompile Include="objectPS_forwardSimple.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release_RT|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='WinRT|Win32'">Pixel</ShaderType>
@@ -1256,7 +1254,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='WinRT|Win32'">
</ExcludedFromBuild>
</FxCompile>
<FxCompile Include="effectPS_simplest.hlsl">
<FxCompile Include="objectPS_simplest.hlsl">
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">4.1</ShaderModel>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">shaders/%(Filename).cso</ObjectFileOutput>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">4.1</ShaderModel>
@@ -1275,7 +1273,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='WinRT|Win32'">
</ExcludedFromBuild>
</FxCompile>
<FxCompile Include="effectPS_textureonly.hlsl">
<FxCompile Include="objectPS_textureonly.hlsl">
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">4.1</ShaderModel>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">shaders/%(Filename).cso</ObjectFileOutput>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">4.1</ShaderModel>
@@ -1294,7 +1292,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='WinRT|Win32'">
</ExcludedFromBuild>
</FxCompile>
<FxCompile Include="effectPS_transparent.hlsl">
<FxCompile Include="objectPS_transparent.hlsl">
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">4.1</ShaderModel>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">shaders/%(Filename).cso</ObjectFileOutput>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">4.1</ShaderModel>
@@ -1313,7 +1311,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='WinRT|Win32'">
</ExcludedFromBuild>
</FxCompile>
<FxCompile Include="effectVS.hlsl">
<FxCompile Include="objectVS.hlsl">
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">5.0</ShaderModel>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">shaders/%(Filename).cso</ObjectFileOutput>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">5.0</ShaderModel>
@@ -1332,7 +1330,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='WinRT|Win32'">
</ExcludedFromBuild>
</FxCompile>
<FxCompile Include="effectVS10.hlsl">
<FxCompile Include="objectVS10.hlsl">
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">4.1</ShaderModel>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">shaders/%(Filename).cso</ObjectFileOutput>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">4.1</ShaderModel>
@@ -2304,7 +2302,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='WinRT|Win32'">
</ExcludedFromBuild>
</FxCompile>
<FxCompile Include="effectVS_reflection.hlsl">
<FxCompile Include="objectVS_reflection.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='WinRT|Win32'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType>
+42 -45
View File
@@ -66,6 +66,9 @@
<Filter Include="Resource Mapping">
<UniqueIdentifier>{37e02c00-e217-4c5b-8ecb-d3671f0c4c0c}</UniqueIdentifier>
</Filter>
<Filter Include="shaders\object">
<UniqueIdentifier>{9ddbb33a-3546-4849-930c-65c71e4def34}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Utility\DDSTextureLoader.cpp">
@@ -1840,18 +1843,6 @@
<None Include="depthConvertHF.hlsli">
<Filter>shaders\headers</Filter>
</None>
<None Include="effectHF_PS.hlsli">
<Filter>shaders\headers</Filter>
</None>
<None Include="effectHF_PSVS.hlsli">
<Filter>shaders\headers</Filter>
</None>
<None Include="effectHF_VS.hlsli">
<Filter>shaders\headers</Filter>
</None>
<None Include="effectInputLayoutHF.hlsli">
<Filter>shaders\headers</Filter>
</None>
<None Include="fogHF.hlsli">
<Filter>shaders\headers</Filter>
</None>
@@ -1916,6 +1907,12 @@
<None Include="envMapHF.hlsli">
<Filter>shaders\envmap</Filter>
</None>
<None Include="objectInputLayoutHF.hlsli">
<Filter>shaders\object</Filter>
</None>
<None Include="objectHF.hlsli">
<Filter>shaders\object</Filter>
</None>
</ItemGroup>
<ItemGroup>
<Text Include="..\features.txt" />
@@ -1941,33 +1938,6 @@
<FxCompile Include="decalVS.hlsl">
<Filter>shaders</Filter>
</FxCompile>
<FxCompile Include="effectDS.hlsl">
<Filter>shaders</Filter>
</FxCompile>
<FxCompile Include="effectHS.hlsl">
<Filter>shaders</Filter>
</FxCompile>
<FxCompile Include="effectPS.hlsl">
<Filter>shaders</Filter>
</FxCompile>
<FxCompile Include="effectPS_blackout.hlsl">
<Filter>shaders</Filter>
</FxCompile>
<FxCompile Include="effectPS_simplest.hlsl">
<Filter>shaders</Filter>
</FxCompile>
<FxCompile Include="effectPS_textureonly.hlsl">
<Filter>shaders</Filter>
</FxCompile>
<FxCompile Include="effectPS_transparent.hlsl">
<Filter>shaders</Filter>
</FxCompile>
<FxCompile Include="effectVS.hlsl">
<Filter>shaders</Filter>
</FxCompile>
<FxCompile Include="effectVS10.hlsl">
<Filter>shaders</Filter>
</FxCompile>
<FxCompile Include="fontPS.hlsl">
<Filter>shaders</Filter>
</FxCompile>
@@ -2139,18 +2109,12 @@
<FxCompile Include="fxaa.hlsl">
<Filter>shaders\image</Filter>
</FxCompile>
<FxCompile Include="effectPS_forwardSimple.hlsl">
<Filter>shaders</Filter>
</FxCompile>
<FxCompile Include="ssr.hlsl">
<Filter>shaders\image</Filter>
</FxCompile>
<FxCompile Include="sunPS.hlsl">
<Filter>shaders</Filter>
</FxCompile>
<FxCompile Include="effectVS_reflection.hlsl">
<Filter>shaders</Filter>
</FxCompile>
<FxCompile Include="skyVS_reflection.hlsl">
<Filter>shaders</Filter>
</FxCompile>
@@ -2181,6 +2145,39 @@
<FxCompile Include="envMap_skyGS.hlsl">
<Filter>shaders\envmap</Filter>
</FxCompile>
<FxCompile Include="objectDS.hlsl">
<Filter>shaders\object</Filter>
</FxCompile>
<FxCompile Include="objectHS.hlsl">
<Filter>shaders\object</Filter>
</FxCompile>
<FxCompile Include="objectPS.hlsl">
<Filter>shaders\object</Filter>
</FxCompile>
<FxCompile Include="objectPS_blackout.hlsl">
<Filter>shaders\object</Filter>
</FxCompile>
<FxCompile Include="objectPS_forwardSimple.hlsl">
<Filter>shaders\object</Filter>
</FxCompile>
<FxCompile Include="objectPS_simplest.hlsl">
<Filter>shaders\object</Filter>
</FxCompile>
<FxCompile Include="objectPS_textureonly.hlsl">
<Filter>shaders\object</Filter>
</FxCompile>
<FxCompile Include="objectPS_transparent.hlsl">
<Filter>shaders\object</Filter>
</FxCompile>
<FxCompile Include="objectVS.hlsl">
<Filter>shaders\object</Filter>
</FxCompile>
<FxCompile Include="objectVS_reflection.hlsl">
<Filter>shaders\object</Filter>
</FxCompile>
<FxCompile Include="objectVS10.hlsl">
<Filter>shaders\object</Filter>
</FxCompile>
</ItemGroup>
<ItemGroup>
<Image Include="fonts\basic.dds">
+1 -1
View File
@@ -1,5 +1,5 @@
#include "globals.hlsli"
#include "effectInputLayoutHF.hlsli"
#include "objectInputLayoutHF.hlsli"
struct GS_CUBEMAP_IN
{
-40
View File
@@ -1,40 +0,0 @@
#ifndef _EFFECTHF_PS_
#define _EFFECTHF_PS_
//TextureCube enviroTex:register(t0);
//Texture2D<float4> xTextureRef:register(t1);
//Texture2D<float4> xTextureRefrac:register(t2);
//
//Texture2D<float4> xTextureTex:register(t3);
//Texture2D<float> xTextureMat:register(t4);
//Texture2D<float4> xTextureNor:register(t5);
//Texture2D<float4> xTextureSpe:register(t6);
// texture_0 : texture map
// texture_1 : reflection map
// texture_2 : normal map
// texture_3 : specular map
// texture_4 : displacement map
// texture_5 : reflections
// texture_6 : refractions
// texture_7 : water ripples normal map
#define xTextureMap texture_0
#define xReflectionMap texture_1
#define xNormalMap texture_2
#define xSpecularMap texture_3
#define xDisplacementMap texture_4
#define xReflection texture_5
#define xRefraction texture_6
#define xWaterRipples texture_7
struct PixelOutputType
{
float4 col : SV_TARGET0; // texture_gbuffer0
float4 nor : SV_TARGET1; // texture_gbuffer1
//float4 spe : SV_TARGET2;
float4 vel : SV_TARGET2; // texture_gbuffer2
};
#include "tangentComputeHF.hlsli"
#endif // _EFFECTHF_PS_
-21
View File
@@ -1,21 +0,0 @@
#ifndef _EFFECTHF_PSVS_
#define _EFFECTHF_PSVS_
#include "globals.hlsli"
struct PixelInputType
{
float4 pos : SV_POSITION;
float clip : SV_ClipDistance0;
float2 tex : TEXCOORD0;
float3 nor : NORMAL;
float4 pos2D : SCREENPOSITION;
float3 pos3D : WORLDPOSITION;
float4 pos2DPrev : SCREENPOSITIONPREV;
float4 ReflectionMapSamplingPos : TEXCOORD1;
float ao : AMBIENT_OCCLUSION;
nointerpolation float dither : DITHER;
nointerpolation float3 instanceColor : INSTANCECOLOR;
float3 nor2D : NORMAL2D;
};
#endif // _EFFECTHF_PSVS_
-31
View File
@@ -1,31 +0,0 @@
#ifndef _EFFECTHF_VS_
#define _EFFECTHF_VS_
#include "effectInputLayoutHF.hlsli"
#include "windHF.hlsli"
inline float2x3 tangentBinormal(in float3 normal){
float3 tangent;
float3 binormal;
float3 c1 = cross(normal, float3(0.0, 0.0, 1.0));
float3 c2 = cross(normal, float3(0.0, 1.0, 0.0));
if(length(c1)>length(c2))
{
tangent = c1;
}
else
{
tangent = c2;
}
tangent = normalize(tangent);
binormal = cross(normal, tangent);
binormal = normalize(binormal);
return float2x3(tangent,binormal);
}
#endif // _EFFECTHF_VS_
-103
View File
@@ -1,103 +0,0 @@
#include "effectHF_PS.hlsli"
#include "effectHF_PSVS.hlsli"
#include "globalsHF.hlsli"
#include "ditherHF.hlsli"
PixelOutputType main(PixelInputType PSIn)
{
clip(dither(PSIn.pos.xy) - PSIn.dither);
PixelOutputType Out = (PixelOutputType)0;
float3 normal = normalize(PSIn.nor);
float4 baseColor = g_xMat_diffuseColor;
float4 spec= g_xMat_specular;
float depth = PSIn.pos.z/PSIn.pos.w;
float3 eyevector = normalize(g_xCamera_CamPos - PSIn.pos3D);
float2 ScreenCoord, ScreenCoordPrev;
ScreenCoord.x = PSIn.pos2D.x / PSIn.pos2D.w / 2.0f + 0.5f;
ScreenCoord.y = -PSIn.pos2D.y / PSIn.pos2D.w / 2.0f + 0.5f;
ScreenCoordPrev.x = PSIn.pos2DPrev.x / PSIn.pos2DPrev.w / 2.0f + 0.5f;
ScreenCoordPrev.y = -PSIn.pos2DPrev.y / PSIn.pos2DPrev.w / 2.0f + 0.5f;
PSIn.tex *= g_xMat_texMulAdd.xy;
PSIn.tex += g_xMat_texMulAdd.zw;
[branch]if(g_xMat_hasTex) {
baseColor *= xTextureMap.Sample(sampler_aniso_wrap,PSIn.tex);
}
baseColor.rgb *= PSIn.instanceColor;
ALPHATEST(baseColor.a)
if(depth){
//NORMALMAP
float3 bumpColor=0;
if(g_xMat_hasNor){
float4 nortex = xNormalMap.Sample(sampler_aniso_wrap,PSIn.tex);
if(nortex.a>0){
float3x3 tangentFrame = compute_tangent_frame(normal, eyevector, -PSIn.tex.xy);
bumpColor = 2.0f * nortex.rgb - 1.0f;
//bumpColor.g*=-1;
normal = normalize(mul(bumpColor, tangentFrame));
}
}
//SPECULAR
//if(hasRefNorTexSpe.w){
spec = lerp(spec,xSpecularMap.Sample(sampler_aniso_wrap, PSIn.tex).r, g_xMat_hasSpe);
//}
//ENVIROMENT MAP
float4 envCol=0;
{
uint mip=0;
float2 size;
float mipLevels;
texture_env_global.GetDimensions(mip,size.x,size.y,mipLevels);
float3 ref = normalize(reflect(-eyevector, normal));
envCol = texture_env_global.SampleLevel(sampler_linear_clamp,ref,(1-smoothstep(0,128, g_xMat_specular_power))*mipLevels);
baseColor = lerp(baseColor,envCol, g_xMat_metallic*spec);
}
[branch]if(g_xMat_hasRef){
//REFLECTION
float2 RefTex;
RefTex.x = PSIn.ReflectionMapSamplingPos.x/PSIn.ReflectionMapSamplingPos.w/2.0f + 0.5f;
RefTex.y = -PSIn.ReflectionMapSamplingPos.y/PSIn.ReflectionMapSamplingPos.w/2.0f + 0.5f;
float colorMat = 0;
colorMat = xReflectionMap.SampleLevel(sampler_aniso_wrap,PSIn.tex,0).r;
normal = normalize( lerp(normal,PSIn.nor,pow(abs(colorMat.x),0.02f)) );
float4 colorReflection = xReflection.SampleLevel(sampler_linear_clamp,RefTex+normal.xz,0);
baseColor.rgb=lerp(baseColor.rgb,colorReflection.rgb,colorMat);
}
}
bool unshaded = g_xMat_shadeless;
float properties = unshaded ? RT_UNSHADED : 0.0f;
float2 vel = ScreenCoord - ScreenCoordPrev;
Out.col = float4(baseColor.rgb*(1+ g_xMat_emissive)*PSIn.ao,1);
Out.nor = float4(normal.xyz,properties);
Out.vel = float4(vel, g_xMat_specular_power,spec.a);
return Out;
}
+1 -1
View File
@@ -1,4 +1,4 @@
#include "effectInputLayoutHF.hlsli"
#include "objectInputLayoutHF.hlsli"
#include "envMapHF.hlsli"
VSOut main(Input input)
@@ -1,5 +1,4 @@
#include "effectHF_PSVS.hlsli"
#include "effectHF_VS.hlsli"
#include "objectHF.hlsli"
struct ConstantOutputType
{
+163
View File
@@ -0,0 +1,163 @@
#ifndef _OBJECTSHADER_HF_
#define _OBJECTSHADER_HF_
#include "globals.hlsli"
#include "objectInputLayoutHF.hlsli"
#include "windHF.hlsli"
#include "ditherHF.hlsli"
#include "tangentComputeHF.hlsli"
#include "gammaHF.hlsli"
#include "toonHF.hlsli"
#include "specularHF.hlsli"
#include "depthConvertHF.hlsli"
#include "fogHF.hlsli"
#include "globalsHF.hlsli"
// DEFINITIONS
//////////////////
#define xTextureMap texture_0
#define xReflectionMap texture_1
#define xNormalMap texture_2
#define xSpecularMap texture_3
#define xDisplacementMap texture_4
#define xReflection texture_5
#define xRefraction texture_6
#define xWaterRipples texture_7
struct PixelInputType
{
float4 pos : SV_POSITION;
float clip : SV_ClipDistance0;
float2 tex : TEXCOORD0;
float3 nor : NORMAL;
float4 pos2D : SCREENPOSITION;
float3 pos3D : WORLDPOSITION;
float4 pos2DPrev : SCREENPOSITIONPREV;
float4 ReflectionMapSamplingPos : TEXCOORD1;
float ao : AMBIENT_OCCLUSION;
nointerpolation float dither : DITHER;
nointerpolation float3 instanceColor : INSTANCECOLOR;
float3 nor2D : NORMAL2D;
};
struct PixelOutputType
{
float4 col : SV_TARGET0; // texture_gbuffer0
float4 nor : SV_TARGET1; // texture_gbuffer1
float4 vel : SV_TARGET2; // texture_gbuffer2
};
// METHODS
////////////
inline void BaseColorMapping(in float2 UV, inout float4 baseColor)
{
[branch]if (g_xMat_hasTex) {
baseColor *= xTextureMap.Sample(sampler_aniso_wrap, UV);
}
}
inline void NormalMapping(in float2 UV, in float3 V, inout float3 N)
{
if (g_xMat_hasNor)
{
float3 bumpColor = 0;
float4 nortex = xNormalMap.Sample(sampler_aniso_wrap, UV);
float3x3 tangentFrame = compute_tangent_frame(N, V, -UV);
bumpColor = 2.0f * nortex.rgb - 1.0f;
bumpColor *= nortex.a;
N = normalize(mul(bumpColor, tangentFrame));
}
}
inline void SpecularMapping(in float2 UV, inout float4 specularColor)
{
specularColor = lerp(specularColor, xSpecularMap.Sample(sampler_aniso_wrap, UV).r, g_xMat_hasSpe);
}
inline void PlanarReflection(in float2 UV, in float2 reflectionUV, in float3 N, inout float4 baseColor)
{
[branch]if (g_xMat_hasRef)
{
float colorMat = xReflectionMap.SampleLevel(sampler_aniso_wrap, UV, 0).r;
//normal = normalize(lerp(normal, PSIn.nor, pow(abs(colorMat.x), 0.02f)));
float4 colorReflection = xReflection.SampleLevel(sampler_linear_clamp, reflectionUV + N.xz, 0);
baseColor.rgb = lerp(baseColor.rgb, colorReflection.rgb, colorMat);
}
}
// #define ENVMAP_CAMERA_BLEND
inline void EnvironmentReflection(in float3 N, in float3 V, in float3 P, in float roughness, in float metalness, in float4 specularColor,
inout float4 color)
{
uint mip0 = 0;
float2 size0;
float mipLevels0;
texture_env0.GetDimensions(mip0, size0.x, size0.y, mipLevels0);
uint mip1 = 0;
float2 size1;
float mipLevels1;
texture_env1.GetDimensions(mip1, size1.x, size1.y, mipLevels1);
float3 ref = reflect(V, N);
float4 envCol0 = texture_env0.SampleLevel(sampler_linear_clamp, ref, roughness*mipLevels0);
float4 envCol1 = texture_env1.SampleLevel(sampler_linear_clamp, ref, roughness*mipLevels0);
#ifdef ENVMAP_CAMERA_BLEND
float dist0 = distance(g_xCamera_CamPos, g_xTransform[0].xyz);
float dist1 = distance(g_xCamera_CamPos, g_xTransform[1].xyz);
#else
float dist0 = distance(P, g_xTransform[0].xyz);
float dist1 = distance(P, g_xTransform[1].xyz);
#endif
static const float blendStrength = 0.05f;
float blend = clamp((dist0 - dist1)*blendStrength, -1, 1)*0.5f + 0.5f;
float4 envCol = lerp(envCol0, envCol1, blend);
color.rgb += envCol.rgb * specularColor.rgb * metalness;
}
// MACROS
////////////
#define OBJECT_PS_MAKE \
float3 N = normalize(PSIn.nor); \
float3 P = PSIn.pos3D; \
float3 V = normalize(P - g_xCamera_CamPos); \
float roughness = 1 - (g_xMat_specular_power / 128.0f); \
float metalness = g_xMat_metallic; \
float2 UV = PSIn.tex * g_xMat_texMulAdd.xy + g_xMat_texMulAdd.zw; \
float4 specularColor = g_xMat_specular; \
float2 refUV = float2(1, -1)*PSIn.ReflectionMapSamplingPos.xy / PSIn.ReflectionMapSamplingPos.w / 2.0f + 0.5f; \
float2 ScreenCoord = float2(1, -1) * PSIn.pos2D.xy / PSIn.pos2D.w / 2.0f + 0.5f; \
float2 ScreenCoordPrev = float2(1, -1)*PSIn.pos2DPrev.xy / PSIn.pos2DPrev.w / 2.0f + 0.5f; \
float depth = PSIn.pos.z / PSIn.pos.w; \
float4 baseColor = g_xMat_diffuseColor * float4(PSIn.instanceColor, 1); \
BaseColorMapping(UV, baseColor);
#define OBJECT_PS_MISC \
clip(dither(PSIn.pos.xy) - PSIn.dither); \
ALPHATEST(baseColor.a)
#define OBJECT_PS_NORMALMAPPING \
NormalMapping(UV, V, N);
#define OBJECT_PS_SPECULARMAPPING \
SpecularMapping(UV, specularColor);
#define OBJECT_PS_ENVIRONMENTMAPPING \
EnvironmentReflection(N, V, P, roughness, metalness, specularColor, baseColor);
#define OBJECT_PS_PLANARREFLECTIONS \
PlanarReflection(PSIn.tex, refUV, N, baseColor);
#define OBJECT_PS_OUT_GBUFFER \
bool unshaded = g_xMat_shadeless; \
float properties = unshaded ? RT_UNSHADED : 0.0f; \
PixelOutputType Out = (PixelOutputType)0; \
Out.col = float4(baseColor.rgb*(1 + g_xMat_emissive)*PSIn.ao, 1); \
Out.nor = float4(N.xyz, properties); \
Out.vel = float4(ScreenCoord - ScreenCoordPrev, g_xMat_specular_power, specularColor.a); \
return Out;
#endif // _OBJECTSHADER_HF_
+19
View File
@@ -0,0 +1,19 @@
#include "objectHF.hlsli"
PixelOutputType main(PixelInputType PSIn)
{
OBJECT_PS_MAKE
OBJECT_PS_MISC
OBJECT_PS_NORMALMAPPING
OBJECT_PS_SPECULARMAPPING
OBJECT_PS_ENVIRONMENTMAPPING
OBJECT_PS_PLANARREFLECTIONS
OBJECT_PS_OUT_GBUFFER
}
@@ -1,5 +1,4 @@
#include "effectHF_PS.hlsli"
#include "effectHF_PSVS.hlsli"
#include "objectHF.hlsli"
@@ -1,11 +1,4 @@
#include "effectHF_PS.hlsli"
#include "effectHF_PSVS.hlsli"
#include "gammaHF.hlsli"
#include "toonHF.hlsli"
#include "specularHF.hlsli"
#include "depthConvertHF.hlsli"
#include "fogHF.hlsli"
#include "ditherHF.hlsli"
#include "objectHF.hlsli"
@@ -1,5 +1,4 @@
#include "effectHF_PS.hlsli"
#include "effectHF_PSVS.hlsli"
#include "objectHF.hlsli"
@@ -1,7 +1,4 @@
#include "effectHF_PS.hlsli"
#include "effectHF_PSVS.hlsli"
#include "gammaHF.hlsli"
#include "toonHF.hlsli"
#include "objectHF.hlsli"
@@ -1,9 +1,4 @@
#include "effectHF_PS.hlsli"
#include "effectHF_PSVS.hlsli"
#include "fogHF.hlsli"
#include "depthConvertHF.hlsli"
#include "gammaHF.hlsli"
#include "specularHF.hlsli"
#include "objectHF.hlsli"
float4 main( PixelInputType PSIn) : SV_TARGET
@@ -1,5 +1,4 @@
#include "effectHF_VS.hlsli"
#include "effectHF_PSVS.hlsli"
#include "objectHF.hlsli"
struct HullInputType
{
@@ -1,5 +1,4 @@
#include "effectHF_PSVS.hlsli"
#include "effectHF_VS.hlsli"
#include "objectHF.hlsli"
PixelInputType main(Input input)
@@ -1,5 +1,4 @@
#include "effectHF_PSVS.hlsli"
#include "effectHF_VS.hlsli"
#include "objectHF.hlsli"
PixelInputType main(Input input)
+1 -1
View File
@@ -1,6 +1,6 @@
//#include "skinningHF.hlsli"
#include "windHF.hlsli"
#include "effectInputLayoutHF.hlsli"
#include "objectInputLayoutHF.hlsli"
#include "globals.hlsli"
struct VertextoPixel
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef _SKY_HF_
#define _SKY_HF_
#include "globals.hlsli"
#include "effectHF_PS.hlsli"
#include "objectHF.hlsli"
inline float4 GetSkyColor(in float3 normal)
{
+6 -1
View File
@@ -1,3 +1,6 @@
#ifndef _SPECULAR_HF_
#define _SPECULAR_HF_
#include "toonHF.hlsli"
#include "gammaHF.hlsli"
@@ -32,4 +35,6 @@ inline void applySpecular(inout float4 color, in float4 lightColor, in float3 no
//color.rgb += lightColor.rgb * finalSpec;
//color.rgb *= 1+finalSpec;
}
}
}
#endif // _SPECULAR_HF_
+1 -2
View File
@@ -1,5 +1,4 @@
#include "effectHF_PS.hlsli"
#include "globalsHF.hlsli"
#include "objectHF.hlsli"
#include "globals.hlsli"
struct VSOut {
+1 -2
View File
@@ -1,5 +1,4 @@
#include "effectHF_PS.hlsli"
#include "effectHF_PSVS.hlsli"
#include "objectHF.hlsli"
#include "depthConvertHF.hlsli"
#include "fogHF.hlsli"
#include "gammaHF.hlsli"
+1 -2
View File
@@ -1,5 +1,4 @@
#include "effectHF_PSVS.hlsli"
#include "effectHF_VS.hlsli"
#include "objectHF.hlsli"
PixelInputType main(Input input)
{
+47 -26
View File
@@ -2525,6 +2525,7 @@ void wiRenderer::SetSpotLightShadowProps(int shadowMapCount, int resolution)
}
}
void wiRenderer::DrawWorld(Camera* camera, bool DX11Eff, int tessF, DeviceContext context
, bool BlackOut, bool isReflection, SHADERTYPE shaded
, TextureView refRes, bool grass, GRAPHICSTHREAD thread)
@@ -2536,22 +2537,52 @@ void wiRenderer::DrawWorld(Camera* camera, bool DX11Eff, int tessF, DeviceContex
else return;
if(!culledObjects.empty())
{
//// sort opaques front to back
//vector<Cullable*> sortedObjects(culledObjects.begin(), culledObjects.end());
//for (unsigned int i = 0; i < sortedObjects.size() - 1; ++i)
//{
// for (unsigned int j = 1; j < sortedObjects.size(); ++j)
// {
// if (wiMath::Distance(cam->translation, ((Object*)sortedObjects[i])->translation) >
// wiMath::Distance(cam->translation, ((Object*)sortedObjects[j])->translation))
// {
// Cullable* swap = sortedObjects[i];
// sortedObjects[i] = sortedObjects[j];
// sortedObjects[j] = swap;
// }
// }
//}
{
TextureView envMaps[] = { enviroMap, enviroMap };
XMFLOAT3 envMapPositions[] = { XMFLOAT3(0,0,0),XMFLOAT3(0,0,0) };
if (!GetScene().environmentProbes.empty())
{
// Get the closest probes to the camera and bind to shader
vector<EnvironmentProbe*> sortedEnvProbes;
vector<float> sortedDistances;
sortedEnvProbes.reserve(GetScene().environmentProbes.size());
sortedDistances.reserve(GetScene().environmentProbes.size());
for (unsigned int i = 0; i < GetScene().environmentProbes.size(); ++i)
{
sortedEnvProbes.push_back(GetScene().environmentProbes[i]);
sortedDistances.push_back(wiMath::DistanceSquared(camera->translation, GetScene().environmentProbes[i]->translation));
}
for (unsigned int i = 0; i < sortedEnvProbes.size() - 1; ++i)
{
for (unsigned int j = i + 1; j < sortedEnvProbes.size(); ++j)
{
if (sortedDistances[i] > sortedDistances[j])
{
float swapDist = sortedDistances[i];
sortedDistances[i] = sortedDistances[j];
sortedDistances[j] = swapDist;
EnvironmentProbe* swapProbe = sortedEnvProbes[i];
sortedEnvProbes[i] = sortedEnvProbes[j];
sortedEnvProbes[j] = swapProbe;
}
}
}
for (unsigned int i = 0; i < min(sortedEnvProbes.size(), 2); ++i)
{
envMaps[i] = sortedEnvProbes[i]->cubeMap.shaderResource.front();
envMapPositions[i] = sortedEnvProbes[i]->translation;
}
}
static thread_local MiscCB* envProbeCB = new MiscCB;
envProbeCB->mTransform.r[0] = XMLoadFloat3(&envMapPositions[0]);
envProbeCB->mTransform.r[1] = XMLoadFloat3(&envMapPositions[1]);
envProbeCB->mTransform = XMMatrixTranspose(envProbeCB->mTransform);
UpdateBuffer(constantBuffers[CBTYPE_MISC], envProbeCB, context);
BindTexturePS(envMaps[0], TEXSLOT_ENV0, context);
BindTexturePS(envMaps[1], TEXSLOT_ENV1, context);
for(Cullable* object : culledObjects){
culledRenderer[((Object*)object)->mesh].insert((Object*)object);
@@ -2632,16 +2663,6 @@ void wiRenderer::DrawWorld(Camera* camera, bool DX11Eff, int tessF, DeviceContex
BindRasterizerState(wireRender?rasterizers[RSTYPE_WIRE]:rasterizers[RSTYPE_DOUBLESIDED],context);
int matsiz = mesh->materialIndices.size();
//if(DX11 && tessF){
// static thread_local ConstantBuffer* cb = new ConstantBuffer;
// if(matsiz == 1) (*cb).mDisplace = XMVectorSet(mesh->materials[0]->hasDisplacementMap,0,0,0);
// else if(matsiz == 2) (*cb).mDisplace = XMVectorSet(mesh->materials[0]->hasDisplacementMap,mesh->materials[1]->hasDisplacementMap,0,0);
// else if(matsiz == 3) (*cb).mDisplace = XMVectorSet(mesh->materials[0]->hasDisplacementMap,mesh->materials[1]->hasDisplacementMap,mesh->materials[2]->hasDisplacementMap,0);
// else if(matsiz == 4) (*cb).mDisplace = XMVectorSet(mesh->materials[0]->hasDisplacementMap,mesh->materials[1]->hasDisplacementMap,mesh->materials[2]->hasDisplacementMap,mesh->materials[3]->hasDisplacementMap);
// UpdateBuffer(constantBuffer,cb,context);
//}
int k=0;
for(CulledObjectList::iterator viter=visibleInstances.begin();viter!=visibleInstances.end();++viter){