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
Alter Hase
C-/C++-Quelltext |
|
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 |
float4x4 mvp : WorldViewProjection; float4x4 m : World; float3 camera_pos : CameraPosition; float3 vLight_Pos = {0.0, 0.0, -40.0}; float3 vFactors = { 0.02, -0.01, 0.5 }; int min_samples = 3; int max_samples = 20; float parallax_ammount = 0.5; texture texmap : DIFFUSE < string ResourceName = "rockwall.jpg"; string ResourceType = "2D"; >; texture reliefmap : NORMAL < string ResourceName = "rockwall.tga"; string ResourceType = "2D"; >; sampler texmap_sampler = sampler_state { Texture = <texmap>; MipFilter = LINEAR; MinFilter = LINEAR; MagFilter = LINEAR; }; sampler reliefmap_sampler = sampler_state { Texture = <reliefmap>; MipFilter = LINEAR; MinFilter = LINEAR; MagFilter = LINEAR; }; struct vertex { float3 position : POSITION; float2 texcoord : TEXCOORD0; float3 normal : NORMAL; float3 tangent : TANGENT; float3 binormal : BINORMAL; }; struct vs_out { float4 position : POSITION; float2 texcoord : TEXCOORD0; float3 view_dir_ts : TEXCOORD1; float3 normal_ts : TEXCOORD2; }; vs_out vertex_shader(vertex IN) { vs_out OUT; float3 vertex_position_ws = mul(float4(IN.position, 1), m).xyz; float3 view_direction_ws = camera_pos - vertex_position_ws; float3x3 tangent_to_world; tangent_to_world[0] = mul(IN.tangent, m); tangent_to_world[1] = mul(IN.binormal, m); tangent_to_world[2] = mul(IN.normal, m); float3x3 world_to_tangent = transpose(tangent_to_world); OUT.position = mul(float4(IN.position, 1), mvp); OUT.texcoord = IN.texcoord; float3x3 modelrot; modelrot[0] = m[0]; modelrot[1] = m[1]; modelrot[2] = m[2]; float3 normal_temp = mul(float4(IN.normal, 1), modelrot).xyz; OUT.view_dir_ts = mul(view_direction_ws, world_to_tangent); OUT.normal_ts = mul(normal_temp, world_to_tangent); return OUT; } float4 pixel_shader(vs_out IN) : COLOR { float3 normal_ts = normalize(IN.normal_ts); float3 view_dir_ts = normalize(IN.view_dir_ts); //Get height from Height|Normal - map float height = tex2D(reliefmap_sampler, IN.texcoord); //Calculate Texture offset float2 offset = (view_dir_ts * parallax_ammount * (height)).xy; return tex2D(texmap_sampler, IN.texcoord + offset); //output difference between eye and view-vector in Tangentspace //float temp = 1- dot(normal_ts, view_dir_ts); //return float4(temp, temp, temp, 0); } technique PrallaxMapping { pass Diff { VertexShader = compile vs_3_0 vertex_shader(); PixelShader = compile ps_3_0 pixel_shader(); } } |
Alter Hase
Administrator
Alter Hase
Werbeanzeige