Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
Administrator
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
// wandelt eine Farbe in einen Normalenvektor um (aus einer Normal-Map) inline float3 decodeNormal(float4 n) { return 2.0 * n.xyz - 1.0; } texture diffuseTexture < string ResourceName = ""; string ResourceType = "2D"; string UIWidget = "Texture"; string UIName = "Diffuse Texture"; >; texture normalTexture < string ResourceName = ""; string ResourceType = "2D"; string UIWidget = "Texture"; string UIName = "Normal Texture"; >; float4 materialAmbient < string UIWidget = "Color"; float4 UIMin = float4(0.0, 0.0, 0.0, 0.0); float4 UIMax = float4(1.0, 1.0, 1.0, 0.0); string UIName = "Material Ambient"; > = {0.05, 0.05, 0.05, 0.0}; float4 materialDiffuse < string UIWidget = "Color"; float4 UIMin = float4(0.0, 0.0, 0.0, 0.0); float4 UIMax = float4(1.0, 1.0, 1.0, 1.0); string UIName = "Material Diffuse"; > = {1.0, 1.0, 1.0, 1.0}; float4 materialSpecular < string UIWidget = "Color"; float4 UIMin = float4(0.0, 0.0, 0.0, 0.0); float4 UIMax = float4(1.0, 1.0, 1.0, 0.0); string UIName = "Material Specular"; > = {0.3, 0.3, 0.3, 0.0}; float materialShininess < string UIWidget = "Slider"; float UIMin = 1.0; float UIMax = 100.0; float UIStep = 0.1; string UIName = "Material Shininess"; > = 16.0; sampler diffuseTextureSampler = sampler_state { texture = <diffuseTexture>; addressU = WRAP; addressV = WRAP; mipFilter = LINEAR; minFilter = LINEAR; magFilter = LINEAR; }; sampler normalTextureSampler = sampler_state { texture = <normalTexture>; addressU = WRAP; addressV = WRAP; mipFilter = LINEAR; minFilter = LINEAR; magFilter = LINEAR; }; struct VertexInput { float4 position : POSITION; float3 normal : NORMAL; float3 tangent : TANGENT; float2 texCoord : TEXCOORD0; }; struct VertexOutput { float4 position : POSITION; float4 diffuse : COLOR0; float4 specular : COLOR1; float2 texCoordDiffuse : TEXCOORD0; float2 texCoordBump : TEXCOORD1; float3 lightVector : TEXCOORD2; float3 halfVector : TEXCOORD3; }; VertexOutput vs(VertexInput IN) { VertexOutputPass1 OUT = (VertexOutputPass1)(0); OUT.position = mul(IN.position, worldViewProjectionMatrix); OUT.diffuse = materialDiffuse * lightDiffuse; OUT.specular = materialSpecular * lightSpecular; OUT.texCoordDiffuse = IN.texCoord; OUT.texCoordBump = IN.texCoord; float3x3 objToTangent = transpose(float3x3(IN.tangent, cross(IN.normal, IN.tangent), IN.normal)); float3 l = mul(lightPositionMS - IN.position.xyz, objToTangent); float3 h = mul(cameraPositionMS - IN.position.xyz, objToTangent); OUT.lightVector = normalize(l); OUT.halfVector = normalize(normalize(h) + l); return OUT; } float4 ps(VertexOutput IN) : COLOR { float3 bumpNormal = decodeNormal(tex2D(normalTextureSampler, IN.texCoordBump)); float3 lightVector = normalize(IN.lightVector); float nDotL = saturate(dot(bumpNormal, lightVector)); float4 diffuseTexture = tex2D(diffuseTextureSampler, IN.texCoordDiffuse); float3 halfVector = normalize(IN.halfVector); float nDotH = saturate(dot(bumpNormal, halfVector)); float f = pow(nDotH, materialShininess); return nDotL * IN.diffuse * diffuseTexture + f * IN.specular; } technique tPS20 { pass p0 { vertexShader = compile vs_2_0 vs(); pixelShader = compile ps_2_0 ps(); } } |
Administrator
Werbeanzeige