SlideShare a Scribd company logo
1 of 7
Download to read offline
Bump Mapping Unparametrized Surfaces on the GPU
                                          Morten S. Mikkelsen
                                         Naughty Dog Inc., USA
                                               May 24, 2010


Abstract                                                     the footprint. Furthermore, when deformation of the
                                                             surface is applied the first order derivatives must be
Original bump mapping is only defined for surfaces            reevaluated every frame. For a deformation which
with a known surface parametrization. In this paper          is not based on linear transformations the reevalua-
a new method, for the GPU, is proposed which does            tion requires a fully deformed version of the surface
not use such a given parametrization. To compute             in memory which means deformation cannot be done
the perturbed normal the only inputs used are the            in a vertex shader. These problems were solved in
surface position, the height value and the original          [Sch06] by computing first order derivatives in the
normal.                                                      fragment shader. However, this solution still uses
  The method decouples bump mapping from the                 normal maps and requires 2D texture coordinates.
primitive type which allows for a higher degree of              A height map represents a single value per texel
proceduralism in both generation of the height value         and thus has the potential to compress better than
and the surface.                                             the equivalent normal map. A normal map may be
                                                             thought of as height derivative map which requires
                                                             two values. Furthermore, additional effects such as
1   Introduction                                             parallax/relief texture mapping [KTI∗ 01], [OBM00]
                                                             use a height map.
In 1978, James Blinn published his paper [Bli78] on
                                                                The requirement that 2D texture coordinates exist
simulation of wrinkled surfaces. The aim of his pa-
                                                             means the method does not apply to certain forms
per was to mimic the high frequency surface irregu-
                                                             of proceduralism. For instance the movie render-
larities that we see in reality on objects everywhere.
                                                             ing industry has enjoyed the ability to distribute
Today the effect is known as bump mapping and is
                                                             heights across a surface from compositions of scalar
widely used in the computer graphics industry. In
                                                             functions/textures defined on domains of arbitrary
real–time computer graphics a variant known as tan-
                                                             dimension since the introduction of the Reyes ar-
gent space normal mapping is used. This is the same
                                                             chitecture [CCC87]. Until now this ability has not
effect but with height derivatives precomputed. For
                                                             been available on the GPU. We present an efficient
a proof the reader is referred to [Mik08].
                                                             method, for the GPU, which overcomes these lim-
   The effect is defined based on the premise that
                                                             itations and does not rely on any predetermined
a surface parametrization is known. For a trian-
                                                             parametrization.
gular mesh this is defined by texture coordinates
which represent some unwrap of the surface onto a
plane. The normal perturbation expression contains           2   The Formulation of Bump Mapping
the first order derivatives of the surface parametriza-
tion. For triangular meshes these are precomputed            Let S ⊂ R3 represent some manifold surface and let
at vertex level and stored in memory which adds to           β represent the height function such that a scalar


                                                         1
value is associated with each point on S. In Jim             3   The Surface Gradient Based Formulation
Blinn’s formulation the surface S has a known sur-
face parametrization and we denote this σ : (s, t) →         The height function β represents a scalar field on the
S where (s, t) ∈ R2 . Furthermore, the height map            surface S. In vector calculus, the gradient of a scalar
is assumed to be a function of the same parameter            field is a vector field which points in the direction of
β : (s, t) → R. Given the unit length surface normal         the greatest rate of increase of the scalar field, and
n the displaced surface is defined as                         whose magnitude is the greatest rate of change.
                                                               The surface gradient S of a scalar field is tangent
                      τ =σ+β·n                               to S. For any point p, on S, if there exists some local
The surface normal of τ represents the perturbed             extension of β which is a smooth function on some
normal n used in bump mapping. To simplify the               open subset of R3 , containing p, then the surface
evaluation Blinn uses approximations for the first            gradient at p is equal to
order derivatives in which the last term is canceled.
                                                                            Sβ   =    β − n · (n •     β)       (2)
                 τs         σ s + βs · n
                 τt         σ t + βt · n                     which is the projection of the regular gradient onto
                                                             the tangent plane. For a known chart σ, containing
Note that the normal n represents the visible side           p, the surface gradient is equal to
of the initial surface S. It is not taken into account
in [Bli78] that the parametrization defined by σ is                     Sβ    =       βs   βt   0     · N −1
not necessarily orientation preserving. A derivation,                            (σt × n)βs + (n × σs )βt
of the perturbed normal n , which takes this into                            =                                  (3)
                                                                                      n • (σs × σt )
account is given in [Mik08] and the unnormalized
result is                                                    The surface gradient S β has the two properties
                                                             that it is a vector in the tangent plane and that the
                                

       N    =  σs       σt       n                         dot product between it and some given unit length
                                                             tangent vector v gives the rate of change in the di-
                                                           rection of v. Equation (3) clearly obeys the former
                             −βs
                                                             and the latter is true since S β • v = a · βs + b · βt
       n    =   (N −1 )T ·  −βt                            for v = aσs + bσt where a, b ∈ R.
                              1
                                                               From equations (1) and (3) it follows that the per-
                       (n × σt )βs + (σs × n)βt              turbed normal can be expressed as
            =   n+                                (1)
                            n • (σs × σt )
                                                                                 n =n−         Sβ               (4)
where the symbol • denotes the dot product. Fur-
thermore, the denominator in the second term of              Intuitively this means the normal is pulled away
equation (1) is equal to                                     from the tangent direction of the greatest rate of
             det(N )    =     n • (σs × σt )                 increase in β. Interestingly the result is identical
                                                             to Blinn’s perturbed normal, for a known surface
                        =     ± σs × σt
                                                             parametrization, as indicated by equation (3).
and is positive when the parametrization is orienta-            The form given by equation (4) indicates that
tion preserving. The formulation given here is al-           the perturbed normal does not depend on a specific
most identical to that of Jim Blinn except that it is        parametrization. It depends on the shape of the sur-
not an assumption here that det(N ) is positive.             face and the distribution of height values. Thus we
   In the following section we will give a formulation       can evaluate the surface gradient S β using some,
of bump mapping which does not require a user–               per pixel chosen, local parametrization. For our so-
defined parametrization of S or β.                            lution we choose inverse projection from the screen


                                                         2
