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
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 |
uniform mat4 matView; uniform mat3 matViewProjection; uniform float fHeightScale; uniform float fPerspectiveBias; uniform vec4 vLightOffset; varying vec2 TexCoord; varying vec3 Normal; varying vec3 Binormal; varying vec3 Tangent; varying vec3 EyeVector; varying vec3 LightVector; varying vec2 vParallaxXY; attribute vec3 rm_Binormal; attribute vec3 rm_Tangent; void main(void) { // Transform the position gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; // Set the texture coordinate TexCoord = gl_MultiTexCoord0.xy; // Compute the view vector in view space vec3 vView = -(matView * gl_Vertex); // Compute tangent space basis vector in view space vec3 vTangent = mat3(matView) * rm_Tangent; vec3 vBinormal = mat3(matView) * rm_Binormal; vec3 vNormal = mat3(matView) * Normal; // Normalize the view vector in tangent space vec3 vViewTS = mat3(vTangent, vBinormal, vNormal) * normalize(vView); // Compute initial parallax displacement direction vec2 vParallaxDirection = normalize(vViewTS.xy); // Compute the length of the parallax displacement vector float fParallaxLength = -sqrt(1.0 - vViewTS.z * vViewTS.z) / vViewTS.z; // Compute the parallax bias parameter float fParallaxBias = fPerspectiveBias + (1.0 - fPerspectiveBias) * (2.0 * vViewTS.z - 1.0); // Compute the actual reverse parallax displacement vector vParallaxXY = -vParallaxDirection * fParallaxLength * fParallaxBias * fHeightScale; // Compute light vector (view space): vec3 vLight = vView + vLightOffset; // Propagate the view and the light vectors (in tangent space): EyeVector = mat3(vTangent, vBinormal, vNormal) * vView; LightVector = mat3(vTangent, vBinormal, vNormal) * vLight; } |
Zitat
A standard height map is used to represent the varying height of the surface. The height
map correlates to the surface's regular texture map and stores one height value per texel.
These values are in the range {0.0, 1.0}.
To compute a texture coordinate offset at a point P, the eye vector must first be normalized
to produce a normalized eye vector V. The height h at the original texture coordinate T_0 is
read from the height map. The height is scaled by a scale factor s and biased by a bias b in
order to map the height from the range {0.0, 1.0} to a range that better represents the physical properties of the surface being simulated. For example, a brick wall texture might
cover a 2x2 meter area. Also imagine the surface of the bricks and the recessed grout give
the surface a thickness of 0.02m. The correct scale factor for this material would be 0.02 /
2 = 0.01. Coupling this with a bias of 0.0 would then remap the height field to a range of
{0.0, 0.01}. Using a bias of 0.01 would remap the range to {0.99, 0.0}. The average of
these two extremes is probably best for most textures.
b = s ∙ 0.5
A bias that excludes 0.0 from the range would be impractical since that assumes that the
surface being simulated does not intersect the polygon that represents it. The new scaled
and biased height hsb is given by
h_sb = h ∙ s + b
An offset is then computed by tracing a vector parallel to the polygon from the point on the
surface directly above P to the eye vector. This new vector is the offset and can be added to
T_0 to produce the new texture coordinate Tn.
T_n = T_0 + ( h_sb ∙ V{x, y} / V{z} )
The new texture coordinate is used to index a regular texture map and any other maps
applied to the surface.
Werbeanzeige