/////////////////////////////////////////////////////////////////////////////// // // ## ###### // ###### ### // ## ############### Shark 3D Engine (www.shark3d.com) // ########## # # # // ######## Copyright (c) 1996-2006 Spinor GmbH. // ######### # # # All rights reserved. // ## ########## // ## // /////////////////////////////////////////////////////////////////////////////// #include \ /////////////////////////////////////////////////////////////////////////////// struct VS_INPUT { float4 posObj: POSITION; float3 normalObj: NORMAL; S3D_BONE_DECL_STD(boneWgh, boneSubscr) float2 mainTexCoord: TEXCOORD0; float3 tangentUObj: TEXCOORD1; float3 tangentVObj: TEXCOORD2; }; struct VS_OUTPUT { float4 posScr: POSITION; float2 mainTexCoord: TEXCOORD0; float3 diffuseDirSurf: TEXCOORD1; float3 specularDirSurf: TEXCOORD2; float3 scaledSurfToLight: TEXCOORD3; #ifdef S3D_PARALLAX_MAPPING float3 camToVertSurf: TEXCOORD4; #endif #ifdef S3D_LIGHT_BRIGHT float4 lightBrightCoord: TEXCOORD5; float4 secPosScr: TEXCOORD6; #endif #ifdef S3D_LIGHT_PROJ float4 lightProjCoord: TEXCOORD5; #endif #ifdef S3D_LIGHT_SHMAP float4 lightShmapCoord: TEXCOORD6; #endif float fog: FOG; }; /////////////////////////////////////////////////////////////////////////////// const float4x4 projMat; const float4x4 lightBrightMat; S3D_MATBONE_DECL_STD(matBone) const float4 lightCenRange; const float4x4 lightProjMat; const float4x4 lightShmapMat; /////////////////////////////////////////////////////////////////////////////// // Vertexshader // Profile: 1x1 VS_OUTPUT main(VS_INPUT input) { VS_OUTPUT output = (VS_OUTPUT)0; float4x4 matBoneFinal; S3D_BONE_TRANSF_STD( matBoneFinal, matBone, input.boneWgh, input.boneSubscr); // Transform vectors by matBoneFinal float4 posView = mul(input.posObj, matBoneFinal); float3 normalView = mul(input.normalObj, matBoneFinal).xyz; float3 tangentUObj = input.tangentUObj.xyz; float3 tangentVObj = input.tangentVObj.xyz; float3 tangentUView = mul(tangentUObj, matBoneFinal); float3 tangentVView = mul(tangentVObj, matBoneFinal); output.posScr = mul(posView, projMat); output.mainTexCoord = input.mainTexCoord; output.fog = posView.z / posView.w; #ifdef S3D_LIGHT_PROJ output.lightProjCoord = mul(posView, lightProjMat); #endif #ifdef S3D_LIGHT_SHMAP output.lightShmapCoord = mul(posView, lightShmapMat); #endif float3 camToVertView = posView.xyz; float3 vertToLightView = lightCenRange - camToVertView; // Lightrange-factor: 1 - (lightpos - surfacepos)^2 / range^2 output.scaledSurfToLight = vertToLightView / lightCenRange.w; #ifdef S3D_PARALLAX_MAPPING output.camToVertSurf.x = dot(tangentUView, camToVertView); output.camToVertSurf.y = dot(tangentVView, camToVertView); output.camToVertSurf.z = dot(normalView, camToVertView); #endif float3 vertToLightDirView = normalize(vertToLightView); float3 halfDirView = vertToLightDirView - camToVertView; s3d_calcBump( output.diffuseDirSurf, output.specularDirSurf, normalView, vertToLightDirView, halfDirView, tangentUView, tangentVView); #ifdef S3D_LIGHT_BRIGHT output.lightBrightCoord = mul(posView, lightBrightMat); output.secPosScr = output.posScr; #endif return output; } ///////////////////////////////////////////////////////////////////////////////