domain M ⊂ R2 to the surface S. Inverse projec-               float3 PerturbNormal ( float3 surf_pos ,
tion does not represent a valid chart for the entire              float3 surf_norm , float height )
                                                              {
surface since a coordinate (s0 , t0 ) ∈ M can map to
                                                                float3 vSigmaS = ddx ( surf_pos ) ;
multiple points on S. However, the map represents               float3 vSigmaT = ddy ( surf_pos ) ;
a valid local parametrization σ at each intersection            float3 vN = surf_norm ;     // n o r m a l i z e d
point. In other words the intersection point is con-
                                                                  float3 vR1 = cross ( vSigmaT , vN ) ;
tained in some small neighborhood on S which does                 float3 vR2 = cross ( vN , vSigmaS ) ;
not overlap itself if projected onto the screen. It is
then a local diffeomorphism. For further details the               float fDet = dot ( vSigmaS , vR1 ) ;
reader is referred to the definition of a manifold and
                                                                  float dBs = ddx ( height ) ;
also the inverse function theorem [Pre01].                        float dBt = ddy ( height ) ;
   In the next section we will discuss how this math,
equation (3) in particular, translates to a shader for            float3 vSurfGrad =
                                                                    sign ( fDet ) * ( dBs * vR1 + dBt * vR2 ) ;
the GPU.
                                                                  return normalize ( abs ( fDet ) * vN - vSurfGrad ) ;
                                                              }

4   The Implementation                                        Listing 1: Perturbed normal calculation without the
                                                              use of texture coordinates.
A surface is a two dimensional manifold which means
on a small scale a neighborhood, containing p ∈ S,
can be perceived as planar. In a sense we inherit
                                                              mals at the vertices which are, subsequently, inter-
the differential structure associated with R2 . On
                                                              polated across the triangle to produce a look which
the GPU a surface is rendered as some, arbitrarily
                                                              is more soft. We use the same normalized interpo-
dense, triangular representation which compliments
                                                              lation of the vertex normals as the input parameter
this concept. A triangle does not overlap itself after
                                                              surf_norm. If the vertex normals are not known
projection unless the projection is a line segment or
                                                              then the normal of the triangle can be obtained us-
a point in which case it is rejected by the GPU. Thus
                                                              ing cross(vSigmaS, vSigmaT) instead.
inverse projection from the screen to the triangle is a
valid parametrization. We denote this σ : (s, t) → p
where the coordinate of the pixel center is (s, t) and
the corresponding point on the triangle is p. This
function is resolved simply by passing the vertex po-
sition to the interpolator.
   To compute the surface gradient by equation (3)
we must produce the derivatives σs , σt , βs and
βt . The screen–space derivative calculation func-
tions provided by the GPU are known as ddx and
ddy. On the current generation these produce the
same result for pixel pairs in blocks of 2 × 1 and
1 × 2 respectively. Better results would be achieved                      (a) flat                  (b) smooth
by using central differencing but in order to keep the
solution simple and effective we rely on the built–in
calculation. The implementation is shown in listing           Figure 1: In figure 1(a) we see hard edges as a result
1.                                                            of using τs × τt to produce the normal. Using the
   A triangular mesh is piecewise flat. However, it is         method in listing 1 perturbs the interpolated vertex
common in computer graphics to use averaged nor-              normal as shown in figure 1(b).


                                                          3
For completion we point out that there exists an          also a possibility. For instance forward differencing
even simpler approach to perturb the normal. This            is used by Perlin in [Per04].
is the cross product between the first order deriva-             The difference between Perlin’s perturbation
tives of the displaced surface position τs × τt . How-       method and equation (4) is visually significant. If
ever, this will perturb the face normal and not the          the gradient is above the tangent plane the perturba-
interpolated vertex normal. A comparison between             tion impact is reduced and results are understated.
this approach and our solution is shown in figure 1.          If the gradient is below the tangent plane the per-
   The method which we have discussed until now              turbation impact is increased. This increase even-
relies on the availability of the shader functions ddx       tually results in the perturbed normal pointing in-
and ddy. This issue will be discussed in the next            ward. A visual is shown in figure 2(a) based on a
section.                                                     low frequency Perlin noise for the height map. The
                                                             negated gradient was used to produce this picture
                                                             since adding it effectively inverts the height map.
5   Pre and Post–Process Bump Mapping                        Using the function in listing 2 gives the artifact free
                                                             result shown in figure 2(b).
The shader function given by listing 1 can only be
used in a pixel shader during the in–process fixed
function rasterization of triangles. This excludes           6   Results
bump mapping in a pre–process such as a vertex
                                                             The results presented in this section were pro-
shader or any post–processing solution such as de-
                                                             duced using an implementation in OpenGL using
ferred rendering. Though the method in listing 1
                                                             the CgFX shading language. Our first scene is a
supports spatial height maps we can, for such a map,
                                                             triangulated isosurface with a single point light. We
achieve the same normal perturbation without it.
                                                             assign a height to each surface point using the spa-
                                                             tial function turbulence() by Ken Perlin [Per85].
float3 PerturbNormal ( float3 surf_norm ,                    Six octaves are used and the Perlin noise function
    float3 vGrad )
{
  float3 vSurfGrad =
    vGrad - surf_norm * dot ( surf_norm , vGrad ) ;
  return normalize ( surf_norm - vSurfGrad ) ;
}

Listing 2: This is the surface gradient based normal
perturbation using a spatial height map.


  It was proposed by Perlin [Per85] that a normal
perturbing effect can be achieved by adding the gra-
dient, of a spatial texture, to the unit normal n.
However, this does not produce the normal associ-
ated with the displaced surface. In this paper we             (a) Perlin’s   perturbation (b) Surface gradient based
have proved that Jim Blinn’s formulation of the per-          method
turbed normal is equivalent to equation (4). Our
implementation is shown in listing 2. The function
takes as input the gradient of the spatial texture β.        Figure 2: The result of Perlin based normal per-
For some functions the gradient can be determined            turbation is shown in figure 2(a). There are visual
analytically which is the case for Perlin noise. When        artifacts which are gone using our method shown in
this is not the case then numerical approximation is         figure 2(b).


                                                         4
(a) method in listing 1      (b) method in listing 2          (c) image cut out 1         (d) image cut out 2



Figure 3: Figures 3(a) and 3(b) confirm that the same results are produced by the surface gradient method
and listing 1 which is our ddx and ddy based implementation. However, looking closer at the images as
shown in figures 3(c) and 3(d) shows that the quality of derivative calculation using the function in listing
1 depends on pixel density.


