float4x4 mWorldViewProjection : WORLDVIEWPROJECTION; float4x4 mWorld : WORLD; float3 camPos : CAMERAPOSITION; float4 KolorSwOtocz; float4 KolorSwRozpr; float3 PswRozproszone; float nSpecular; float4 KolorSpec; float4 WspOdpSpecMaterial; texture2D tekstura; texture2D texNormalne; sampler TextureSampler = sampler_state { texture = ; magfilter = LINEAR; minfilter = LINEAR; mipfilter = LINEAR; AddressU = mirror; AddressV = mirror; }; sampler TexNormalSampler = sampler_state { texture = ; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR; AddressU = mirror; AddressV = mirror; }; struct VSInputData { float4 Pozycja3D : POSITION0; float3 Normalna : NORMAL0; float2 texWsp : TEXCOORD0; float3 Tangent : TANGENT; float3 Binormal : BINORMAL; }; struct VSOutputData { float4 Pozycja2D : POSITION; float2 texWsp : TEXCOORD0; float3 Pozycja3D : TEXCOORD1; float3 Normalna : TEXCOORD2; float3 Tangent : TEXCOORD3; float3 Binormal : TEXCOORD4; }; struct PSOutputData { float4 Kolor : COLOR0; }; float moj_Phong(float3 L, float3 N , float3 V, float n) { float3 R = normalize(2*dot(N, L)*N-L); float RV = saturate(dot(R,V)); RV = saturate(pow(RV, n)); return RV; } VSOutputData VS(VSInputData inputData) { VSOutputData output; float3 poz3D = mul(inputData.Pozycja3D,mWorld).xyz; float3 Normalna = normalize(mul(inputData.Normalna,mWorld)); output.Pozycja2D = mul(inputData.Pozycja3D,mWorldViewProjection); output.Pozycja3D = poz3D; output.Normalna = Normalna; output.texWsp = float2(1,0)-inputData.texWsp; output.Tangent = normalize(mul(inputData.Tangent,mWorld)); output.Binormal = normalize(mul(inputData.Binormal,mWorld)); return output; } PSOutputData PS(VSOutputData inputData) { PSOutputData output; float4 baseColor = tex2D(TextureSampler, inputData.texWsp); float3 Normalna = tex2D( TexNormalSampler, inputData.texWsp ) * 2 - 1; float3x3 mTangentToWorld = float3x3(inputData.Tangent, inputData.Binormal, inputData.Normalna); Normalna = normalize(mul(Normalna,mTangentToWorld)); float3 KswRozproszone = normalize(PswRozproszone-inputData.Pozycja3D); float wspSwRozproszone = saturate(dot(KswRozproszone,Normalna)); float4 diffuse = KolorSwRozpr*baseColor*wspSwRozproszone; float3 L = normalize(PswRozproszone-inputData.Pozycja3D); float3 V = normalize(camPos-inputData.Pozycja3D); float wspSpec = moj_Phong(L, Normalna , V, nSpecular); float4 specular = wspSpec*KolorSpec*WspOdpSpecMaterial; output.Kolor = saturate(KolorSwOtocz * baseColor + diffuse + specular); return output; } Technique naszaTechnika { Pass p0 { VertexShader = compile vs_2_0 VS(); PixelShader = compile ps_2_0 PS(); } }