From 752fceb1e3c4ce06b6f20b9c4471927821469bf2 Mon Sep 17 00:00:00 2001 From: aap Date: Tue, 21 Apr 2020 13:38:43 +0200 Subject: [PATCH] fixed matfx; forgot skin file --- src/d3d/shaders/matfx_env_PS.h | 32 +++++++------ src/d3d/shaders/matfx_env_PS.hlsl | 3 +- src/d3d/shaders/matfx_env_tex_PS.h | 76 ++++++++++++++++-------------- src/d3d/shaders/skin_VS.hlsl | 66 ++++++++++++++++++++++++++ 4 files changed, 126 insertions(+), 51 deletions(-) create mode 100644 src/d3d/shaders/skin_VS.hlsl diff --git a/src/d3d/shaders/matfx_env_PS.h b/src/d3d/shaders/matfx_env_PS.h index 41d5678..2224b68 100644 --- a/src/d3d/shaders/matfx_env_PS.h +++ b/src/d3d/shaders/matfx_env_PS.h @@ -32,13 +32,14 @@ max r1.xyz, v0, c2 mul r1.xyz, r1, c1.x mul r0.xyz, r0, r1 + mul r0.xyz, r0, t0.z add r1.xyz, v0, -c0 mad r1.xyz, t0.z, r1, c0 mad r0.xyz, r1, v0.w, r0 mov r0.w, v0.w mov oC0, r0 -// approximately 9 instruction slots used (1 texture, 8 arithmetic) +// approximately 10 instruction slots used (1 texture, 9 arithmetic) #endif const BYTE g_ps20_main[] = @@ -105,19 +106,22 @@ const BYTE g_ps20_main[] = 228, 128, 1, 0, 0, 160, 5, 0, 0, 3, 0, 0, 7, 128, 0, 0, 228, 128, - 1, 0, 228, 128, 2, 0, - 0, 3, 1, 0, 7, 128, - 0, 0, 228, 144, 0, 0, - 228, 161, 4, 0, 0, 4, + 1, 0, 228, 128, 5, 0, + 0, 3, 0, 0, 7, 128, + 0, 0, 228, 128, 0, 0, + 170, 176, 2, 0, 0, 3, 1, 0, 7, 128, 0, 0, - 170, 176, 1, 0, 228, 128, - 0, 0, 228, 160, 4, 0, - 0, 4, 0, 0, 7, 128, + 228, 144, 0, 0, 228, 161, + 4, 0, 0, 4, 1, 0, + 7, 128, 0, 0, 170, 176, 1, 0, 228, 128, 0, 0, - 255, 144, 0, 0, 228, 128, - 1, 0, 0, 2, 0, 0, - 8, 128, 0, 0, 255, 144, - 1, 0, 0, 2, 0, 8, - 15, 128, 0, 0, 228, 128, - 255, 255, 0, 0 + 228, 160, 4, 0, 0, 4, + 0, 0, 7, 128, 1, 0, + 228, 128, 0, 0, 255, 144, + 0, 0, 228, 128, 1, 0, + 0, 2, 0, 0, 8, 128, + 0, 0, 255, 144, 1, 0, + 0, 2, 0, 8, 15, 128, + 0, 0, 228, 128, 255, 255, + 0, 0 }; diff --git a/src/d3d/shaders/matfx_env_PS.hlsl b/src/d3d/shaders/matfx_env_PS.hlsl index 3508351..767e313 100644 --- a/src/d3d/shaders/matfx_env_PS.hlsl +++ b/src/d3d/shaders/matfx_env_PS.hlsl @@ -16,14 +16,15 @@ float4 colorClamp : register(c2); float4 main(VS_out input) : COLOR { float4 pass1 = input.Color; + float4 envColor = max(pass1, colorClamp); #ifdef TEX pass1 *= tex2D(diffTex, input.TexCoord0.xy); #endif - float4 envColor = max(pass1, colorClamp); float4 pass2 = envColor*shininess*tex2D(envTex, input.TexCoord1.xy); pass1.rgb = lerp(fogColor.rgb, pass1.rgb, input.TexCoord0.z); + pass2.rgb = lerp(float3(0.0, 0.0, 0.0), pass2.rgb, input.TexCoord0.z); // We simulate drawing this in two passes. // First pass with standard blending, second with addition diff --git a/src/d3d/shaders/matfx_env_tex_PS.h b/src/d3d/shaders/matfx_env_tex_PS.h index 4559954..f6054a9 100644 --- a/src/d3d/shaders/matfx_env_tex_PS.h +++ b/src/d3d/shaders/matfx_env_tex_PS.h @@ -31,18 +31,19 @@ dcl v0 dcl_2d s0 dcl_2d s1 - texld r0, t0, s0 - texld r1, t1, s1 - mad r2.xyz, v0, r0, -c0 - mul r0, r0, v0 - mad r2.xyz, t0.z, r2, c0 - max r3.xyz, r0, c2 - mul r3.xyz, r3, c1.x - mul r1.xyz, r1, r3 - mad r0.xyz, r2, r0.w, r1 - mov oC0, r0 + texld r0, t1, s1 + texld r1, t0, s0 + max r2.xyz, v0, c2 + mul r2.xyz, r2, c1.x + mul r0.xyz, r0, r2 + mul r0.xyz, r0, t0.z + mad r1.xyz, v0, r1, -c0 + mul r2.w, r1.w, v0.w + mad r1.xyz, t0.z, r1, c0 + mad r2.xyz, r1, r2.w, r0 + mov oC0, r2 -// approximately 10 instruction slots used (2 texture, 8 arithmetic) +// approximately 11 instruction slots used (2 texture, 9 arithmetic) #endif const BYTE g_ps20_main[] = @@ -109,32 +110,35 @@ const BYTE g_ps20_main[] = 15, 160, 31, 0, 0, 2, 0, 0, 0, 144, 1, 8, 15, 160, 66, 0, 0, 3, - 0, 0, 15, 128, 0, 0, - 228, 176, 0, 8, 228, 160, + 0, 0, 15, 128, 1, 0, + 228, 176, 1, 8, 228, 160, 66, 0, 0, 3, 1, 0, - 15, 128, 1, 0, 228, 176, - 1, 8, 228, 160, 4, 0, - 0, 4, 2, 0, 7, 128, - 0, 0, 228, 144, 0, 0, - 228, 128, 0, 0, 228, 161, + 15, 128, 0, 0, 228, 176, + 0, 8, 228, 160, 11, 0, + 0, 3, 2, 0, 7, 128, + 0, 0, 228, 144, 2, 0, + 228, 160, 5, 0, 0, 3, + 2, 0, 7, 128, 2, 0, + 228, 128, 1, 0, 0, 160, 5, 0, 0, 3, 0, 0, - 15, 128, 0, 0, 228, 128, - 0, 0, 228, 144, 4, 0, - 0, 4, 2, 0, 7, 128, - 0, 0, 170, 176, 2, 0, - 228, 128, 0, 0, 228, 160, - 11, 0, 0, 3, 3, 0, 7, 128, 0, 0, 228, 128, - 2, 0, 228, 160, 5, 0, - 0, 3, 3, 0, 7, 128, - 3, 0, 228, 128, 1, 0, - 0, 160, 5, 0, 0, 3, - 1, 0, 7, 128, 1, 0, - 228, 128, 3, 0, 228, 128, - 4, 0, 0, 4, 0, 0, - 7, 128, 2, 0, 228, 128, - 0, 0, 255, 128, 1, 0, - 228, 128, 1, 0, 0, 2, - 0, 8, 15, 128, 0, 0, - 228, 128, 255, 255, 0, 0 + 2, 0, 228, 128, 5, 0, + 0, 3, 0, 0, 7, 128, + 0, 0, 228, 128, 0, 0, + 170, 176, 4, 0, 0, 4, + 1, 0, 7, 128, 0, 0, + 228, 144, 1, 0, 228, 128, + 0, 0, 228, 161, 5, 0, + 0, 3, 2, 0, 8, 128, + 1, 0, 255, 128, 0, 0, + 255, 144, 4, 0, 0, 4, + 1, 0, 7, 128, 0, 0, + 170, 176, 1, 0, 228, 128, + 0, 0, 228, 160, 4, 0, + 0, 4, 2, 0, 7, 128, + 1, 0, 228, 128, 2, 0, + 255, 128, 0, 0, 228, 128, + 1, 0, 0, 2, 0, 8, + 15, 128, 2, 0, 228, 128, + 255, 255, 0, 0 }; diff --git a/src/d3d/shaders/skin_VS.hlsl b/src/d3d/shaders/skin_VS.hlsl new file mode 100644 index 0000000..7e19c08 --- /dev/null +++ b/src/d3d/shaders/skin_VS.hlsl @@ -0,0 +1,66 @@ +#include "standardConstants.h" + +float4x4 boneMatrices[64] : register(c41); + +struct VS_in +{ + float4 Position : POSITION; + float3 Normal : NORMAL; + float2 TexCoord : TEXCOORD0; + float4 Prelight : COLOR0; + float4 Weights : BLENDWEIGHT; + int4 Indices : BLENDINDICES; +}; + +struct VS_out { + float4 Position : POSITION; + float3 TexCoord0 : TEXCOORD0; // also fog + float4 Color : COLOR0; +}; + + +VS_out main(in VS_in input) +{ + VS_out output; + + int j; + float3 SkinVertex = float3(0.0, 0.0, 0.0); + float3 SkinNormal = float3(0.0, 0.0, 0.0); + for(j = 0; j < 4; j++){ + SkinVertex += mul(boneMatrices[input.Indices[j]], input.Position).xyz * input.Weights[j]; + SkinNormal += mul((float3x3)boneMatrices[input.Indices[j]], input.Normal).xyz * input.Weights[j]; + } + + output.Position = mul(combinedMat, float4(SkinVertex, 1.0)); + float3 Vertex = mul(worldMat, float4(SkinVertex, 1.0)).xyz; + float3 Normal = mul(normalMat, SkinNormal); + + output.TexCoord0.xy = input.TexCoord; + + output.Color = float4(0.0, 0.0, 0.0, 1.0); + if(surfPrelight > 0.0) + output.Color = input.Prelight; + + output.Color.rgb += ambientLight.rgb * surfAmbient; + + int i; +#ifdef DIRECTIONALS + for(i = 0; i < numDirLights; i++) + output.Color.xyz += DoDirLight(lights[i+firstDirLight], Normal)*surfDiffuse; +#endif +#ifdef POINTLIGHTS + for(i = 0; i < numPointLights; i++) + output.Color.xyz += DoPointLight(lights[i+firstPointLight], Vertex.xyz, Normal)*surfDiffuse; +#endif +#ifdef SPOTLIGHTS + for(i = 0; i < numSpotLights; i++) + output.Color.xyz += DoSpotLight(lights[i+firstSpotLight], Vertex.xyz, Normal)*surfDiffuse; +#endif + // PS2 clamps before material color + output.Color = clamp(output.Color, 0.0, 1.0); + output.Color *= matCol; + + output.TexCoord0.z = clamp((output.Position.w - fogEnd)*fogRange, fogDisable, 1.0); + + return output; +}