is done with the implementation by Simon Green                 ing the function in listing 1 and normal mapping
in [Gre05]. Note that the gradient of Perlin noise             using interpolation of per vertex tangent spaces.
has an analytical solution dnoise() which can eas-             The model used is a treasure item from the game
ily be implemented in a shader. This implies that              ”Uncharted 2: Among Thieves”. Again results are
the resulting perturbed normal has an analytical so-           the same as shown in figures 4(a) and 4(b). How-
lution using equations (2) and (4). However, the               ever, there is a difference since derivatives are com-
function turbulence() accumulates numerical val-               puted in screen–space from a reconstruction of the
ues of noise so we use central differencing to approx-          height function. This reconstruction is done using
imate the gradient. The result is shown in figure               the built–in texture sampler which produces a sig-
3(b) and the corresponding result in figure 3(a) us-            nal of relatively low accuracy. For instance when the
ing the function in listing 1. The results are the same        texture map is magnified due to undersampling the
which confirms the analysis in section 3. However,              reconstruction of heights is reduced to a piecewise
at closer inspection there are differences in terms of          linear function. The derivative function of such a
quality since the derivative calculation using listing 1       signal is a piecewise constant function. The result is
depends on the pixel density across the surface rela-          illustrated as a close up of the model in figure 4(e).
tive to the frequency level of the height function. As
an example a small part of the sphere in figures 3(a)–
3(b) is shown in figures 3(c)–3(d) respectively. Note
that these correspond to zooming in on the images.                A possible solution is of course to use higher or-
In contrast approaching the sphere increases pixel             der filtering but this makes the solution significantly
density and gives similar results using these meth-            more expensive. We propose either accepting the
ods. Increasing the resolution or super–sampling will          limitation of the method or hiding the problem us-
also achieve this.                                             ing a well known solution which is detail maps. Fig-
                                                               ure 4(f) shows the result of using turbulence() for
  The following test compares results between us-              detail.


                                                           5
7   Conclusion                                              References
                                                            [Bli78]   Blinn J.: Simulation of wrinkled surfaces. In
In this paper we have shown how bump mapping                          ACM Computer Graphics (SIGGRAPH ’78)
can be done on the GPU using the following inputs                     (1978), pp. 286–292.
only in the perturbation function: surface position,        [CCC87] Cook R. L., Carpenter L., Catmull E.:
surface normal and the height value.                                The reyes image rendering architecture. In
  The solution works without precomputed tangent                    ACM Computer Graphics (SIGGRAPH ’87)
                                                                    (1987), ACM, pp. 95–102.
vectors and in fact does not even require that the
height value is produced from a texture coordinate.         [Gre05]   Green S.:          GPU Gems 2 – Pro-
The height function can be either spatial or defined                   gramming Techniques for High–Performance
on the 2D domain. It can be analytical/procedural                     Graphics and General–Purpose Computa-
                                                                      tion”.    Addison–Wesley Publishing, 2005,
or represented by a texture map. Thus our method
                                                                      ch. 26, pp. 409–416.
presents a uniform solution to determine the per-
turbed normal.                                              [KTI∗ 01] Kaneko T., Takahei T., Inami M.,
                                                                      Kawakami N., Yanagida Y., Maeda T.,
   A limitation exists due to our use of the screen–                  Tachi S.: Detailed shape representation with
space derivative instructions ddx and ddy. These are                  parallax mapping. In Proceedings of the ICAT
only available when using the built–in rasterization                  2001 (2001), pp. 205–208.
pipeline of the GPU which is restricted to triangles.       [Mik08]   Mikkelsen M. S.: Simulation of Wrinkled
This excludes certain use cases such as perturbation                  Surfaces Revisited. Master’s thesis, Depart-
of the normal during a deferred process. However,                     ment of Computer Science at the University
in this paper we have shown that Jim Blinn’s formu-                   of Copenhagen, 2008.
lation of the perturbed normal is equivalent to sub-        [OBM00] Oliveira M. M., Bishop G., McAllis-
tracting the surface gradient of the height function                ter D.: Relief texture mapping. In ACM
from the unit normal. Thus if the height function                   Computer Graphics (SIGGRAPH ’00) (2000),
is spatial, such as Perlin noise, the normal can be                 Addison–Wesley Publishing, pp. 359–368.
perturbed without the use of ddx and ddy. This is           [Per85]   Perlin K.: An image synthesizer. SIG-
particularly efficient in the case of Perlin noise be-                  GRAPH Comput. Graph. 19, 3 (1985), 287–
cause it has an analytical gradient function. When                    296.
this is not the case the gradient can be approximated       [Per04]   Perlin K.: GPU Gems – Programming Tech-
numerically.                                                          niques, Tips and Tricks for Real-Time Graph-
   The primary limitation is that bump mapping in                     ics. Addison–Wesley Publishing, 2004, ch. 5,
the general case is only supported during in–process                  pp. 409–416.
rendering of triangles. For future work it would be         [Pre01]   Pressley A.: Elementary Differential Geom-
interesting to see if we can achieve support for two                  etry. Springer, 2001.
dimensional height maps in the vertex shader and/or         [Sch06]   Schuler C.:        Normal mapping with-
achieve a uniform solution in post process.                           out precomputed tangents. In ShaderX5:
                                                                      Advanced Rendering Techniques, Engel W.,
                                                                      (Ed.). Charles River Media, 2006, pp. 131–
                                                                      140.
Acknowledgments. This author would like to
thank Bryan Mcnett for helpful discussions, Manchor
Ko, Pal–Kristian Engstad, and Swaminathan Narayanan
for constructive comments and proof reading. Finally,
thank you to Naughty Dog for allowing me to use the
treasure object for this paper.


                                                        6
(a) method in listing 1                      (b) normal mapping




             (c) no perturbation                  (d) method in listing 1 with albedo




              (e) undersampling                      (f) undersampling with detail


                                            7
Figure 4: Our listing 1 method gives results which are very similar to that of normal
mapping as shown in figures 4(a)-4(b). The model is shown without perturbation of
normals, in figure 4(c), to illustrate which elements of the detail are in the height map.
The final result is shown in figure 4(d) with the albedo map applied. When the height
texture map is magnified the surface becomes piecewise flat as shown in figure 4(e).
The shortcoming can be hidden by using a detail map which is shown in figure 4(f).

More Related Content

What's hot

Visualization using tSNE
Visualization using tSNEVisualization using tSNE
Visualization using tSNEYan Xu
 
SURF - Speeded Up Robust Features
SURF - Speeded Up Robust FeaturesSURF - Speeded Up Robust Features
SURF - Speeded Up Robust FeaturesMarta Lopes
 
