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
Phili
unregistriert
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 |
TEXTURE Bitmap; TEXTURE Specmap; TEXTURE Bumpmap; struct InVertex { float4 Position : POSITION; float2 Texture : TEXCOORD0; float3 TanU : TEXCOORD1; float3 TanV : TEXCOORD2; float3 TanW : TEXCOORD3; float4 Licht : TEXCOORD4; float4 Kamera : TEXCOORD5; }; sampler Bitmapsamp = sampler_state { Texture=<Bitmap>; AdressU=Wrap; AdressV=Wrap; MipFilter=Linear; MinFilter=Linear; MagFilter=Linear; }; sampler Specmapsamp = sampler_state { Texture=<Specmap>; AdressU=Wrap; AdressV=Wrap; MipFilter=Linear; MinFilter=Linear; MagFilter=Linear; }; sampler Bumpsamp = sampler_state { Texture=<Bumpmap>; AdressU=Wrap; AdressV=Wrap; MipFilter=Linear; MinFilter=Linear; MagFilter=Linear; }; float4x4 View : register(c0); float4x4 Projection : register(c4); float4x4 Transformation : register(c8); float4x4 TransformInvers: register(c12); float4 KameraPosition : register(c16); float Time : register(c17); float4 LichtPosition : register(c19); float4 LichtDiffus : register(c20); float4 LichtAmbient : register(c21); float LichtAbnahme : register(c22); float3 BumpMapTransform(float3 TanU, float3 TanV, float3 TanW, float3 V) { float3 R; V[0]=0.5-V[0]; V[1]=0.5-V[1]; V=normalize(V); R[0]=V[0]*TanU[0]+V[1]*TanV[0]+V[2]*TanW[0]; R[1]=V[0]*TanU[1]+V[1]*TanV[1]+V[2]*TanW[1]; R[2]=V[0]*TanU[2]+V[1]*TanV[2]+V[2]*TanW[2]; return R; } float4 main(InVertex In) : COLOR { float3 Norm=BumpMapTransform(In.TanU, In.TanV, In.TanW, tex2D(Bumpsamp, In.Texture)); float3 Licht=normalize(In.Licht); float3 Kam=normalize(In.Kamera); float Winkel=dot(Norm, Licht); float Reflection=dot(reflect(-Licht, Norm), Kam); if(Reflection<0) Reflection=0; float4 Diffus=Winkel*LichtDiffus*tex2D(Bitmapsamp, In.Texture); float4 Ambient=LichtAmbient*tex2D(Bitmapsamp, In.Texture); float4 Specular=pow(Reflection, 50)*LichtDiffus*tex2D(Specmapsamp, In.Texture)*3; float Abnahme=LichtAbnahme*sqrt(In.Licht[0]*In.Licht[0]+In.Licht[1]*In.Licht[1]+In.Licht[2]*In.Licht[2]); Abnahme=1-Abnahme; if(Abnahme<0)Abnahme=0; float4 Beleuchtung=(Diffus+Ambient+Specular)*Abnahme; return Beleuchtung; } |
C-/C++-Quelltext |
|
1 2 |
V[0]=0.5-V[0]; V[1]=0.5-V[1]; |
Quellcode |
|
1 2 |
V[0]=0.5-V[0]; V[1]=0.5-V[1]; |
Quellcode |
|
1 2 3 |
R[0]=V[0]*TanU[0]+V[1]*TanV[0]+V[2]*TanW[0]; R[1]=V[0]*TanU[1]+V[1]*TanV[1]+V[2]*TanW[1]; R[2]=V[0]*TanU[2]+V[1]*TanV[2]+V[2]*TanW[2]; |
Phili
unregistriert
Zitat
das soll deine normalen aus der normal map vermutlich vom 0..1 bereich in den -1..1 bereich bringen!?
Zitat
außerdem dürfte es um einiges schneller sein, das licht im vertex shader IN den tangent space zu transformieren (dazu kannst du einfach die transponierte nehmen, da die tangentspace matrix hoffentlich orthogonal ist), anstatt die normalen jedes pixels AUS dem tangent space...
Zitat
sieht grottenfalsch aus
Zitat
Ambient nimmt ab?!?
Phili
unregistriert
Quellcode |
|
1 |
V[0] = 2.0f * V[0] - 1.0f; |
Zitat
Was ist handedness?
Quellcode |
|
1 |
float4 Beleuchtung=(Diffus+Ambient+Specular)*Abnahme; |
Phili
unregistriert
Zitat
Dein Fehler hört sich an als ob Du die "handedness" nicht berücksichtigst Wink , dann siehts so aus:
Zitat
wenn ich mir das so anschaue, dann seh ich aber auch, dass ambient abnimmt...
Zitat
V[0] = 2.0f * V[0] - 1.0f;
Phili
unregistriert
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
OutVertex main(InVertex In) { OutVertex Out=(OutVertex)(0); Out.Position=mul(In.Position, Transformation); Out.Licht=LichtPosition-Out.Position; Out.TanU=normalize(mul(In.TanU, TransformInvers)); Out.TanV=normalize(mul(In.TanV, TransformInvers)); Out.TanW=normalize(mul(In.TanW, TransformInvers)); Out.Texture=In.Texture; Out.Position=mul(Out.Position, View); Out.Position=mul(Out.Position, Projection); return Out; } |
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 |
float3 BumpMapTransform(float3 TanU, float3 TanV, float3 TanW, float3 V) { float3 R; R=V; R[0]=R[0]-0.5; R[2]=R[2]-0.5; float3x3 Trans; Trans[0]=normalize(TanU); Trans[1]=normalize(TanW); Trans[2]=normalize(TanV); R=mul(R, Trans); return R; } float4 main(InVertex In) : COLOR { float3 Norm=normalize(tex2D(Bumpsamp, In.Texture)); Norm=BumpMapTransform(In.TanU, In.TanV, In.TanW, Norm); float3 Licht=normalize(In.Licht); float Winkel=dot(Norm, Licht); float4 Diffus=Winkel*LichtDiffus*tex2D(Bitmapsamp, In.Texture); float4 Ambient=LichtAmbient*tex2D(Bitmapsamp, In.Texture); float Abnahme=LichtAbnahme*length(In.Licht); Abnahme=1-Abnahme; if(Abnahme<0)Abnahme=0; float4 Beleuchtung=(Diffus+Ambient)*Abnahme; return Beleuchtung; } |
Werbeanzeige