diff --git a/WickedEngine/WickedEngine.vcxproj b/WickedEngine/WickedEngine.vcxproj index 43c6f6ca2..52f9a48af 100644 --- a/WickedEngine/WickedEngine.vcxproj +++ b/WickedEngine/WickedEngine.vcxproj @@ -843,10 +843,7 @@ - - - - + @@ -857,6 +854,7 @@ + @@ -1161,7 +1159,7 @@ - + 5.0 shaders/%(Filename).cso 5.0 @@ -1180,7 +1178,7 @@ - + 5.0 shaders/%(Filename).cso 5.0 @@ -1199,7 +1197,7 @@ - + 4.1 shaders/%(Filename).cso 4.1 @@ -1218,7 +1216,7 @@ - + 4.1 shaders/%(Filename).cso 4.1 @@ -1237,7 +1235,7 @@ - + Pixel Pixel Pixel @@ -1256,7 +1254,7 @@ - + 4.1 shaders/%(Filename).cso 4.1 @@ -1275,7 +1273,7 @@ - + 4.1 shaders/%(Filename).cso 4.1 @@ -1294,7 +1292,7 @@ - + 4.1 shaders/%(Filename).cso 4.1 @@ -1313,7 +1311,7 @@ - + 5.0 shaders/%(Filename).cso 5.0 @@ -1332,7 +1330,7 @@ - + 4.1 shaders/%(Filename).cso 4.1 @@ -2304,7 +2302,7 @@ - + Vertex Vertex Vertex diff --git a/WickedEngine/WickedEngine.vcxproj.filters b/WickedEngine/WickedEngine.vcxproj.filters index 1ef5ac341..ef194810b 100644 --- a/WickedEngine/WickedEngine.vcxproj.filters +++ b/WickedEngine/WickedEngine.vcxproj.filters @@ -66,6 +66,9 @@ {37e02c00-e217-4c5b-8ecb-d3671f0c4c0c} + + {9ddbb33a-3546-4849-930c-65c71e4def34} + @@ -1840,18 +1843,6 @@ shaders\headers - - shaders\headers - - - shaders\headers - - - shaders\headers - - - shaders\headers - shaders\headers @@ -1916,6 +1907,12 @@ shaders\envmap + + shaders\object + + + shaders\object + @@ -1941,33 +1938,6 @@ shaders - - shaders - - - shaders - - - shaders - - - shaders - - - shaders - - - shaders - - - shaders - - - shaders - - - shaders - shaders @@ -2139,18 +2109,12 @@ shaders\image - - shaders - shaders\image shaders - - shaders - shaders @@ -2181,6 +2145,39 @@ shaders\envmap + + shaders\object + + + shaders\object + + + shaders\object + + + shaders\object + + + shaders\object + + + shaders\object + + + shaders\object + + + shaders\object + + + shaders\object + + + shaders\object + + + shaders\object + diff --git a/WickedEngine/cubeShadowVS.hlsl b/WickedEngine/cubeShadowVS.hlsl index 07a79a5b4..da6f1591b 100644 --- a/WickedEngine/cubeShadowVS.hlsl +++ b/WickedEngine/cubeShadowVS.hlsl @@ -1,5 +1,5 @@ #include "globals.hlsli" -#include "effectInputLayoutHF.hlsli" +#include "objectInputLayoutHF.hlsli" struct GS_CUBEMAP_IN { diff --git a/WickedEngine/effectHF_PS.hlsli b/WickedEngine/effectHF_PS.hlsli deleted file mode 100644 index dbe194bf1..000000000 --- a/WickedEngine/effectHF_PS.hlsli +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef _EFFECTHF_PS_ -#define _EFFECTHF_PS_ - -//TextureCube enviroTex:register(t0); -//Texture2D xTextureRef:register(t1); -//Texture2D xTextureRefrac:register(t2); -// -//Texture2D xTextureTex:register(t3); -//Texture2D xTextureMat:register(t4); -//Texture2D xTextureNor:register(t5); -//Texture2D 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_ diff --git a/WickedEngine/effectHF_PSVS.hlsli b/WickedEngine/effectHF_PSVS.hlsli deleted file mode 100644 index f78de4c88..000000000 --- a/WickedEngine/effectHF_PSVS.hlsli +++ /dev/null @@ -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_ diff --git a/WickedEngine/effectHF_VS.hlsli b/WickedEngine/effectHF_VS.hlsli deleted file mode 100644 index ad7481dbf..000000000 --- a/WickedEngine/effectHF_VS.hlsli +++ /dev/null @@ -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_ diff --git a/WickedEngine/effectPS.hlsl b/WickedEngine/effectPS.hlsl deleted file mode 100644 index 42f038ca6..000000000 --- a/WickedEngine/effectPS.hlsl +++ /dev/null @@ -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; -} - diff --git a/WickedEngine/envMapVS.hlsl b/WickedEngine/envMapVS.hlsl index 153b3fa4d..aa4e0bb5e 100644 --- a/WickedEngine/envMapVS.hlsl +++ b/WickedEngine/envMapVS.hlsl @@ -1,4 +1,4 @@ -#include "effectInputLayoutHF.hlsli" +#include "objectInputLayoutHF.hlsli" #include "envMapHF.hlsli" VSOut main(Input input) diff --git a/WickedEngine/effectDS.hlsl b/WickedEngine/objectDS.hlsl similarity index 98% rename from WickedEngine/effectDS.hlsl rename to WickedEngine/objectDS.hlsl index dd81e89fd..b80b8becd 100644 --- a/WickedEngine/effectDS.hlsl +++ b/WickedEngine/objectDS.hlsl @@ -1,5 +1,4 @@ -#include "effectHF_PSVS.hlsli" -#include "effectHF_VS.hlsli" +#include "objectHF.hlsli" struct ConstantOutputType { diff --git a/WickedEngine/objectHF.hlsli b/WickedEngine/objectHF.hlsli new file mode 100644 index 000000000..a6073d33b --- /dev/null +++ b/WickedEngine/objectHF.hlsli @@ -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_ \ No newline at end of file diff --git a/WickedEngine/effectHS.hlsl b/WickedEngine/objectHS.hlsl similarity index 100% rename from WickedEngine/effectHS.hlsl rename to WickedEngine/objectHS.hlsl diff --git a/WickedEngine/effectInputLayoutHF.hlsli b/WickedEngine/objectInputLayoutHF.hlsli similarity index 100% rename from WickedEngine/effectInputLayoutHF.hlsli rename to WickedEngine/objectInputLayoutHF.hlsli diff --git a/WickedEngine/objectPS.hlsl b/WickedEngine/objectPS.hlsl new file mode 100644 index 000000000..4a5296873 --- /dev/null +++ b/WickedEngine/objectPS.hlsl @@ -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 +} + diff --git a/WickedEngine/effectPS_blackout.hlsl b/WickedEngine/objectPS_blackout.hlsl similarity index 79% rename from WickedEngine/effectPS_blackout.hlsl rename to WickedEngine/objectPS_blackout.hlsl index fcfe70c73..dbff4c82a 100644 --- a/WickedEngine/effectPS_blackout.hlsl +++ b/WickedEngine/objectPS_blackout.hlsl @@ -1,5 +1,4 @@ -#include "effectHF_PS.hlsli" -#include "effectHF_PSVS.hlsli" +#include "objectHF.hlsli" diff --git a/WickedEngine/effectPS_forwardSimple.hlsl b/WickedEngine/objectPS_forwardSimple.hlsl similarity index 89% rename from WickedEngine/effectPS_forwardSimple.hlsl rename to WickedEngine/objectPS_forwardSimple.hlsl index 03b77cf96..5d689516d 100644 --- a/WickedEngine/effectPS_forwardSimple.hlsl +++ b/WickedEngine/objectPS_forwardSimple.hlsl @@ -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" diff --git a/WickedEngine/effectPS_simplest.hlsl b/WickedEngine/objectPS_simplest.hlsl similarity index 57% rename from WickedEngine/effectPS_simplest.hlsl rename to WickedEngine/objectPS_simplest.hlsl index e42638a20..c0ea37cb0 100644 --- a/WickedEngine/effectPS_simplest.hlsl +++ b/WickedEngine/objectPS_simplest.hlsl @@ -1,5 +1,4 @@ -#include "effectHF_PS.hlsli" -#include "effectHF_PSVS.hlsli" +#include "objectHF.hlsli" diff --git a/WickedEngine/effectPS_textureonly.hlsl b/WickedEngine/objectPS_textureonly.hlsl similarity index 76% rename from WickedEngine/effectPS_textureonly.hlsl rename to WickedEngine/objectPS_textureonly.hlsl index c8e80db57..34b55677e 100644 --- a/WickedEngine/effectPS_textureonly.hlsl +++ b/WickedEngine/objectPS_textureonly.hlsl @@ -1,7 +1,4 @@ -#include "effectHF_PS.hlsli" -#include "effectHF_PSVS.hlsli" -#include "gammaHF.hlsli" -#include "toonHF.hlsli" +#include "objectHF.hlsli" diff --git a/WickedEngine/effectPS_transparent.hlsl b/WickedEngine/objectPS_transparent.hlsl similarity index 93% rename from WickedEngine/effectPS_transparent.hlsl rename to WickedEngine/objectPS_transparent.hlsl index 17a2b8ab3..4d50146fc 100644 --- a/WickedEngine/effectPS_transparent.hlsl +++ b/WickedEngine/objectPS_transparent.hlsl @@ -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 diff --git a/WickedEngine/effectVS.hlsl b/WickedEngine/objectVS.hlsl similarity index 92% rename from WickedEngine/effectVS.hlsl rename to WickedEngine/objectVS.hlsl index 4b10d99ec..234c7a926 100644 --- a/WickedEngine/effectVS.hlsl +++ b/WickedEngine/objectVS.hlsl @@ -1,5 +1,4 @@ -#include "effectHF_VS.hlsli" -#include "effectHF_PSVS.hlsli" +#include "objectHF.hlsli" struct HullInputType { diff --git a/WickedEngine/effectVS10.hlsl b/WickedEngine/objectVS10.hlsl similarity index 95% rename from WickedEngine/effectVS10.hlsl rename to WickedEngine/objectVS10.hlsl index 54aae651e..b517c552d 100644 --- a/WickedEngine/effectVS10.hlsl +++ b/WickedEngine/objectVS10.hlsl @@ -1,5 +1,4 @@ -#include "effectHF_PSVS.hlsli" -#include "effectHF_VS.hlsli" +#include "objectHF.hlsli" PixelInputType main(Input input) diff --git a/WickedEngine/effectVS_reflection.hlsl b/WickedEngine/objectVS_reflection.hlsl similarity index 93% rename from WickedEngine/effectVS_reflection.hlsl rename to WickedEngine/objectVS_reflection.hlsl index 72fb482c6..024ac92a8 100644 --- a/WickedEngine/effectVS_reflection.hlsl +++ b/WickedEngine/objectVS_reflection.hlsl @@ -1,5 +1,4 @@ -#include "effectHF_PSVS.hlsli" -#include "effectHF_VS.hlsli" +#include "objectHF.hlsli" PixelInputType main(Input input) diff --git a/WickedEngine/shadowVS.hlsl b/WickedEngine/shadowVS.hlsl index 7b48628f1..a7c87f36b 100644 --- a/WickedEngine/shadowVS.hlsl +++ b/WickedEngine/shadowVS.hlsl @@ -1,6 +1,6 @@ //#include "skinningHF.hlsli" #include "windHF.hlsli" -#include "effectInputLayoutHF.hlsli" +#include "objectInputLayoutHF.hlsli" #include "globals.hlsli" struct VertextoPixel diff --git a/WickedEngine/skyHF.hlsli b/WickedEngine/skyHF.hlsli index 77b847bbb..b4862eda8 100644 --- a/WickedEngine/skyHF.hlsli +++ b/WickedEngine/skyHF.hlsli @@ -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) { diff --git a/WickedEngine/specularHF.hlsli b/WickedEngine/specularHF.hlsli index 8cc4484d5..1f711d190 100644 --- a/WickedEngine/specularHF.hlsli +++ b/WickedEngine/specularHF.hlsli @@ -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; } -} \ No newline at end of file +} + +#endif // _SPECULAR_HF_ diff --git a/WickedEngine/sunPS.hlsl b/WickedEngine/sunPS.hlsl index 744781a0c..3cab7f2f3 100644 --- a/WickedEngine/sunPS.hlsl +++ b/WickedEngine/sunPS.hlsl @@ -1,5 +1,4 @@ -#include "effectHF_PS.hlsli" -#include "globalsHF.hlsli" +#include "objectHF.hlsli" #include "globals.hlsli" struct VSOut { diff --git a/WickedEngine/waterPS.hlsl b/WickedEngine/waterPS.hlsl index e6ccde8a8..cc9844f71 100644 --- a/WickedEngine/waterPS.hlsl +++ b/WickedEngine/waterPS.hlsl @@ -1,5 +1,4 @@ -#include "effectHF_PS.hlsli" -#include "effectHF_PSVS.hlsli" +#include "objectHF.hlsli" #include "depthConvertHF.hlsli" #include "fogHF.hlsli" #include "gammaHF.hlsli" diff --git a/WickedEngine/waterVS.hlsl b/WickedEngine/waterVS.hlsl index 6a312ed61..5763f3b54 100644 --- a/WickedEngine/waterVS.hlsl +++ b/WickedEngine/waterVS.hlsl @@ -1,5 +1,4 @@ -#include "effectHF_PSVS.hlsli" -#include "effectHF_VS.hlsli" +#include "objectHF.hlsli" PixelInputType main(Input input) { diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 2e16a6048..33536d01b 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -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 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 sortedEnvProbes; + vector 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){