A computerized score for the automated differentiation of usual interstitial ...
A computerized score for the automated differentiation of usual interstitial ...A computerized score for the automated differentiation of usual interstitial ...
A computerized score for the automated differentiation of usual interstitial ...Institute of Information Systems (HES-SO)
 
3D gravity inversion by planting anomalous densities
3D gravity inversion by planting anomalous densities3D gravity inversion by planting anomalous densities
3D gravity inversion by planting anomalous densitiesLeonardo Uieda
 
Visualizing Data Using t-SNE
Visualizing Data Using t-SNEVisualizing Data Using t-SNE
Visualizing Data Using t-SNEDavid Khosid
 
A Note on Confidence Bands for Linear Regression Means-07-24-2015
A Note on Confidence Bands for Linear Regression Means-07-24-2015A Note on Confidence Bands for Linear Regression Means-07-24-2015
A Note on Confidence Bands for Linear Regression Means-07-24-2015Junfeng Liu
 
High-Density 3D (HD3D) EAGE Workshop 092004 Andrew Long
High-Density 3D (HD3D) EAGE Workshop 092004 Andrew LongHigh-Density 3D (HD3D) EAGE Workshop 092004 Andrew Long
High-Density 3D (HD3D) EAGE Workshop 092004 Andrew LongAndrew Long
 
High Dimensional Data Visualization using t-SNE
High Dimensional Data Visualization using t-SNEHigh Dimensional Data Visualization using t-SNE
High Dimensional Data Visualization using t-SNEKai-Wen Zhao
 
(文献紹介)デブラー手法の紹介
(文献紹介)デブラー手法の紹介(文献紹介)デブラー手法の紹介
(文献紹介)デブラー手法の紹介Morpho, Inc.
 
Lossless image compression via by lifting scheme
Lossless image compression via by lifting schemeLossless image compression via by lifting scheme
Lossless image compression via by lifting schemeSubhashini Subramanian
 
POLCAL_shimada.pptx
POLCAL_shimada.pptxPOLCAL_shimada.pptx
POLCAL_shimada.pptxgrssieee
 
Internal multiple attenuation using inverse scattering: Results from prestack...
Internal multiple attenuation using inverse scattering: Results from prestack...Internal multiple attenuation using inverse scattering: Results from prestack...
Internal multiple attenuation using inverse scattering: Results from prestack...Arthur Weglein
 
Icuc1
Icuc1Icuc1
Icuc1epfl
 
Basics of edge detection and forier transform
Basics of edge detection and forier transformBasics of edge detection and forier transform
Basics of edge detection and forier transformSimranjit Singh
 
Lesson 24: Areas, Distances, the Integral (Section 021 slides)
Lesson 24: Areas, Distances, the Integral (Section 021 slides)Lesson 24: Areas, Distances, the Integral (Section 021 slides)
Lesson 24: Areas, Distances, the Integral (Section 021 slides)Matthew Leingang
 
Lesson 24: Areas, Distances, the Integral (Section 041 slides)
Lesson 24: Areas, Distances, the Integral (Section 041 slides)Lesson 24: Areas, Distances, the Integral (Section 041 slides)
Lesson 24: Areas, Distances, the Integral (Section 041 slides)Matthew Leingang
 

What's hot (18)

Visualization using tSNE
Visualization using tSNEVisualization using tSNE
Visualization using tSNE
 
SURF - Speeded Up Robust Features
SURF - Speeded Up Robust FeaturesSURF - Speeded Up Robust Features
SURF - Speeded Up Robust Features
 
ThesisFinal2
ThesisFinal2ThesisFinal2
ThesisFinal2
 
A computerized score for the automated differentiation of usual interstitial ...
A computerized score for the automated differentiation of usual interstitial ...A computerized score for the automated differentiation of usual interstitial ...
A computerized score for the automated differentiation of usual interstitial ...
 
3D gravity inversion by planting anomalous densities
3D gravity inversion by planting anomalous densities3D gravity inversion by planting anomalous densities
3D gravity inversion by planting anomalous densities
 
07 Tensor Visualization
07 Tensor Visualization07 Tensor Visualization
07 Tensor Visualization
 
Visualizing Data Using t-SNE
Visualizing Data Using t-SNEVisualizing Data Using t-SNE
Visualizing Data Using t-SNE
 
A Note on Confidence Bands for Linear Regression Means-07-24-2015
A Note on Confidence Bands for Linear Regression Means-07-24-2015A Note on Confidence Bands for Linear Regression Means-07-24-2015
A Note on Confidence Bands for Linear Regression Means-07-24-2015
 
High-Density 3D (HD3D) EAGE Workshop 092004 Andrew Long
High-Density 3D (HD3D) EAGE Workshop 092004 Andrew LongHigh-Density 3D (HD3D) EAGE Workshop 092004 Andrew Long
High-Density 3D (HD3D) EAGE Workshop 092004 Andrew Long
 
High Dimensional Data Visualization using t-SNE
High Dimensional Data Visualization using t-SNEHigh Dimensional Data Visualization using t-SNE
High Dimensional Data Visualization using t-SNE
 
(文献紹介)デブラー手法の紹介
(文献紹介)デブラー手法の紹介(文献紹介)デブラー手法の紹介
(文献紹介)デブラー手法の紹介
 
Lossless image compression via by lifting scheme
Lossless image compression via by lifting schemeLossless image compression via by lifting scheme
Lossless image compression via by lifting scheme
 
POLCAL_shimada.pptx
POLCAL_shimada.pptxPOLCAL_shimada.pptx
POLCAL_shimada.pptx
 
Internal multiple attenuation using inverse scattering: Results from prestack...
Internal multiple attenuation using inverse scattering: Results from prestack...Internal multiple attenuation using inverse scattering: Results from prestack...
Internal multiple attenuation using inverse scattering: Results from prestack...
 
Icuc1
Icuc1Icuc1
Icuc1
 
Basics of edge detection and forier transform
Basics of edge detection and forier transformBasics of edge detection and forier transform
Basics of edge detection and forier transform
 
Lesson 24: Areas, Distances, the Integral (Section 021 slides)
Lesson 24: Areas, Distances, the Integral (Section 021 slides)Lesson 24: Areas, Distances, the Integral (Section 021 slides)
Lesson 24: Areas, Distances, the Integral (Section 021 slides)
 
