diff --git a/WickedEngine/ResourceMapping.h b/WickedEngine/ResourceMapping.h index 6a0361eec..db4e12691 100644 --- a/WickedEngine/ResourceMapping.h +++ b/WickedEngine/ResourceMapping.h @@ -64,13 +64,11 @@ // Skinning: #define SKINNINGSLOT_IN_VERTEX_POS 0 -#define SKINNINGSLOT_IN_VERTEX_NOR 1 -#define SKINNINGSLOT_IN_VERTEX_BON 2 -#define SKINNINGSLOT_IN_BONEBUFFER 3 +#define SKINNINGSLOT_IN_VERTEX_BON 1 +#define SKINNINGSLOT_IN_BONEBUFFER 2 #define SKINNINGSLOT_OUT_VERTEX_POS 0 -#define SKINNINGSLOT_OUT_VERTEX_NOR 1 -#define SKINNINGSLOT_OUT_VERTEX_PRE 2 +#define SKINNINGSLOT_OUT_VERTEX_PRE 1 #endif // _RESOURCEBUFFER_MAPPING_H_ diff --git a/WickedEngine/ShaderInterop_EmittedParticle.h b/WickedEngine/ShaderInterop_EmittedParticle.h index f25f340a7..310688f29 100644 --- a/WickedEngine/ShaderInterop_EmittedParticle.h +++ b/WickedEngine/ShaderInterop_EmittedParticle.h @@ -29,7 +29,6 @@ CBUFFER(EmittedParticleCB, CBSLOT_OTHER_EMITTEDPARTICLE) uint xEmitCount; uint xEmitterMeshIndexCount; uint xEmitterMeshVertexPositionStride; - uint xEmitterMeshVertexNormalStride; float xEmitterRandomness; float xParticleSize; diff --git a/WickedEngine/cubeShadowVS.hlsl b/WickedEngine/cubeShadowVS.hlsl index 0db25d885..81bcf41b1 100644 --- a/WickedEngine/cubeShadowVS.hlsl +++ b/WickedEngine/cubeShadowVS.hlsl @@ -8,16 +8,15 @@ struct GS_CUBEMAP_IN float4 Pos : SV_POSITION; // World position }; -GS_CUBEMAP_IN main(Input_Shadow_POS input) +GS_CUBEMAP_IN main(Input_Object_POS input) { - GS_CUBEMAP_IN Out = (GS_CUBEMAP_IN)0; - + GS_CUBEMAP_IN Out; float4x4 WORLD = MakeWorldMatrixFromInstance(input.instance); + VertexSurface surface = MakeVertexSurfaceFromInput(input); - Out.Pos = mul(float4(input.pos.xyz, 1), WORLD); - affectWind(Out.Pos.xyz, input.pos.w, g_xFrame_Time); - + Out.Pos = mul(surface.position, WORLD); + affectWind(Out.Pos.xyz, surface.wind, g_xFrame_Time); return Out; } \ No newline at end of file diff --git a/WickedEngine/cubeShadowVS_alphatest.hlsl b/WickedEngine/cubeShadowVS_alphatest.hlsl index c672cc17e..28c0aa1b8 100644 --- a/WickedEngine/cubeShadowVS_alphatest.hlsl +++ b/WickedEngine/cubeShadowVS_alphatest.hlsl @@ -9,16 +9,16 @@ struct GS_CUBEMAP_IN float2 Tex : TEXCOORD0; // Texture coord }; -GS_CUBEMAP_IN main(Input_Shadow_POS_TEX input) +GS_CUBEMAP_IN main(Input_Object_POS_TEX input) { - GS_CUBEMAP_IN Out = (GS_CUBEMAP_IN)0; - + GS_CUBEMAP_IN Out; float4x4 WORLD = MakeWorldMatrixFromInstance(input.instance); + VertexSurface surface = MakeVertexSurfaceFromInput(input); - Out.Pos = mul(float4(input.pos.xyz, 1), WORLD); - affectWind(Out.Pos.xyz, input.pos.w, g_xFrame_Time); - Out.Tex = input.tex.xy; + Out.Pos = mul(surface.position, WORLD); + affectWind(Out.Pos.xyz, surface.wind, g_xFrame_Time); + Out.Tex = surface.uv; return Out; diff --git a/WickedEngine/emittedparticle_emitCS.hlsl b/WickedEngine/emittedparticle_emitCS.hlsl index d130bc2e4..d11db0432 100644 --- a/WickedEngine/emittedparticle_emitCS.hlsl +++ b/WickedEngine/emittedparticle_emitCS.hlsl @@ -10,7 +10,6 @@ RWSTRUCTUREDBUFFER(counterBuffer, ParticleCounters, 4); TEXTURE2D(randomTex, float4, TEXSLOT_ONDEMAND0); TYPEDBUFFER(meshIndexBuffer, uint, TEXSLOT_ONDEMAND1); RAWBUFFER(meshVertexBuffer_POS, TEXSLOT_ONDEMAND2); -RAWBUFFER(meshVertexBuffer_NOR, TEXSLOT_ONDEMAND3); [numthreads(THREADCOUNT_EMIT, 1, 1)] @@ -33,25 +32,25 @@ void main(uint3 DTid : SV_DispatchThreadID) uint i2 = meshIndexBuffer[tri * 3 + 2]; // load vertices of triangle from vertex buffer: - float3 pos0 = asfloat(meshVertexBuffer_POS.Load3(i0 * xEmitterMeshVertexPositionStride)); - float3 pos1 = asfloat(meshVertexBuffer_POS.Load3(i1 * xEmitterMeshVertexPositionStride)); - float3 pos2 = asfloat(meshVertexBuffer_POS.Load3(i2 * xEmitterMeshVertexPositionStride)); + float4 pos_nor0 = asfloat(meshVertexBuffer_POS.Load4(i0 * xEmitterMeshVertexPositionStride)); + float4 pos_nor1 = asfloat(meshVertexBuffer_POS.Load4(i1 * xEmitterMeshVertexPositionStride)); + float4 pos_nor2 = asfloat(meshVertexBuffer_POS.Load4(i2 * xEmitterMeshVertexPositionStride)); - uint nor_u = meshVertexBuffer_NOR.Load(i0 * xEmitterMeshVertexNormalStride); + uint nor_u = asuint(pos_nor0.w); float3 nor0; { nor0.x = (float)((nor_u >> 0) & 0x000000FF) / 255.0f * 2.0f - 1.0f; nor0.y = (float)((nor_u >> 8) & 0x000000FF) / 255.0f * 2.0f - 1.0f; nor0.z = (float)((nor_u >> 16) & 0x000000FF) / 255.0f * 2.0f - 1.0f; } - nor_u = meshVertexBuffer_NOR.Load(i1 * xEmitterMeshVertexNormalStride); + nor_u = asuint(pos_nor1.w); float3 nor1; { nor1.x = (float)((nor_u >> 0) & 0x000000FF) / 255.0f * 2.0f - 1.0f; nor1.y = (float)((nor_u >> 8) & 0x000000FF) / 255.0f * 2.0f - 1.0f; nor1.z = (float)((nor_u >> 16) & 0x000000FF) / 255.0f * 2.0f - 1.0f; } - nor_u = meshVertexBuffer_NOR.Load(i2 * xEmitterMeshVertexNormalStride); + nor_u = asuint(pos_nor2.w); float3 nor2; { nor2.x = (float)((nor_u >> 0) & 0x000000FF) / 255.0f * 2.0f - 1.0f; @@ -70,7 +69,7 @@ void main(uint3 DTid : SV_DispatchThreadID) } // compute final surface position on triangle from barycentric coords: - float3 pos = pos0 + f * (pos1 - pos0) + g * (pos2 - pos0); + float3 pos = pos_nor0.xyz + f * (pos_nor1.xyz - pos_nor0.xyz) + g * (pos_nor2.xyz - pos_nor0.xyz); float3 nor = nor0 + f * (nor1 - nor0) + g * (nor2 - nor0); pos = mul(xEmitterWorld, float4(pos, 1)).xyz; nor = normalize(mul((float3x3)xEmitterWorld, nor)); diff --git a/WickedEngine/envMapVS.hlsl b/WickedEngine/envMapVS.hlsl index 151c6167e..980da4cf7 100644 --- a/WickedEngine/envMapVS.hlsl +++ b/WickedEngine/envMapVS.hlsl @@ -7,11 +7,12 @@ VSOut main(Input_Object_ALL input) VSOut Out = (VSOut)0; float4x4 WORLD = MakeWorldMatrixFromInstance(input.instance); - Out.pos = mul(float4(input.pos.xyz, 1), WORLD); - Out.nor = normalize(mul(normalize(input.nor.xyz * 2 - 1), (float3x3)WORLD)); - Out.tex = input.tex.xy; + VertexSurface surface = MakeVertexSurfaceFromInput(input); + + Out.pos = mul(surface.position, WORLD); + Out.nor = normalize(mul(surface.normal, (float3x3)WORLD)); + Out.tex = surface.uv; Out.instanceColor = input.instance.color_dither.rgb; - Out.ao = input.nor.w; return Out; } \ No newline at end of file diff --git a/WickedEngine/objectDS.hlsl b/WickedEngine/objectDS.hlsl index fcdfab5b1..169569006 100644 --- a/WickedEngine/objectDS.hlsl +++ b/WickedEngine/objectDS.hlsl @@ -23,7 +23,7 @@ struct HullOutputType { float3 pos : POSITION; float3 posPrev : POSITIONPREV; - float3 tex : TEXCOORD0; + float2 tex : TEXCOORD0; float4 nor : NORMAL; nointerpolation float3 instanceColor : INSTANCECOLOR; nointerpolation float dither : DITHER; @@ -125,8 +125,6 @@ PixelInputType main(ConstantOutputType input, float3 uvwCoord : SV_DomainLocatio Out.ReflectionMapSamplingPos = mul(vertexPosition, g_xFrame_MainCamera_ReflVP); - Out.ao = vertexNormal.w; - Out.instanceColor = patch[0].instanceColor.rgb; Out.dither = patch[0].dither; diff --git a/WickedEngine/objectHF.hlsli b/WickedEngine/objectHF.hlsli index e179e4508..db922a09b 100644 --- a/WickedEngine/objectHF.hlsli +++ b/WickedEngine/objectHF.hlsli @@ -59,7 +59,6 @@ struct PixelInputType float2 tex : TEXCOORD0; nointerpolation float dither : DITHER; nointerpolation float3 instanceColor : INSTANCECOLOR; - float ao : AMBIENT_OCCLUSION; float3 nor : NORMAL; float4 pos2D : SCREENPOSITION; float3 pos3D : WORLDPOSITION; @@ -300,7 +299,7 @@ inline void TiledLighting(in float2 pixel, in float3 N, in float3 V, in float3 P float sss = g_xMat_subsurfaceScattering; \ float3 bumpColor = 0; \ float depth = input.pos.z; \ - float ao = input.ao; + float ao = 1; #define OBJECT_PS_MAKE \ OBJECT_PS_MAKE_COMMON \ diff --git a/WickedEngine/objectHS.hlsl b/WickedEngine/objectHS.hlsl index 08b2fd9e2..f0d3dcbfe 100644 --- a/WickedEngine/objectHS.hlsl +++ b/WickedEngine/objectHS.hlsl @@ -11,7 +11,7 @@ struct HullInputType { float3 f3Position : POSITION; float3 f3PositionPrev : POSITIONPREV; - float3 tex : TEXCOORD0; + float2 tex : TEXCOORD0; float4 f4Normal : NORMAL; nointerpolation float3 instanceColor : INSTANCECOLOR; nointerpolation float dither : DITHER; @@ -41,7 +41,7 @@ struct HullOutputType { float3 pos : POSITION; float3 posPrev : POSITIONPREV; - float3 tex : TEXCOORD0; + float2 tex : TEXCOORD0; float4 nor : NORMAL; nointerpolation float3 instanceColor : INSTANCECOLOR; nointerpolation float dither : DITHER; diff --git a/WickedEngine/objectInputLayoutHF.hlsli b/WickedEngine/objectInputLayoutHF.hlsli index 72c6090cc..d10eed2a4 100644 --- a/WickedEngine/objectInputLayoutHF.hlsli +++ b/WickedEngine/objectInputLayoutHF.hlsli @@ -15,40 +15,21 @@ struct Input_InstancePrev float4 wiPrev2 : MATIPREV2; }; -struct Input_Shadow_POS -{ - float4 pos : POSITION; - Input_Instance instance; -}; -struct Input_Shadow_POS_TEX -{ - float4 pos : POSITION; - float4 tex : TEXCOORD0; - Input_Instance instance; -}; -struct Input_Skinning -{ - float4 pos : POSITION; - float4 nor : NORMAL; - float4 bon : TEXCOORD0; - float4 wei : TEXCOORD1; -}; struct Input_Object_POS { - float4 pos : POSITION; + float4 pos : POSITION_NORMAL_WIND; Input_Instance instance; }; struct Input_Object_POS_TEX { - float4 pos : POSITION; - float4 tex : TEXCOORD0; + float4 pos : POSITION_NORMAL_WIND; + float2 tex : TEXCOORD0; Input_Instance instance; }; struct Input_Object_ALL { - float4 pos : POSITION; - float4 nor : NORMAL; - float4 tex : TEXCOORD0; + float4 pos : POSITION_NORMAL_WIND; + float2 tex : TEXCOORD0; float4 pre : TEXCOORD1; Input_Instance instance; Input_InstancePrev instancePrev; @@ -73,4 +54,61 @@ inline float4x4 MakeWorldMatrixFromInstance(in Input_InstancePrev input) ); } +struct VertexSurface +{ + float4 position; + float3 normal; + float wind; + float2 uv; + float4 prevPos; +}; +inline VertexSurface MakeVertexSurfaceFromInput(Input_Object_POS input) +{ + VertexSurface surface; + + surface.position = float4(input.pos.xyz, 1); + + uint normal_wind = asuint(input.pos.w); + surface.normal.x = (float)((normal_wind >> 0) & 0x000000FF) / 255.0f * 2.0f - 1.0f; + surface.normal.y = (float)((normal_wind >> 8) & 0x000000FF) / 255.0f * 2.0f - 1.0f; + surface.normal.z = (float)((normal_wind >> 16) & 0x000000FF) / 255.0f * 2.0f - 1.0f; + surface.wind = (float)((normal_wind >> 24) & 0x000000FF) / 255.0f; + + return surface; +} +inline VertexSurface MakeVertexSurfaceFromInput(Input_Object_POS_TEX input) +{ + VertexSurface surface; + + surface.position = float4(input.pos.xyz, 1); + + uint normal_wind = asuint(input.pos.w); + surface.normal.x = (float)((normal_wind >> 0) & 0x000000FF) / 255.0f * 2.0f - 1.0f; + surface.normal.y = (float)((normal_wind >> 8) & 0x000000FF) / 255.0f * 2.0f - 1.0f; + surface.normal.z = (float)((normal_wind >> 16) & 0x000000FF) / 255.0f * 2.0f - 1.0f; + surface.wind = (float)((normal_wind >> 24) & 0x000000FF) / 255.0f; + + surface.uv = input.tex.xy; + + return surface; +} +inline VertexSurface MakeVertexSurfaceFromInput(Input_Object_ALL input) +{ + VertexSurface surface; + + surface.position = float4(input.pos.xyz, 1); + + uint normal_wind = asuint(input.pos.w); + surface.normal.x = (float)((normal_wind >> 0) & 0x000000FF) / 255.0f * 2.0f - 1.0f; + surface.normal.y = (float)((normal_wind >> 8) & 0x000000FF) / 255.0f * 2.0f - 1.0f; + surface.normal.z = (float)((normal_wind >> 16) & 0x000000FF) / 255.0f * 2.0f - 1.0f; + surface.wind = (float)((normal_wind >> 24) & 0x000000FF) / 255.0f; + + surface.uv = input.tex.xy; + + surface.prevPos = float4(input.pre.xyz, 1); + + return surface; +} + #endif // _MESH_INPUT_LAYOUT_HF_ \ No newline at end of file diff --git a/WickedEngine/objectVS_common.hlsl b/WickedEngine/objectVS_common.hlsl index 84f7fae4b..b337e28aa 100644 --- a/WickedEngine/objectVS_common.hlsl +++ b/WickedEngine/objectVS_common.hlsl @@ -4,49 +4,34 @@ PixelInputType main(Input_Object_ALL input) { - PixelInputType Out = (PixelInputType)0; + PixelInputType Out; float4x4 WORLD = MakeWorldMatrixFromInstance(input.instance); float4x4 WORLDPREV = MakeWorldMatrixFromInstance(input.instancePrev); + VertexSurface surface = MakeVertexSurfaceFromInput(input); Out.instanceColor = input.instance.color_dither.rgb; Out.dither = input.instance.color_dither.a; - - float4 pos = float4(input.pos.xyz, 1); - float4 posPrev = float4(input.pre.xyz, 1); - pos = mul( pos,WORLD ); - posPrev = mul(posPrev, WORLDPREV); + surface.position = mul(surface.position, WORLD); + surface.prevPos = mul(surface.prevPos, WORLDPREV); + surface.normal = normalize(mul(surface.normal, (float3x3)WORLD)); - - Out.clip = dot(pos, g_xClipPlane); + Out.clip = dot(surface.position, g_xClipPlane); - float3 normal = mul(input.nor.xyz * 2 - 1, (float3x3)WORLD); - affectWind(pos.xyz, input.pos.w, g_xFrame_Time); - affectWind(posPrev.xyz, input.pos.w, g_xFrame_TimePrev); + affectWind(surface.position.xyz, surface.wind, g_xFrame_Time); + affectWind(surface.prevPos.xyz, surface.wind, g_xFrame_TimePrev); - - //VERTEX OFFSET MOTION BLUR - //if(xMotionBlur.x){ - //float offsetMod = dot(input.nor,vel); - //pos = lerp(pos,posPrev,(offsetMod<0?((1-saturate(offsetMod))*(noiseTex.SampleLevel( sampler_linear_wrap,input.tex.xy,0 ).r)*0.6f):0)); - //} - - Out.pos = Out.pos2D = mul(pos, g_xCamera_VP); - Out.pos2DPrev = mul(posPrev, g_xFrame_MainCamera_PrevVP); - Out.pos3D = pos.xyz; - Out.tex = input.tex.xy; - Out.nor = normalize(normal); + Out.pos = Out.pos2D = mul(surface.position, g_xCamera_VP); + Out.pos2DPrev = mul(surface.prevPos, g_xFrame_MainCamera_PrevVP); + Out.pos3D = surface.position.xyz; + Out.tex = surface.uv; + Out.nor = surface.normal; Out.nor2D = mul(Out.nor.xyz, (float3x3)g_xCamera_VP).xy; - Out.ReflectionMapSamplingPos = mul(pos, g_xFrame_MainCamera_ReflVP); - - - //Out.vel = mul( vel.xyz, g_xCamera_VP ).xyz; - - Out.ao = input.nor.w; + Out.ReflectionMapSamplingPos = mul(surface.position, g_xFrame_MainCamera_ReflVP); return Out; diff --git a/WickedEngine/objectVS_common_tessellation.hlsl b/WickedEngine/objectVS_common_tessellation.hlsl index 13b207a26..bd8c35a1e 100644 --- a/WickedEngine/objectVS_common_tessellation.hlsl +++ b/WickedEngine/objectVS_common_tessellation.hlsl @@ -5,7 +5,7 @@ struct HullInputType { float3 pos : POSITION; float3 posPrev : POSITIONPREV; - float3 tex : TEXCOORD0; + float2 tex : TEXCOORD0; float4 nor : NORMAL; nointerpolation float3 instanceColor : INSTANCECOLOR; nointerpolation float dither : DITHER; @@ -14,29 +14,27 @@ struct HullInputType HullInputType main(Input_Object_ALL input) { - HullInputType Out = (HullInputType)0; + HullInputType Out; float4x4 WORLD = MakeWorldMatrixFromInstance(input.instance); float4x4 WORLDPREV = MakeWorldMatrixFromInstance(input.instancePrev); - - float4 pos = float4(input.pos.xyz, 1); - float4 posPrev = float4(input.pre.xyz, 1); + VertexSurface surface = MakeVertexSurfaceFromInput(input); - pos = mul(pos, WORLD); - posPrev = mul(posPrev, WORLDPREV); + surface.position = mul(surface.position, WORLD); + surface.prevPos = mul(surface.prevPos, WORLDPREV); + surface.normal = normalize(mul(surface.normal, (float3x3)WORLD)); - float3 normal = mul(normalize(input.nor.xyz * 2 - 1), (float3x3)WORLD); - affectWind(pos.xyz, input.pos.w, g_xFrame_Time); - affectWind(posPrev.xyz,input.pos.w, g_xFrame_TimePrev); + affectWind(surface.position.xyz, surface.wind, g_xFrame_Time); + affectWind(surface.prevPos.xyz, surface.wind, g_xFrame_TimePrev); - Out.pos=pos.xyz; - Out.posPrev = posPrev.xyz; - Out.tex=input.tex.xyz; - Out.nor = float4(normalize(normal), input.nor.w); + Out.pos = surface.position.xyz; + Out.posPrev = surface.prevPos.xyz; + Out.tex = surface.uv; + Out.nor = float4(surface.normal, 1); Out.instanceColor = input.instance.color_dither.rgb; Out.dither = input.instance.color_dither.a; diff --git a/WickedEngine/objectVS_debug.hlsl b/WickedEngine/objectVS_debug.hlsl index af0e6de75..e2e15c6ec 100644 --- a/WickedEngine/objectVS_debug.hlsl +++ b/WickedEngine/objectVS_debug.hlsl @@ -1,6 +1,6 @@ #include "globals.hlsli" -float4 main( float4 pos : POSITION ) : SV_POSITION +float4 main(float4 pos : POSITION_NORMAL_WIND) : SV_POSITION { return mul(float4(pos.xyz, 1), g_xTransform); -} \ No newline at end of file +} diff --git a/WickedEngine/objectVS_positionstream.hlsl b/WickedEngine/objectVS_positionstream.hlsl index 14ec0810c..afb80fc64 100644 --- a/WickedEngine/objectVS_positionstream.hlsl +++ b/WickedEngine/objectVS_positionstream.hlsl @@ -1,19 +1,13 @@ #include "objectHF.hlsli" - - float4 main(Input_Object_POS input) : SV_POSITION { - PixelInputType_Simple Out = (PixelInputType_Simple)0; - float4x4 WORLD = MakeWorldMatrixFromInstance(input.instance); + VertexSurface surface = MakeVertexSurfaceFromInput(input); - float4 pos = float4(input.pos.xyz, 1); + surface.position = mul(surface.position, WORLD); - pos = mul(pos, WORLD); + affectWind(surface.position.xyz, surface.wind, g_xFrame_Time); - affectWind(pos.xyz, input.pos.w, g_xFrame_Time); - - - return mul(pos, g_xCamera_VP); + return mul(surface.position, g_xCamera_VP); } diff --git a/WickedEngine/objectVS_simple.hlsl b/WickedEngine/objectVS_simple.hlsl index ea6c66f04..c5f9034b4 100644 --- a/WickedEngine/objectVS_simple.hlsl +++ b/WickedEngine/objectVS_simple.hlsl @@ -1,28 +1,23 @@ #include "objectHF.hlsli" - - PixelInputType_Simple main(Input_Object_POS_TEX input) { - PixelInputType_Simple Out = (PixelInputType_Simple)0; + PixelInputType_Simple Out; float4x4 WORLD = MakeWorldMatrixFromInstance(input.instance); + VertexSurface surface = MakeVertexSurfaceFromInput(input); Out.instanceColor = input.instance.color_dither.rgb; Out.dither = input.instance.color_dither.a; - float4 pos = float4(input.pos.xyz, 1); + surface.position = mul(surface.position, WORLD); - pos = mul(pos, WORLD); + Out.clip = dot(surface.position, g_xClipPlane); - Out.clip = dot(pos, g_xClipPlane); - - affectWind(pos.xyz, input.pos.w, g_xFrame_Time); - - - Out.pos = mul(pos, g_xCamera_VP); - Out.tex = input.tex.xy; + affectWind(surface.position.xyz, surface.wind, g_xFrame_Time); + Out.pos = mul(surface.position, g_xCamera_VP); + Out.tex = surface.uv; return Out; } \ No newline at end of file diff --git a/WickedEngine/objectVS_simple_tessellation.hlsl b/WickedEngine/objectVS_simple_tessellation.hlsl index 1fabbce05..7c7705282 100644 --- a/WickedEngine/objectVS_simple_tessellation.hlsl +++ b/WickedEngine/objectVS_simple_tessellation.hlsl @@ -5,7 +5,7 @@ struct HullInputType { float3 pos : POSITION; float3 posPrev : POSITIONPREV; - float3 tex : TEXCOORD0; + float2 tex : TEXCOORD0; float4 nor : NORMAL; nointerpolation float3 instanceColor : INSTANCECOLOR; nointerpolation float dither : DITHER; @@ -14,24 +14,20 @@ struct HullInputType HullInputType main(Input_Object_ALL input) { - HullInputType Out = (HullInputType)0; - + HullInputType Out; float4x4 WORLD = MakeWorldMatrixFromInstance(input.instance); + VertexSurface surface = MakeVertexSurfaceFromInput(input); - float4 pos = float4(input.pos.xyz, 1); + surface.position = mul(surface.position, WORLD); + surface.normal = normalize(mul(surface.normal, (float3x3)WORLD)); + affectWind(surface.position.xyz, surface.wind, g_xFrame_Time); - pos = mul(pos, WORLD); - affectWind(pos.xyz, input.pos.w, g_xFrame_Time); + Out.pos = surface.position.xyz; + Out.tex = surface.uv; - float3 normal = mul(normalize(input.nor.xyz * 2 - 1), (float3x3)WORLD); - - Out.pos = pos.xyz; - Out.tex = input.tex.xyz; - - // note: simple vs doesn't have normal but this needs it because tessellation is using normal information - Out.nor = float4(normalize(normal), input.nor.w); + Out.nor = float4(surface.normal, 1); // todo: leave these but I'm lazy to create appropriate hull/domain shaders now... Out.posPrev = 0; diff --git a/WickedEngine/objectVS_voxelizer.hlsl b/WickedEngine/objectVS_voxelizer.hlsl index 9647cba71..24ca3524c 100644 --- a/WickedEngine/objectVS_voxelizer.hlsl +++ b/WickedEngine/objectVS_voxelizer.hlsl @@ -10,13 +10,14 @@ struct VSOut VSOut main(Input_Object_ALL input, uint instanceID : SV_INSTANCEID) { - VSOut Out = (VSOut)0; + VSOut Out; float4x4 WORLD = MakeWorldMatrixFromInstance(input.instance); + VertexSurface surface = MakeVertexSurfaceFromInput(input); - Out.pos = mul(float4(input.pos.xyz, 1), WORLD); - Out.nor = normalize(mul(input.nor.xyz * 2 - 1, (float3x3)WORLD)); - Out.tex = input.tex.xy; + Out.pos = mul(surface.position, WORLD); + Out.nor = normalize(mul(surface.normal, (float3x3)WORLD)); + Out.tex = surface.uv; Out.instanceColor = input.instance.color_dither.rgb; return Out; diff --git a/WickedEngine/shadowVS.hlsl b/WickedEngine/shadowVS.hlsl index 691733949..bef38b779 100644 --- a/WickedEngine/shadowVS.hlsl +++ b/WickedEngine/shadowVS.hlsl @@ -5,20 +5,20 @@ struct VertexOut { - float4 pos : SV_POSITION; + float4 pos : SV_POSITION; }; -VertexOut main(Input_Shadow_POS input) +VertexOut main(Input_Object_POS input) { - VertexOut Out = (VertexOut)0; + VertexOut Out; float4x4 WORLD = MakeWorldMatrixFromInstance(input.instance); + VertexSurface surface = MakeVertexSurfaceFromInput(input); - Out.pos = mul(float4(input.pos.xyz, 1), WORLD); - affectWind(Out.pos.xyz, input.pos.w, g_xFrame_Time); + Out.pos = mul(surface.position, WORLD); + affectWind(Out.pos.xyz, surface.wind, g_xFrame_Time); Out.pos = mul(Out.pos, g_xCamera_VP); - return Out; } \ No newline at end of file diff --git a/WickedEngine/shadowVS_alphatest.hlsl b/WickedEngine/shadowVS_alphatest.hlsl index a4e224ddc..a51b74cb2 100644 --- a/WickedEngine/shadowVS_alphatest.hlsl +++ b/WickedEngine/shadowVS_alphatest.hlsl @@ -9,18 +9,18 @@ struct VertexOut float2 tex : TEXCOORD0; }; -VertexOut main(Input_Shadow_POS_TEX input) +VertexOut main(Input_Object_POS_TEX input) { VertexOut Out = (VertexOut)0; float4x4 WORLD = MakeWorldMatrixFromInstance(input.instance); + VertexSurface surface = MakeVertexSurfaceFromInput(input); - Out.pos = mul(float4(input.pos.xyz, 1), WORLD); - affectWind(Out.pos.xyz, input.pos.w, g_xFrame_Time); + Out.pos = mul(surface.position, WORLD); + affectWind(Out.pos.xyz, surface.wind, g_xFrame_Time); Out.pos = mul(Out.pos, g_xCamera_VP); - Out.tex = input.tex.xy; - + Out.tex = surface.uv; return Out; } \ No newline at end of file diff --git a/WickedEngine/skinningCS.hlsl b/WickedEngine/skinningCS.hlsl index 776c824f7..545026594 100644 --- a/WickedEngine/skinningCS.hlsl +++ b/WickedEngine/skinningCS.hlsl @@ -10,16 +10,14 @@ struct Bone STRUCTUREDBUFFER(boneBuffer, Bone, SKINNINGSLOT_IN_BONEBUFFER); RAWBUFFER(vertexBuffer_POS, SKINNINGSLOT_IN_VERTEX_POS); -RAWBUFFER(vertexBuffer_NOR, SKINNINGSLOT_IN_VERTEX_NOR); RAWBUFFER(vertexBuffer_BON, SKINNINGSLOT_IN_VERTEX_BON); RWRAWBUFFER(streamoutBuffer_POS, SKINNINGSLOT_OUT_VERTEX_POS); -RWRAWBUFFER(streamoutBuffer_NOR, SKINNINGSLOT_OUT_VERTEX_NOR); RWRAWBUFFER(streamoutBuffer_PRE, SKINNINGSLOT_OUT_VERTEX_PRE); -inline void Skinning(inout float4 pos, inout float4 nor, in float4 inBon, in float4 inWei) +inline void Skinning(inout float3 pos, inout float3 nor, in float4 inBon, in float4 inWei) { float4 p = 0; float3 n = 0; @@ -52,28 +50,25 @@ inline void Skinning(inout float4 pos, inout float4 nor, in float4 inBon, in flo [numthreads(SKINNING_COMPUTE_THREADCOUNT, 1, 1)] void main(uint3 DTid : SV_DispatchThreadID) { - const uint stride_POS = 16; - const uint stride_NOR = 4; + const uint stride_POS_NOR = 16; const uint stride_BON_IND = 8; const uint stride_BON_WEI = 8; - const uint fetchAddress_POS = DTid.x * stride_POS; - const uint fetchAddress_NOR = DTid.x * stride_NOR; + const uint fetchAddress_POS_NOR = DTid.x * stride_POS_NOR; const uint fetchAddress_BON = DTid.x * (stride_BON_IND + stride_BON_WEI); // Manual type-conversion for pos: - uint4 pos_u = vertexBuffer_POS.Load4(fetchAddress_POS); - float4 pos = asfloat(pos_u); + uint4 pos_nor_u = vertexBuffer_POS.Load4(fetchAddress_POS_NOR); + float3 pos = asfloat(pos_nor_u.xyz); // Manual type-conversion for normal: - uint nor_u = vertexBuffer_NOR.Load(fetchAddress_NOR); float4 nor = 0; { - nor.x = (float)((nor_u >> 0) & 0x000000FF) / 255.0f * 2.0f - 1.0f; - nor.y = (float)((nor_u >> 8) & 0x000000FF) / 255.0f * 2.0f - 1.0f; - nor.z = (float)((nor_u >> 16) & 0x000000FF) / 255.0f * 2.0f - 1.0f; - nor.w = (float)((nor_u >> 24) & 0x000000FF) / 255.0f; // occlusion + nor.x = (float)((pos_nor_u.w >> 0) & 0x000000FF) / 255.0f * 2.0f - 1.0f; + nor.y = (float)((pos_nor_u.w >> 8) & 0x000000FF) / 255.0f * 2.0f - 1.0f; + nor.z = (float)((pos_nor_u.w >> 16) & 0x000000FF) / 255.0f * 2.0f - 1.0f; + nor.w = (float)((pos_nor_u.w >> 24) & 0x000000FF) / 255.0f; // wind } @@ -95,25 +90,24 @@ void main(uint3 DTid : SV_DispatchThreadID) // Perform skinning: - Skinning(pos, nor, ind, wei); + Skinning(pos, nor.xyz, ind, wei); // Manual type-conversion for pos: - pos_u = asuint(pos); + pos_nor_u.xyz = asuint(pos.xyz); // Manual type-conversion for normal: - nor_u = 0; + pos_nor_u.w = 0; { - nor_u |= (uint)((nor.x * 0.5f + 0.5f) * 255.0f) << 0; - nor_u |= (uint)((nor.y * 0.5f + 0.5f) * 255.0f) << 8; - nor_u |= (uint)((nor.z * 0.5f + 0.5f) * 255.0f) << 16; - nor_u |= (uint)(nor.w * 255.0f) << 24; // occlusion + pos_nor_u.w |= (uint)((nor.x * 0.5f + 0.5f) * 255.0f) << 0; + pos_nor_u.w |= (uint)((nor.y * 0.5f + 0.5f) * 255.0f) << 8; + pos_nor_u.w |= (uint)((nor.z * 0.5f + 0.5f) * 255.0f) << 16; + pos_nor_u.w |= (uint)(nor.w * 255.0f) << 24; // wind } // Store data: - streamoutBuffer_PRE.Store4(fetchAddress_POS, streamoutBuffer_POS.Load4(fetchAddress_POS)); // copy prev frame current pos to current frame prev pos - streamoutBuffer_POS.Store4(fetchAddress_POS, pos_u); - streamoutBuffer_NOR.Store(fetchAddress_NOR, nor_u); + streamoutBuffer_PRE.Store4(fetchAddress_POS_NOR, streamoutBuffer_POS.Load4(fetchAddress_POS_NOR)); // copy prev frame current pos to current frame prev pos + streamoutBuffer_POS.Store4(fetchAddress_POS_NOR, pos_nor_u); } \ No newline at end of file diff --git a/WickedEngine/waterVS.hlsl b/WickedEngine/waterVS.hlsl index a597f9a3b..5d58b9156 100644 --- a/WickedEngine/waterVS.hlsl +++ b/WickedEngine/waterVS.hlsl @@ -5,24 +5,20 @@ PixelInputType main(Input_Object_ALL input) PixelInputType Out = (PixelInputType)0; float4x4 WORLD = MakeWorldMatrixFromInstance(input.instance); + VertexSurface surface = MakeVertexSurfaceFromInput(input); - float4 pos = float4(input.pos.xyz, 1); - pos = mul(pos, WORLD); + surface.position = mul(surface.position, WORLD); - Out.pos = Out.pos2D = mul(pos, g_xCamera_VP); - Out.pos3D = pos.xyz; - Out.tex = input.tex.xy; - Out.nor = mul(input.nor.xyz * 2 - 1, (float3x3)WORLD); - Out.nor = normalize(Out.nor); + Out.pos3D = surface.position.xyz; + Out.pos = Out.pos2D = mul(surface.position, g_xCamera_VP); + Out.tex = surface.uv; + Out.nor = normalize(mul(surface.normal, (float3x3)WORLD)); Out.nor2D = mul(Out.nor.xyz, (float3x3)g_xCamera_VP).xy; - - Out.ReflectionMapSamplingPos = mul(pos, g_xFrame_MainCamera_ReflVP); + Out.ReflectionMapSamplingPos = mul(surface.position, g_xFrame_MainCamera_ReflVP); Out.instanceColor = input.instance.color_dither.rgb; Out.dither = input.instance.color_dither.a; - Out.ao = 1; - return Out; } \ No newline at end of file diff --git a/WickedEngine/wiBULLET.cpp b/WickedEngine/wiBULLET.cpp index aa24c4520..1a29a671b 100644 --- a/WickedEngine/wiBULLET.cpp +++ b/WickedEngine/wiBULLET.cpp @@ -595,7 +595,7 @@ void wiBULLET::connectVerticesToSoftBody(Mesh* const mesh, int objectI){ mesh->vertices_Transformed_POS[i].pos.x = nodes[indexP].m_x.getX(); mesh->vertices_Transformed_POS[i].pos.y = nodes[indexP].m_x.getY(); mesh->vertices_Transformed_POS[i].pos.z = nodes[indexP].m_x.getZ(); - mesh->vertices_Transformed_NOR[i].FromFLOAT(XMFLOAT3(-nodes[indexP].m_n.getX(), -nodes[indexP].m_n.getY(), -nodes[indexP].m_n.getZ())); + mesh->vertices_Transformed_POS[i].NORWINDFromFloat(XMFLOAT3(-nodes[indexP].m_n.getX(), -nodes[indexP].m_n.getY(), -nodes[indexP].m_n.getZ()), 0); } } } @@ -707,7 +707,7 @@ void wiBULLET::registerObject(Object* object){ pos_stream[i].x = object->mesh->vertices_POS[i].pos.x; pos_stream[i].y = object->mesh->vertices_POS[i].pos.y; pos_stream[i].z = object->mesh->vertices_POS[i].pos.z; - pos_stream[i].w = object->mesh->vertices_POS[i].pos.w; + pos_stream[i].w = 1; } addConvexHull( @@ -725,7 +725,7 @@ void wiBULLET::registerObject(Object* object){ pos_stream[i].x = object->mesh->vertices_POS[i].pos.x; pos_stream[i].y = object->mesh->vertices_POS[i].pos.y; pos_stream[i].z = object->mesh->vertices_POS[i].pos.z; - pos_stream[i].w = object->mesh->vertices_POS[i].pos.w; + pos_stream[i].w = 1; } addTriangleMesh( diff --git a/WickedEngine/wiEmittedParticle.cpp b/WickedEngine/wiEmittedParticle.cpp index f80367cdd..22bc78510 100644 --- a/WickedEngine/wiEmittedParticle.cpp +++ b/WickedEngine/wiEmittedParticle.cpp @@ -283,7 +283,6 @@ void wiEmittedParticle::UpdateRenderData(GRAPHICSTHREAD threadID) cb.xEmitCount = (UINT)emit; cb.xEmitterMeshIndexCount = (UINT)object->mesh->indices.size(); cb.xEmitterMeshVertexPositionStride = sizeof(Mesh::Vertex_POS); - cb.xEmitterMeshVertexNormalStride = sizeof(Mesh::Vertex_NOR); cb.xEmitterRandomness = wiRandom::getRandom(0, 1000) * 0.001f; cb.xParticleLifeSpan = life / 60.0f; cb.xParticleLifeSpanRandomness = random_life; @@ -313,7 +312,6 @@ void wiEmittedParticle::UpdateRenderData(GRAPHICSTHREAD threadID) wiTextureHelper::getInstance()->getRandom64x64(), &object->mesh->indexBuffer, &object->mesh->vertexBuffer_POS, - &object->mesh->vertexBuffer_NOR, }; device->BindResourcesCS(resources, TEXSLOT_ONDEMAND0, ARRAYSIZE(resources), threadID); diff --git a/WickedEngine/wiLoader.cpp b/WickedEngine/wiLoader.cpp index 878a3fd10..4a81e3b15 100644 --- a/WickedEngine/wiLoader.cpp +++ b/WickedEngine/wiLoader.cpp @@ -1665,9 +1665,7 @@ void VertexGroup::Serialize(wiArchive& archive) #pragma region MESH -//GPUBuffer Mesh::impostorVBs[VPROP_COUNT]; GPUBuffer Mesh::impostorVB_POS; -GPUBuffer Mesh::impostorVB_NOR; GPUBuffer Mesh::impostorVB_TEX; void Mesh::LoadFromFile(const std::string& newName, const std::string& fname @@ -2024,10 +2022,6 @@ void Mesh::CreateBuffers(Object* object) bd.ByteWidth = (UINT)(sizeof(Vertex_POS) * vertices_POS.size()); wiRenderer::GetDevice()->CreateBuffer(&bd, &InitData, &vertexBuffer_POS); - InitData.pSysMem = vertices_NOR.data(); - bd.ByteWidth = (UINT)(sizeof(Vertex_NOR) * vertices_NOR.size()); - wiRenderer::GetDevice()->CreateBuffer(&bd, &InitData, &vertexBuffer_NOR); - InitData.pSysMem = vertices_BON.data(); bd.ByteWidth = (UINT)(sizeof(Vertex_BON) * vertices_BON.size()); wiRenderer::GetDevice()->CreateBuffer(&bd, &InitData, &vertexBuffer_BON); @@ -2042,9 +2036,6 @@ void Mesh::CreateBuffers(Object* object) bd.ByteWidth = (UINT)(sizeof(Vertex_POS) * vertices_POS.size()); wiRenderer::GetDevice()->CreateBuffer(&bd, nullptr, &streamoutBuffer_POS); - bd.ByteWidth = (UINT)(sizeof(Vertex_NOR) * vertices_NOR.size()); - wiRenderer::GetDevice()->CreateBuffer(&bd, nullptr, &streamoutBuffer_NOR); - bd.ByteWidth = (UINT)(sizeof(Vertex_POS) * vertices_POS.size()); wiRenderer::GetDevice()->CreateBuffer(&bd, nullptr, &streamoutBuffer_PRE); } @@ -2299,12 +2290,10 @@ void Mesh::CreateImpostorVB() Vertex_POS impostorVertices_POS[ARRAYSIZE(impostorVertices)]; - Vertex_NOR impostorVertices_NOR[ARRAYSIZE(impostorVertices)]; Vertex_TEX impostorVertices_TEX[ARRAYSIZE(impostorVertices)]; for (int i = 0; i < ARRAYSIZE(impostorVertices); ++i) { impostorVertices_POS[i] = Vertex_POS(impostorVertices[i]); - impostorVertices_NOR[i] = Vertex_NOR(impostorVertices[i]); impostorVertices_TEX[i] = Vertex_TEX(impostorVertices[i]); } @@ -2319,9 +2308,6 @@ void Mesh::CreateImpostorVB() InitData.pSysMem = impostorVertices_POS; bd.ByteWidth = sizeof(impostorVertices_POS); wiRenderer::GetDevice()->CreateBuffer(&bd, &InitData, &impostorVB_POS); - InitData.pSysMem = impostorVertices_NOR; - bd.ByteWidth = sizeof(impostorVertices_NOR); - wiRenderer::GetDevice()->CreateBuffer(&bd, &InitData, &impostorVB_NOR); InitData.pSysMem = impostorVertices_TEX; bd.ByteWidth = sizeof(impostorVertices_TEX); wiRenderer::GetDevice()->CreateBuffer(&bd, &InitData, &impostorVB_TEX); @@ -2336,7 +2322,6 @@ void Mesh::CreateVertexArrays() // De-interleave vertex arrays: vertices_POS.resize(vertices_FULL.size()); - vertices_NOR.resize(vertices_FULL.size()); vertices_TEX.resize(vertices_FULL.size()); vertices_BON.resize(vertices_FULL.size()); for (size_t i = 0; i < vertices_FULL.size(); ++i) @@ -2361,14 +2346,12 @@ void Mesh::CreateVertexArrays() // Split and type conversion: vertices_POS[i] = Vertex_POS(vertices_FULL[i]); - vertices_NOR[i] = Vertex_NOR(vertices_FULL[i]); vertices_TEX[i] = Vertex_TEX(vertices_FULL[i]); vertices_BON[i] = Vertex_BON(vertices_FULL[i]); } // Save original vertices. This will be input for CPU skinning / soft bodies vertices_Transformed_POS = vertices_POS; - vertices_Transformed_NOR = vertices_NOR; vertices_Transformed_PRE = vertices_POS; // pre <- pos!! // Map subset indices: diff --git a/WickedEngine/wiLoader.h b/WickedEngine/wiLoader.h index 39dbaff14..6dc4cbbc9 100644 --- a/WickedEngine/wiLoader.h +++ b/WickedEngine/wiLoader.h @@ -253,7 +253,7 @@ public: struct Vertex_FULL { XMFLOAT4 pos; //pos, wind - XMFLOAT4 nor; //normal, vertex ao + XMFLOAT4 nor; //normal, unused XMFLOAT4 tex; //tex, matIndex, unused XMFLOAT4 ind; //bone indices XMFLOAT4 wei; //bone weights @@ -275,70 +275,58 @@ public: }; struct Vertex_POS { - XMFLOAT4 pos; + XMFLOAT3 pos; + uint32_t normal_wind; - Vertex_POS() :pos(XMFLOAT4(0.0f, 0.0f, 0.0f, 0.0f)) {} + Vertex_POS() :pos(XMFLOAT3(0.0f, 0.0f, 0.0f)), normal_wind(0) {} Vertex_POS(const Vertex_FULL& vert) { - pos = vert.pos; + pos.x = vert.pos.x; + pos.y = vert.pos.y; + pos.z = vert.pos.z; + NORWINDFromFloat(XMFLOAT3(vert.nor.x, vert.nor.y, vert.nor.z), vert.pos.w); } - inline XMVECTOR Load() const + inline XMVECTOR LoadPOS() const { - return XMLoadFloat4(&pos); + return XMLoadFloat3(&pos); } - - static const wiGraphicsTypes::FORMAT FORMAT = wiGraphicsTypes::FORMAT::FORMAT_R32G32B32A32_FLOAT; - }; - struct Vertex_NOR - { - uint32_t nor; - - Vertex_NOR() :nor(0) {} - Vertex_NOR(const Vertex_FULL& vert) + inline XMVECTOR LoadNOR() const { - nor = 0; - - nor |= (uint8_t)((vert.nor.x * 0.5f + 0.5f) * 255.0f) << 0; - nor |= (uint8_t)((vert.nor.y * 0.5f + 0.5f) * 255.0f) << 8; - nor |= (uint8_t)((vert.nor.z * 0.5f + 0.5f) * 255.0f) << 16; - nor |= (uint8_t)(vert.nor.w * 255.0f) << 24; // ao (0-1) + return XMLoadFloat3(&GetNor_FULL()); } - inline void FromFLOAT(const XMFLOAT3& value) + inline void NORWINDFromFloat(const XMFLOAT3& normal, float wind) { - uint8_t alpha = (nor >> 24) & 0x000000FF; + normal_wind = 0; - nor = 0; - - nor |= (uint8_t)((value.x * 0.5f + 0.5f) * 255.0f) << 0; - nor |= (uint8_t)((value.y * 0.5f + 0.5f) * 255.0f) << 8; - nor |= (uint8_t)((value.z * 0.5f + 0.5f) * 255.0f) << 16; - nor |= alpha << 24; + normal_wind |= (uint32_t)((normal.x * 0.5f + 0.5f) * 255.0f) << 0; + normal_wind |= (uint32_t)((normal.y * 0.5f + 0.5f) * 255.0f) << 8; + normal_wind |= (uint32_t)((normal.z * 0.5f + 0.5f) * 255.0f) << 16; + normal_wind |= (uint32_t)(wind * 255.0f) << 24; } - inline XMFLOAT4 GetNor_FULL() const + inline XMFLOAT3 GetNor_FULL() const { - XMFLOAT4 nor_FULL(0, 0, 0, 0); + XMFLOAT3 nor_FULL(0, 0, 0); - nor_FULL.x = (float)((nor >> 0) & 0x000000FF) / 255.0f * 2.0f - 1.0f; - nor_FULL.y = (float)((nor >> 8) & 0x000000FF) / 255.0f * 2.0f - 1.0f; - nor_FULL.z = (float)((nor >> 16) & 0x000000FF) / 255.0f * 2.0f - 1.0f; - nor_FULL.w = (float)((nor >> 24) & 0x000000FF) / 255.0f; + nor_FULL.x = (float)((normal_wind >> 0) & 0x000000FF) / 255.0f * 2.0f - 1.0f; + nor_FULL.y = (float)((normal_wind >> 8) & 0x000000FF) / 255.0f * 2.0f - 1.0f; + nor_FULL.z = (float)((normal_wind >> 16) & 0x000000FF) / 255.0f * 2.0f - 1.0f; return nor_FULL; } - static const wiGraphicsTypes::FORMAT FORMAT = wiGraphicsTypes::FORMAT::FORMAT_R8G8B8A8_UNORM; + static const wiGraphicsTypes::FORMAT FORMAT = wiGraphicsTypes::FORMAT::FORMAT_R32G32B32A32_FLOAT; }; struct Vertex_TEX { - XMHALF4 tex; + XMHALF2 tex; - Vertex_TEX() :tex(XMHALF4(0.0f, 0.0f, 0.0f, 0.0f)) {} + Vertex_TEX() :tex(XMHALF2(0.0f, 0.0f)) {} Vertex_TEX(const Vertex_FULL& vert) { - tex = XMHALF4(vert.tex.x, vert.tex.y, vert.tex.z, vert.tex.w); + tex = XMHALF2(vert.tex.x, vert.tex.y); } - static const wiGraphicsTypes::FORMAT FORMAT = wiGraphicsTypes::FORMAT::FORMAT_R16G16B16A16_FLOAT; + static const wiGraphicsTypes::FORMAT FORMAT = wiGraphicsTypes::FORMAT::FORMAT_R16G16_FLOAT; }; struct Vertex_BON { @@ -392,12 +380,10 @@ public: std::string name; std::string parent; std::vector vertices_FULL; - std::vector vertices_POS; // position(xyz), wind(w) - std::vector vertices_NOR; // normal + std::vector vertices_POS; // position(xyz), normal+wind(w as uint) std::vector vertices_TEX; // texcoords std::vector vertices_BON; // bone indices, bone weights std::vector vertices_Transformed_POS; // for soft body simulation - std::vector vertices_Transformed_NOR; // for soft body simulation std::vector vertices_Transformed_PRE; // for soft body simulation std::vector indices; std::vector physicsverts; @@ -408,16 +394,13 @@ public: wiGraphicsTypes::GPUBuffer indexBuffer; wiGraphicsTypes::GPUBuffer vertexBuffer_POS; - wiGraphicsTypes::GPUBuffer vertexBuffer_NOR; wiGraphicsTypes::GPUBuffer vertexBuffer_TEX; wiGraphicsTypes::GPUBuffer vertexBuffer_BON; wiGraphicsTypes::GPUBuffer streamoutBuffer_POS; - wiGraphicsTypes::GPUBuffer streamoutBuffer_NOR; wiGraphicsTypes::GPUBuffer streamoutBuffer_PRE; // Dynamic vertexbuffers write into a global pool, these will be the offsets into that: UINT bufferOffset_POS; - UINT bufferOffset_NOR; UINT bufferOffset_PRE; wiGraphicsTypes::INDEXBUFFER_FORMAT indexFormat; @@ -446,7 +429,6 @@ public: wiRenderTarget impostorTarget; float impostorDistance; static wiGraphicsTypes::GPUBuffer impostorVB_POS; - static wiGraphicsTypes::GPUBuffer impostorVB_NOR; static wiGraphicsTypes::GPUBuffer impostorVB_TEX; float tessellationFactor; @@ -497,7 +479,6 @@ public: tessellationFactor = 0.0f; optimized = false; bufferOffset_POS = 0; - bufferOffset_NOR = 0; bufferOffset_PRE = 0; indexFormat = wiGraphicsTypes::INDEXFORMAT_16BIT; } diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 5d5a86a36..e9e0fac50 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -653,7 +653,7 @@ void wiRenderer::LoadShaders() { VertexLayoutDesc layout[] = { - { "POSITION", 0, Mesh::Vertex_POS::FORMAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, + { "POSITION_NORMAL_WIND", 0, Mesh::Vertex_POS::FORMAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, }; UINT numElements = ARRAYSIZE(layout); VertexShaderInfo* vsinfo = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectVS_debug.cso", wiResourceManager::VERTEXSHADER, layout, numElements)); @@ -665,18 +665,17 @@ void wiRenderer::LoadShaders() { VertexLayoutDesc layout[] = { - { "POSITION", 0, Mesh::Vertex_POS::FORMAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, - { "NORMAL", 0, Mesh::Vertex_NOR::FORMAT, 1, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, - { "TEXCOORD", 0, Mesh::Vertex_TEX::FORMAT, 2, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, - { "TEXCOORD", 1, Mesh::Vertex_POS::FORMAT, 3, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, + { "POSITION_NORMAL_WIND", 0, Mesh::Vertex_POS::FORMAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, + { "TEXCOORD", 0, Mesh::Vertex_TEX::FORMAT, 1, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, + { "TEXCOORD", 1, Mesh::Vertex_POS::FORMAT, 2, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, - { "MATI", 0, FORMAT_R32G32B32A32_FLOAT, 4, APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, - { "MATI", 1, FORMAT_R32G32B32A32_FLOAT, 4, APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, - { "MATI", 2, FORMAT_R32G32B32A32_FLOAT, 4, APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, - { "COLOR_DITHER", 0, FORMAT_R32G32B32A32_FLOAT, 4, APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, - { "MATIPREV", 0, FORMAT_R32G32B32A32_FLOAT, 5, APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, - { "MATIPREV", 1, FORMAT_R32G32B32A32_FLOAT, 5, APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, - { "MATIPREV", 2, FORMAT_R32G32B32A32_FLOAT, 5, APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, + { "MATI", 0, FORMAT_R32G32B32A32_FLOAT, 3, APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, + { "MATI", 1, FORMAT_R32G32B32A32_FLOAT, 3, APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, + { "MATI", 2, FORMAT_R32G32B32A32_FLOAT, 3, APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, + { "COLOR_DITHER", 0, FORMAT_R32G32B32A32_FLOAT, 3, APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, + { "MATIPREV", 0, FORMAT_R32G32B32A32_FLOAT, 4, APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, + { "MATIPREV", 1, FORMAT_R32G32B32A32_FLOAT, 4, APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, + { "MATIPREV", 2, FORMAT_R32G32B32A32_FLOAT, 4, APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, }; UINT numElements = ARRAYSIZE(layout); VertexShaderInfo* vsinfo = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectVS_common.cso", wiResourceManager::VERTEXSHADER, layout, numElements)); @@ -688,7 +687,7 @@ void wiRenderer::LoadShaders() { VertexLayoutDesc layout[] = { - { "POSITION", 0, Mesh::Vertex_POS::FORMAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, + { "POSITION_NORMAL_WIND", 0, Mesh::Vertex_POS::FORMAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, { "MATI", 0, FORMAT_R32G32B32A32_FLOAT, 1, APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, { "MATI", 1, FORMAT_R32G32B32A32_FLOAT, 1, APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, @@ -705,8 +704,8 @@ void wiRenderer::LoadShaders() { VertexLayoutDesc layout[] = { - { "POSITION", 0, Mesh::Vertex_POS::FORMAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, - { "TEXCOORD", 0, Mesh::Vertex_TEX::FORMAT, 1, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, + { "POSITION_NORMAL_WIND", 0, Mesh::Vertex_POS::FORMAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, + { "TEXCOORD", 0, Mesh::Vertex_TEX::FORMAT, 1, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, { "MATI", 0, FORMAT_R32G32B32A32_FLOAT, 2, APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, { "MATI", 1, FORMAT_R32G32B32A32_FLOAT, 2, APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, @@ -723,7 +722,7 @@ void wiRenderer::LoadShaders() { VertexLayoutDesc layout[] = { - { "POSITION", 0, Mesh::Vertex_POS::FORMAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, + { "POSITION_NORMAL_WIND", 0, Mesh::Vertex_POS::FORMAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, { "MATI", 0, FORMAT_R32G32B32A32_FLOAT, 1, APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, { "MATI", 1, FORMAT_R32G32B32A32_FLOAT, 1, APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, @@ -740,8 +739,8 @@ void wiRenderer::LoadShaders() { VertexLayoutDesc layout[] = { - { "POSITION", 0, Mesh::Vertex_POS::FORMAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, - { "TEXCOORD", 0, Mesh::Vertex_TEX::FORMAT, 1, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, + { "POSITION_NORMAL_WIND", 0, Mesh::Vertex_POS::FORMAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, + { "TEXCOORD", 0, Mesh::Vertex_TEX::FORMAT, 1, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, { "MATI", 0, FORMAT_R32G32B32A32_FLOAT, 2, APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, { "MATI", 1, FORMAT_R32G32B32A32_FLOAT, 2, APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, @@ -1565,8 +1564,8 @@ Light* wiRenderer::getLightByName(const std::string& name) Mesh::Vertex_FULL wiRenderer::TransformVertex(const Mesh* mesh, int vertexI, const XMMATRIX& mat) { XMMATRIX sump; - XMVECTOR pos = mesh->vertices_POS[vertexI].Load(); - XMVECTOR nor = XMLoadFloat4(&mesh->vertices_NOR[vertexI].GetNor_FULL()); + XMVECTOR pos = mesh->vertices_POS[vertexI].LoadPOS(); + XMVECTOR nor = mesh->vertices_POS[vertexI].LoadNOR(); if (mesh->hasArmature() && !mesh->armature->boneCollection.empty()) { @@ -1612,12 +1611,7 @@ Mesh::Vertex_FULL wiRenderer::TransformVertex(const Mesh* mesh, int vertexI, con Mesh::Vertex_FULL retV(transformedP); retV.nor = XMFLOAT4(transformedN.x, transformedN.y, transformedN.z, retV.nor.w); - retV.tex = XMFLOAT4( - mesh->vertices_TEX[vertexI].tex.x, - mesh->vertices_TEX[vertexI].tex.y, - mesh->vertices_TEX[vertexI].tex.z, - mesh->vertices_TEX[vertexI].tex.w - ); + retV.tex = mesh->vertices_FULL[vertexI].tex; return retV; } @@ -2093,12 +2087,10 @@ void wiRenderer::UpdateRenderData(GRAPHICSTHREAD threadID) // Do the skinning const GPUResource* vbs[] = { &mesh->vertexBuffer_POS, - &mesh->vertexBuffer_NOR, &mesh->vertexBuffer_BON, }; const GPUUnorderedResource* sos[] = { &mesh->streamoutBuffer_POS, - &mesh->streamoutBuffer_NOR, &mesh->streamoutBuffer_PRE, }; @@ -2112,16 +2104,13 @@ void wiRenderer::UpdateRenderData(GRAPHICSTHREAD threadID) { // Upload CPU skinned vertex buffer (Soft body VB) size_t size_pos = sizeof(Mesh::Vertex_POS)*mesh->vertices_Transformed_POS.size(); - size_t size_nor = sizeof(Mesh::Vertex_NOR)*mesh->vertices_Transformed_NOR.size(); size_t size_pre = sizeof(Mesh::Vertex_POS)*mesh->vertices_Transformed_PRE.size(); UINT offset; - void* vertexData = GetDevice()->AllocateFromRingBuffer(dynamicVertexBufferPool, size_pos + size_nor + size_pre, offset, threadID); + void* vertexData = GetDevice()->AllocateFromRingBuffer(dynamicVertexBufferPool, size_pos + size_pre, offset, threadID); mesh->bufferOffset_POS = offset; - mesh->bufferOffset_NOR = offset + (UINT)size_pos; - mesh->bufferOffset_PRE = offset + (UINT)size_pos + (UINT)size_nor; + mesh->bufferOffset_PRE = offset + (UINT)size_pos; memcpy(vertexData, mesh->vertices_Transformed_POS.data(), size_pos); - memcpy(reinterpret_cast(reinterpret_cast(vertexData) + size_pos), mesh->vertices_Transformed_NOR.data(), size_nor); - memcpy(reinterpret_cast(reinterpret_cast(vertexData) + size_pos + size_nor), mesh->vertices_Transformed_PRE.data(), size_pre); + memcpy(reinterpret_cast(reinterpret_cast(vertexData) + size_pos), mesh->vertices_Transformed_PRE.data(), size_pre); GetDevice()->InvalidateBufferAccess(dynamicVertexBufferPool, threadID); } } @@ -2170,7 +2159,7 @@ void wiRenderer::UpdateRenderData(GRAPHICSTHREAD threadID) } void wiRenderer::OcclusionCulling_Render(GRAPHICSTHREAD threadID) { - if (!GetOcclusionCullingEnabled() || spTree == nullptr) + if (!GetOcclusionCullingEnabled() || spTree == nullptr || GetFreezeCullingCameraEnabled()) { return; } @@ -2251,7 +2240,7 @@ void wiRenderer::OcclusionCulling_Render(GRAPHICSTHREAD threadID) } void wiRenderer::OcclusionCulling_Read() { - if (!GetOcclusionCullingEnabled() || spTree == nullptr) + if (!GetOcclusionCullingEnabled() || spTree == nullptr || GetFreezeCullingCameraEnabled()) { return; } @@ -4175,11 +4164,12 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle ++k; } - if (k < 1) - continue; device->InvalidateBufferAccess(dynamicVertexBufferPool, threadID); + if (k < 1) + continue; + if (realVL == VLTYPE_OBJECT_POS_TEX) { GPUBuffer* vbs[] = { @@ -4203,7 +4193,6 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle { GPUBuffer* vbs[] = { &Mesh::impostorVB_POS, - &Mesh::impostorVB_NOR, &Mesh::impostorVB_TEX, &Mesh::impostorVB_POS, dynamicVertexBufferPool, @@ -4211,7 +4200,6 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle }; UINT strides[] = { sizeof(Mesh::Vertex_POS), - sizeof(Mesh::Vertex_NOR), sizeof(Mesh::Vertex_TEX), sizeof(Mesh::Vertex_POS), sizeof(InstBuf), @@ -4364,11 +4352,12 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle ++k; } - if (k < 1) - continue; device->InvalidateBufferAccess(dynamicVertexBufferPool, threadID); + if (k < 1) + continue; + device->BindIndexBuffer(&mesh->indexBuffer, mesh->GetIndexFormat(), 0, threadID); enum class BOUNDVERTEXBUFFERTYPE @@ -4476,7 +4465,6 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle { GPUBuffer* vbs[] = { mesh->hasDynamicVB() ? dynamicVertexBufferPool : (mesh->streamoutBuffer_POS.IsValid() ? &mesh->streamoutBuffer_POS : &mesh->vertexBuffer_POS), - mesh->hasDynamicVB() ? dynamicVertexBufferPool : (mesh->streamoutBuffer_NOR.IsValid() ? &mesh->streamoutBuffer_NOR : &mesh->vertexBuffer_NOR), &mesh->vertexBuffer_TEX, mesh->hasDynamicVB() ? dynamicVertexBufferPool : (mesh->streamoutBuffer_PRE.IsValid() ? &mesh->streamoutBuffer_PRE : &mesh->vertexBuffer_POS), dynamicVertexBufferPool, @@ -4484,7 +4472,6 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle }; UINT strides[] = { sizeof(Mesh::Vertex_POS), - sizeof(Mesh::Vertex_NOR), sizeof(Mesh::Vertex_TEX), sizeof(Mesh::Vertex_POS), sizeof(InstBuf), @@ -4492,7 +4479,6 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle }; UINT offsets[] = { mesh->hasDynamicVB() ? mesh->bufferOffset_POS : 0, - mesh->hasDynamicVB() ? mesh->bufferOffset_NOR : 0, 0, mesh->hasDynamicVB() ? mesh->bufferOffset_PRE : 0, instancesOffset, @@ -5995,14 +5981,14 @@ void wiRenderer::RayIntersectMeshes(const RAY& ray, const CulledList& culledObje { for (size_t i = 0; i < mesh->vertices_Transformed_POS.size(); ++i) { - _vertices[i] = mesh->vertices_Transformed_POS[i].Load(); + _vertices[i] = mesh->vertices_Transformed_POS[i].LoadPOS(); } } else { for (size_t i = 0; i < mesh->vertices_POS.size(); ++i) { - _vertices[i] = mesh->vertices_POS[i].Load(); + _vertices[i] = mesh->vertices_POS[i].LoadPOS(); } } @@ -6023,8 +6009,7 @@ void wiRenderer::RayIntersectMeshes(const RAY& ray, const CulledList& culledObje XMStoreFloat3(&picked.position, pos); XMStoreFloat3(&picked.normal, nor); picked.distance = wiMath::Distance(pos, rayOrigin); - XMVECTOR& tmpTex = XMLoadHalf4(&mesh->vertices_TEX[i0].tex); - picked.subsetIndex = (int)XMVectorGetZ(tmpTex); // half has no normal conversion, so have to do load-store + picked.subsetIndex = (int)mesh->vertices_FULL[i0].tex.z; points.push_back(picked); } } @@ -6286,7 +6271,6 @@ void wiRenderer::CreateImpostor(Mesh* mesh) GPUBuffer* vbs[] = { mesh->hasDynamicVB() ? dynamicVertexBufferPool : (mesh->streamoutBuffer_POS.IsValid() ? &mesh->streamoutBuffer_POS : &mesh->vertexBuffer_POS), - mesh->hasDynamicVB() ? dynamicVertexBufferPool : (mesh->streamoutBuffer_NOR.IsValid() ? &mesh->streamoutBuffer_NOR : &mesh->vertexBuffer_NOR), &mesh->vertexBuffer_TEX, mesh->hasDynamicVB() ? dynamicVertexBufferPool : (mesh->streamoutBuffer_PRE.IsValid() ? &mesh->streamoutBuffer_PRE : &mesh->vertexBuffer_POS), dynamicVertexBufferPool, @@ -6294,7 +6278,6 @@ void wiRenderer::CreateImpostor(Mesh* mesh) }; UINT strides[] = { sizeof(Mesh::Vertex_POS), - sizeof(Mesh::Vertex_NOR), sizeof(Mesh::Vertex_TEX), sizeof(Mesh::Vertex_POS), sizeof(InstBuf), @@ -6302,7 +6285,6 @@ void wiRenderer::CreateImpostor(Mesh* mesh) }; UINT offsets[] = { mesh->hasDynamicVB() ? mesh->bufferOffset_POS : 0, - mesh->hasDynamicVB() ? mesh->bufferOffset_NOR : 0, 0, mesh->hasDynamicVB() ? mesh->bufferOffset_PRE : 0, instancesOffset, diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 51c8beeb1..9f1853421 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wiVersion // minor features, major updates const int minor = 13; // minor bug fixes, alterations, refactors, updates - const int revision = 90; + const int revision = 91; long GetVersion()