Lesson 24: Areas, Distances, the Integral (Section 041 slides)
Lesson 24: Areas, Distances, the Integral (Section 041 slides)Lesson 24: Areas, Distances, the Integral (Section 041 slides)
Lesson 24: Areas, Distances, the Integral (Section 041 slides)
 

Similar to Bump Mapping Unparametrized Surfaces on the GPU

Normalized averaging using adaptive applicability functions with applications...
Normalized averaging using adaptive applicability functions with applications...Normalized averaging using adaptive applicability functions with applications...
Normalized averaging using adaptive applicability functions with applications...guest31063e
 
Approximate Thin Plate Spline Mappings
Approximate Thin Plate Spline MappingsApproximate Thin Plate Spline Mappings
Approximate Thin Plate Spline MappingsArchzilon Eshun-Davies
 
Texture mapping
Texture mapping Texture mapping
Texture mapping wahab13
 
30th コンピュータビジョン勉強会@関東 DynamicFusion
30th コンピュータビジョン勉強会@関東 DynamicFusion30th コンピュータビジョン勉強会@関東 DynamicFusion
30th コンピュータビジョン勉強会@関東 DynamicFusionHiroki Mizuno
 
ImageSegmentation (1).ppt
ImageSegmentation (1).pptImageSegmentation (1).ppt
ImageSegmentation (1).pptNoorUlHaq47
 
ImageSegmentation.ppt
ImageSegmentation.pptImageSegmentation.ppt
ImageSegmentation.pptAVUDAI1
 
ImageSegmentation.ppt
ImageSegmentation.pptImageSegmentation.ppt
ImageSegmentation.pptDEEPUKUMARR
 
A Rapid Location Independent Full Tensor Gravity Algorithm
A Rapid Location Independent Full Tensor Gravity AlgorithmA Rapid Location Independent Full Tensor Gravity Algorithm
A Rapid Location Independent Full Tensor Gravity AlgorithmPioneer Natural Resources
 
Scale Invariant Feature Tranform
Scale Invariant Feature TranformScale Invariant Feature Tranform
Scale Invariant Feature TranformShanker Naik
 
A STUDY AND ANALYSIS OF DIFFERENT EDGE DETECTION TECHNIQUES
A STUDY AND ANALYSIS OF DIFFERENT EDGE DETECTION TECHNIQUESA STUDY AND ANALYSIS OF DIFFERENT EDGE DETECTION TECHNIQUES
A STUDY AND ANALYSIS OF DIFFERENT EDGE DETECTION TECHNIQUEScscpconf
 
SIFT/SURF can achieve scale, rotation and illumination invariant during image...
SIFT/SURF can achieve scale, rotation and illumination invariant during image...SIFT/SURF can achieve scale, rotation and illumination invariant during image...
SIFT/SURF can achieve scale, rotation and illumination invariant during image...National Cheng Kung University
 
Newton cotes integration method
Newton cotes integration  methodNewton cotes integration  method
Newton cotes integration methodshashikant pabari
 
Projection of a Vector upon a Plane from an Arbitrary Angle, via Geometric (C...
Projection of a Vector upon a Plane from an Arbitrary Angle, via Geometric (C...Projection of a Vector upon a Plane from an Arbitrary Angle, via Geometric (C...
Projection of a Vector upon a Plane from an Arbitrary Angle, via Geometric (C...James Smith
 
EDGE DETECTION IN RADAR IMAGES USING WEIBULL DISTRIBUTION
EDGE DETECTION IN RADAR IMAGES USING WEIBULL DISTRIBUTIONEDGE DETECTION IN RADAR IMAGES USING WEIBULL DISTRIBUTION
EDGE DETECTION IN RADAR IMAGES USING WEIBULL DISTRIBUTIONcscpconf
 
EDGE DETECTION IN RADAR IMAGES USING WEIBULL DISTRIBUTION
EDGE DETECTION IN RADAR IMAGES USING WEIBULL DISTRIBUTIONEDGE DETECTION IN RADAR IMAGES USING WEIBULL DISTRIBUTION
EDGE DETECTION IN RADAR IMAGES USING WEIBULL DISTRIBUTIONcsitconf
 
Image Processing
Image ProcessingImage Processing
Image ProcessingTuyen Pham
 
Parallel Evaluation of Multi-Semi-Joins
Parallel Evaluation of Multi-Semi-JoinsParallel Evaluation of Multi-Semi-Joins
Parallel Evaluation of Multi-Semi-JoinsJonny Daenen
 
Chapter10 image segmentation
Chapter10 image segmentationChapter10 image segmentation
Chapter10 image segmentationasodariyabhavesh
 

Similar to Bump Mapping Unparametrized Surfaces on the GPU (20)

Normalized averaging using adaptive applicability functions with applications...
Normalized averaging using adaptive applicability functions with applications...Normalized averaging using adaptive applicability functions with applications...
Normalized averaging using adaptive applicability functions with applications...
 
Approximate Thin Plate Spline Mappings
Approximate Thin Plate Spline MappingsApproximate Thin Plate Spline Mappings
Approximate Thin Plate Spline Mappings
 
Texture mapping
Texture mapping Texture mapping
Texture mapping
 
30th コンピュータビジョン勉強会@関東 DynamicFusion
30th コンピュータビジョン勉強会@関東 DynamicFusion30th コンピュータビジョン勉強会@関東 DynamicFusion
30th コンピュータビジョン勉強会@関東 DynamicFusion
 
Image segmentation
Image segmentationImage segmentation
Image segmentation
 
ImageSegmentation (1).ppt
ImageSegmentation (1).pptImageSegmentation (1).ppt
ImageSegmentation (1).ppt
 
ImageSegmentation.ppt
ImageSegmentation.pptImageSegmentation.ppt
ImageSegmentation.ppt
 
ImageSegmentation.ppt
ImageSegmentation.pptImageSegmentation.ppt
ImageSegmentation.ppt
 
New test123
New test123New test123
New test123
 
A Rapid Location Independent Full Tensor Gravity Algorithm
A Rapid Location Independent Full Tensor Gravity AlgorithmA Rapid Location Independent Full Tensor Gravity Algorithm
A Rapid Location Independent Full Tensor Gravity Algorithm
 
Scale Invariant Feature Tranform
Scale Invariant Feature TranformScale Invariant Feature Tranform
Scale Invariant Feature Tranform
 
A STUDY AND ANALYSIS OF DIFFERENT EDGE DETECTION TECHNIQUES
A STUDY AND ANALYSIS OF DIFFERENT EDGE DETECTION TECHNIQUESA STUDY AND ANALYSIS OF DIFFERENT EDGE DETECTION TECHNIQUES
A STUDY AND ANALYSIS OF DIFFERENT EDGE DETECTION TECHNIQUES
 
SIFT/SURF can achieve scale, rotation and illumination invariant during image...
SIFT/SURF can achieve scale, rotation and illumination invariant during image...SIFT/SURF can achieve scale, rotation and illumination invariant during image...
SIFT/SURF can achieve scale, rotation and illumination invariant during image...
 
Newton cotes integration method
Newton cotes integration  methodNewton cotes integration  method
Newton cotes integration method
 
Projection of a Vector upon a Plane from an Arbitrary Angle, via Geometric (C...
Projection of a Vector upon a Plane from an Arbitrary Angle, via Geometric (C...Projection of a Vector upon a Plane from an Arbitrary Angle, via Geometric (C...
Projection of a Vector upon a Plane from an Arbitrary Angle, via Geometric (C...
 
EDGE DETECTION IN RADAR IMAGES USING WEIBULL DISTRIBUTION
EDGE DETECTION IN RADAR IMAGES USING WEIBULL DISTRIBUTIONEDGE DETECTION IN RADAR IMAGES USING WEIBULL DISTRIBUTION
EDGE DETECTION IN RADAR IMAGES USING WEIBULL DISTRIBUTION
 
EDGE DETECTION IN RADAR IMAGES USING WEIBULL DISTRIBUTION
EDGE DETECTION IN RADAR IMAGES USING WEIBULL DISTRIBUTIONEDGE DETECTION IN RADAR IMAGES USING WEIBULL DISTRIBUTION
EDGE DETECTION IN RADAR IMAGES USING WEIBULL DISTRIBUTION
 
Image Processing
Image ProcessingImage Processing
Image Processing
 
Parallel Evaluation of Multi-Semi-Joins
Parallel Evaluation of Multi-Semi-JoinsParallel Evaluation of Multi-Semi-Joins
Parallel Evaluation of Multi-Semi-Joins
 
Chapter10 image segmentation
Chapter10 image segmentationChapter10 image segmentation
Chapter10 image segmentation
 

Recently uploaded

How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 

Recently uploaded (20)

How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 

Bump Mapping Unparametrized Surfaces on the GPU

  • 1. Bump Mapping Unparametrized Surfaces on the GPU Morten S. Mikkelsen Naughty Dog Inc., USA May 24, 2010 Abstract the footprint. Furthermore, when deformation of the surface is applied the first order derivatives must be Original bump mapping is only defined for surfaces reevaluated every frame. For a deformation which with a known surface parametrization. In this paper is not based on linear transformations the reevalua- a new method, for the GPU, is proposed which does tion requires a fully deformed version of the surface not use such a given parametrization. To compute in memory which means deformation cannot be done the perturbed normal the only inputs used are the in a vertex shader. These problems were solved in surface position, the height value and the original [Sch06] by computing first order derivatives in the normal. fragment shader. However, this solution still uses The method decouples bump mapping from the normal maps and requires 2D texture coordinates. primitive type which allows for a higher degree of A height map represents a single value per texel proceduralism in both generation of the height value and thus has the potential to compress better than and the surface. the equivalent normal map. A normal map may be thought of as height derivative map which requires two values. Furthermore, additional effects such as 1 Introduction parallax/relief texture mapping [KTI∗ 01], [OBM00] use a height map. In 1978, James Blinn published his paper [Bli78] on The requirement that 2D texture coordinates exist simulation of wrinkled surfaces. The aim of his pa- means the method does not apply to certain forms per was to mimic the high frequency surface irregu- of proceduralism. For instance the movie render- larities that we see in reality on objects everywhere. ing industry has enjoyed the ability to distribute Today the effect is known as bump mapping and is heights across a surface from compositions of scalar widely used in the computer graphics industry. In functions/textures defined on domains of arbitrary real–time computer graphics a variant known as tan- dimension since the introduction of the Reyes ar- gent space normal mapping is used. This is the same chitecture [CCC87]. Until now this ability has not effect but with height derivatives precomputed. For been available on the GPU. We present an efficient a proof the reader is referred to [Mik08]. method, for the GPU, which overcomes these lim- The effect is defined based on the premise that itations and does not rely on any predetermined a surface parametrization is known. For a trian- parametrization. gular mesh this is defined by texture coordinates which represent some unwrap of the surface onto a plane. The normal perturbation expression contains 2 The Formulation of Bump Mapping the first order derivatives of the surface parametriza- tion. For triangular meshes these are precomputed Let S ⊂ R3 represent some manifold surface and let at vertex level and stored in memory which adds to β represent the height function such that a scalar 1
  • 2. value is associated with each point on S. In Jim 3 The Surface Gradient Based Formulation Blinn’s formulation the surface S has a known sur- face parametrization and we denote this σ : (s, t) → The height function β represents a scalar field on the S where (s, t) ∈ R2 . Furthermore, the height map surface S. In vector calculus, the gradient of a scalar is assumed to be a function of the same parameter field is a vector field which points in the direction of β : (s, t) → R. Given the unit length surface normal the greatest rate of increase of the scalar field, and n the displaced surface is defined as whose magnitude is the greatest rate of change. The surface gradient S of a scalar field is tangent τ =σ+β·n to S. For any point p, on S, if there exists some local The surface normal of τ represents the perturbed extension of β which is a smooth function on some normal n used in bump mapping. To simplify the open subset of R3 , containing p, then the surface evaluation Blinn uses approximations for the first gradient at p is equal to order derivatives in which the last term is canceled. Sβ = β − n · (n • β) (2) τs σ s + βs · n τt σ t + βt · n which is the projection of the regular gradient onto the tangent plane. For a known chart σ, containing Note that the normal n represents the visible side p, the surface gradient is equal to of the initial surface S. It is not taken into account in [Bli78] that the parametrization defined by σ is Sβ = βs βt 0 · N −1 not necessarily orientation preserving. A derivation, (σt × n)βs + (n × σs )βt of the perturbed normal n , which takes this into = (3) n • (σs × σt ) account is given in [Mik08] and the unnormalized result is The surface gradient S β has the two properties that it is a vector in the tangent plane and that the   N =  σs σt n  dot product between it and some given unit length tangent vector v gives the rate of change in the di-   rection of v. Equation (3) clearly obeys the former −βs and the latter is true since S β • v = a · βs + b · βt n = (N −1 )T ·  −βt  for v = aσs + bσt where a, b ∈ R. 1 From equations (1) and (3) it follows that the per- (n × σt )βs + (σs × n)βt turbed normal can be expressed as = n+ (1) n • (σs × σt ) n =n− Sβ (4) where the symbol • denotes the dot product. Fur- thermore, the denominator in the second term of Intuitively this means the normal is pulled away equation (1) is equal to from the tangent direction of the greatest rate of det(N ) = n • (σs × σt ) increase in β. Interestingly the result is identical to Blinn’s perturbed normal, for a known surface = ± σs × σt parametrization, as indicated by equation (3). and is positive when the parametrization is orienta- The form given by equation (4) indicates that tion preserving. The formulation given here is al- the perturbed normal does not depend on a specific most identical to that of Jim Blinn except that it is parametrization. It depends on the shape of the sur- not an assumption here that det(N ) is positive. face and the distribution of height values. Thus we In the following section we will give a formulation can evaluate the surface gradient S β using some, of bump mapping which does not require a user– per pixel chosen, local parametrization. For our so- defined parametrization of S or β. lution we choose inverse projection from the screen 2
  • 3. domain M ⊂ R2 to the surface S. Inverse projec- float3 PerturbNormal ( float3 surf_pos , tion does not represent a valid chart for the entire float3 surf_norm , float height ) { surface since a coordinate (s0 , t0 ) ∈ M can map to float3 vSigmaS = ddx ( surf_pos ) ; multiple points on S. However, the map represents float3 vSigmaT = ddy ( surf_pos ) ; a valid local parametrization σ at each intersection float3 vN = surf_norm ; // n o r m a l i z e d point. In other words the intersection point is con- float3 vR1 = cross ( vSigmaT , vN ) ; tained in some small neighborhood on S which does float3 vR2 = cross ( vN , vSigmaS ) ; not overlap itself if projected onto the screen. It is then a local diffeomorphism. For further details the float fDet = dot ( vSigmaS , vR1 ) ; reader is referred to the definition of a manifold and float dBs = ddx ( height ) ; also the inverse function theorem [Pre01]. float dBt = ddy ( height ) ; In the next section we will discuss how this math, equation (3) in particular, translates to a shader for float3 vSurfGrad = sign ( fDet ) * ( dBs * vR1 + dBt * vR2 ) ; the GPU. return normalize ( abs ( fDet ) * vN - vSurfGrad ) ; } 4 The Implementation Listing 1: Perturbed normal calculation without the use of texture coordinates. A surface is a two dimensional manifold which means on a small scale a neighborhood, containing p ∈ S, can be perceived as planar. In a sense we inherit mals at the vertices which are, subsequently, inter- the differential structure associated with R2 . On polated across the triangle to produce a look which the GPU a surface is rendered as some, arbitrarily is more soft. We use the same normalized interpo- dense, triangular representation which compliments lation of the vertex normals as the input parameter this concept. A triangle does not overlap itself after surf_norm. If the vertex normals are not known projection unless the projection is a line segment or then the normal of the triangle can be obtained us- a point in which case it is rejected by the GPU. Thus ing cross(vSigmaS, vSigmaT) instead. inverse projection from the screen to the triangle is a valid parametrization. We denote this σ : (s, t) → p where the coordinate of the pixel center is (s, t) and the corresponding point on the triangle is p. This function is resolved simply by passing the vertex po- sition to the interpolator. To compute the surface gradient by equation (3) we must produce the derivatives σs , σt , βs and βt . The screen–space derivative calculation func- tions provided by the GPU are known as ddx and ddy. On the current generation these produce the same result for pixel pairs in blocks of 2 × 1 and 1 × 2 respectively. Better results would be achieved (a) flat (b) smooth by using central differencing but in order to keep the solution simple and effective we rely on the built–in calculation. The implementation is shown in listing Figure 1: In figure 1(a) we see hard edges as a result 1. of using τs × τt to produce the normal. Using the A triangular mesh is piecewise flat. However, it is method in listing 1 perturbs the interpolated vertex common in computer graphics to use averaged nor- normal as shown in figure 1(b). 3
  • 4. For completion we point out that there exists an also a possibility. For instance forward differencing even simpler approach to perturb the normal. This is used by Perlin in [Per04]. is the cross product between the first order deriva- The difference between Perlin’s perturbation tives of the displaced surface position τs × τt . How- method and equation (4) is visually significant. If ever, this will perturb the face normal and not the the gradient is above the tangent plane the perturba- interpolated vertex normal. A comparison between tion impact is reduced and results are understated. this approach and our solution is shown in figure 1. If the gradient is below the tangent plane the per- The method which we have discussed until now turbation impact is increased. This increase even- relies on the availability of the shader functions ddx tually results in the perturbed normal pointing in- and ddy. This issue will be discussed in the next ward. A visual is shown in figure 2(a) based on a section. low frequency Perlin noise for the height map. The negated gradient was used to produce this picture since adding it effectively inverts the height map. 5 Pre and Post–Process Bump Mapping Using the function in listing 2 gives the artifact free result shown in figure 2(b). The shader function given by listing 1 can only be used in a pixel shader during the in–process fixed function rasterization of triangles. This excludes 6 Results bump mapping in a pre–process such as a vertex The results presented in this section were pro- shader or any post–processing solution such as de- duced using an implementation in OpenGL using ferred rendering. Though the method in listing 1 the CgFX shading language. Our first scene is a supports spatial height maps we can, for such a map, triangulated isosurface with a single point light. We achieve the same normal perturbation without it. assign a height to each surface point using the spa- tial function turbulence() by Ken Perlin [Per85]. float3 PerturbNormal ( float3 surf_norm , Six octaves are used and the Perlin noise function float3 vGrad ) { float3 vSurfGrad = vGrad - surf_norm * dot ( surf_norm , vGrad ) ; return normalize ( surf_norm - vSurfGrad ) ; } Listing 2: This is the surface gradient based normal perturbation using a spatial height map. It was proposed by Perlin [Per85] that a normal perturbing effect can be achieved by adding the gra- dient, of a spatial texture, to the unit normal n. However, this does not produce the normal associ- ated with the displaced surface. In this paper we (a) Perlin’s perturbation (b) Surface gradient based have proved that Jim Blinn’s formulation of the per- method turbed normal is equivalent to equation (4). Our implementation is shown in listing 2. The function takes as input the gradient of the spatial texture β. Figure 2: The result of Perlin based normal per- For some functions the gradient can be determined turbation is shown in figure 2(a). There are visual analytically which is the case for Perlin noise. When artifacts which are gone using our method shown in this is not the case then numerical approximation is figure 2(b). 4
  • 5. (a) method in listing 1 (b) method in listing 2 (c) image cut out 1 (d) image cut out 2 Figure 3: Figures 3(a) and 3(b) confirm that the same results are produced by the surface gradient method and listing 1 which is our ddx and ddy based implementation. However, looking closer at the images as shown in figures 3(c) and 3(d) shows that the quality of derivative calculation using the function in listing 1 depends on pixel density. is done with the implementation by Simon Green ing the function in listing 1 and normal mapping in [Gre05]. Note that the gradient of Perlin noise using interpolation of per vertex tangent spaces. has an analytical solution dnoise() which can eas- The model used is a treasure item from the game ily be implemented in a shader. This implies that ”Uncharted 2: Among Thieves”. Again results are the resulting perturbed normal has an analytical so- the same as shown in figures 4(a) and 4(b). How- lution using equations (2) and (4). However, the ever, there is a difference since derivatives are com- function turbulence() accumulates numerical val- puted in screen–space from a reconstruction of the ues of noise so we use central differencing to approx- height function. This reconstruction is done using imate the gradient. The result is shown in figure the built–in texture sampler which produces a sig- 3(b) and the corresponding result in figure 3(a) us- nal of relatively low accuracy. For instance when the ing the function in listing 1. The results are the same texture map is magnified due to undersampling the which confirms the analysis in section 3. However, reconstruction of heights is reduced to a piecewise at closer inspection there are differences in terms of linear function. The derivative function of such a quality since the derivative calculation using listing 1 signal is a piecewise constant function. The result is depends on the pixel density across the surface rela- illustrated as a close up of the model in figure 4(e). tive to the frequency level of the height function. As an example a small part of the sphere in figures 3(a)– 3(b) is shown in figures 3(c)–3(d) respectively. Note that these correspond to zooming in on the images. A possible solution is of course to use higher or- In contrast approaching the sphere increases pixel der filtering but this makes the solution significantly density and gives similar results using these meth- more expensive. We propose either accepting the ods. Increasing the resolution or super–sampling will limitation of the method or hiding the problem us- also achieve this. ing a well known solution which is detail maps. Fig- ure 4(f) shows the result of using turbulence() for The following test compares results between us- detail. 5
  • 6. 7 Conclusion References [Bli78] Blinn J.: Simulation of wrinkled surfaces. In In this paper we have shown how bump mapping ACM Computer Graphics (SIGGRAPH ’78) can be done on the GPU using the following inputs (1978), pp. 286–292. only in the perturbation function: surface position, [CCC87] Cook R. L., Carpenter L., Catmull E.: surface normal and the height value. The reyes image rendering architecture. In The solution works without precomputed tangent ACM Computer Graphics (SIGGRAPH ’87) (1987), ACM, pp. 95–102. vectors and in fact does not even require that the height value is produced from a texture coordinate. [Gre05] Green S.: GPU Gems 2 – Pro- The height function can be either spatial or defined gramming Techniques for High–Performance on the 2D domain. It can be analytical/procedural Graphics and General–Purpose Computa- tion”. Addison–Wesley Publishing, 2005, or represented by a texture map. Thus our method ch. 26, pp. 409–416. presents a uniform solution to determine the per- turbed normal. [KTI∗ 01] Kaneko T., Takahei T., Inami M., Kawakami N., Yanagida Y., Maeda T., A limitation exists due to our use of the screen– Tachi S.: Detailed shape representation with space derivative instructions ddx and ddy. These are parallax mapping. In Proceedings of the ICAT only available when using the built–in rasterization 2001 (2001), pp. 205–208. pipeline of the GPU which is restricted to triangles. [Mik08] Mikkelsen M. S.: Simulation of Wrinkled This excludes certain use cases such as perturbation Surfaces Revisited. Master’s thesis, Depart- of the normal during a deferred process. However, ment of Computer Science at the University in this paper we have shown that Jim Blinn’s formu- of Copenhagen, 2008. lation of the perturbed normal is equivalent to sub- [OBM00] Oliveira M. M., Bishop G., McAllis- tracting the surface gradient of the height function ter D.: Relief texture mapping. In ACM from the unit normal. Thus if the height function Computer Graphics (SIGGRAPH ’00) (2000), is spatial, such as Perlin noise, the normal can be Addison–Wesley Publishing, pp. 359–368. perturbed without the use of ddx and ddy. This is [Per85] Perlin K.: An image synthesizer. SIG- particularly efficient in the case of Perlin noise be- GRAPH Comput. Graph. 19, 3 (1985), 287– cause it has an analytical gradient function. When 296. this is not the case the gradient can be approximated [Per04] Perlin K.: GPU Gems – Programming Tech- numerically. niques, Tips and Tricks for Real-Time Graph- The primary limitation is that bump mapping in ics. Addison–Wesley Publishing, 2004, ch. 5, the general case is only supported during in–process pp. 409–416. rendering of triangles. For future work it would be [Pre01] Pressley A.: Elementary Differential Geom- interesting to see if we can achieve support for two etry. Springer, 2001. dimensional height maps in the vertex shader and/or [Sch06] Schuler C.: Normal mapping with- achieve a uniform solution in post process. out precomputed tangents. In ShaderX5: Advanced Rendering Techniques, Engel W., (Ed.). Charles River Media, 2006, pp. 131– 140. Acknowledgments. This author would like to thank Bryan Mcnett for helpful discussions, Manchor Ko, Pal–Kristian Engstad, and Swaminathan Narayanan for constructive comments and proof reading. Finally, thank you to Naughty Dog for allowing me to use the treasure object for this paper. 6
  • 7. (a) method in listing 1 (b) normal mapping (c) no perturbation (d) method in listing 1 with albedo (e) undersampling (f) undersampling with detail 7 Figure 4: Our listing 1 method gives results which are very similar to that of normal mapping as shown in figures 4(a)-4(b). The model is shown without perturbation of normals, in figure 4(c), to illustrate which elements of the detail are in the height map. The final result is shown in figure 4(d) with the albedo map applied. When the height texture map is magnified the surface becomes piecewise flat as shown in figure 4(e). The shortcoming can be hidden by using a detail map which is shown in figure 4(f).