1 / 17

Demo: bumpy_shiny_patch

Demo: bumpy_shiny_patch. Cass Everitt. Overview. The bumpy_shiny_patch demo illustrates three key new extensions working together NV_evaluators NV_vertex_program NV_texture_shader

jonco
Download Presentation

Demo: bumpy_shiny_patch

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Demo: bumpy_shiny_patch Cass Everitt

  2. Overview • The bumpy_shiny_patch demo illustrates three key new extensions working together • NV_evaluators • NV_vertex_program • NV_texture_shader • The goal of bumpy_shiny_patch is to render a bumpy, mirrored, and deformable patch -- with an RGB glossmap to boot

  3. Game Plan • Use 4 NV_evaluators maps to generate • P, dP/du, dP/dv, and (s,t) texture coordinates • Pass these values in to a vertex program • Use NV_vertex_program to • Produce a set of normalized basis vectors • T = normalize(dP/du), N = normalize(TdP/Dv), and B = NT • Calculate the 3x3 “texel matrix” == CMS • basis vectors for S (surface to object space) • M is the upper 3x3 of the inverse transpose of the MODELVIEW matrix • C is the rotation from eye-space to world-space (or cubemap-space) • Put the texel matrix into the appropriate texture coordinates • Calculate the cubemap space eye vector, and put itinto the appropriate texture coordinates

  4. Game Plan (2) • Use NV_texture_shader “reflect cube map” dot product program to • Calculate a per-pixel reflection vector based on the normal map normals and the interpolated cubemap space eye vector • Use the reflection vector to look into a cubic environment map • Final “simple” 2D pass to modulate the framebuffer results with an RGB glossmap

  5. NV_evaluators • Map 0 uses a 4x4 patch for position • Map 1 uses a 3x4 patch for dP/du • This map is the difference of adjacent columns from map 0 • Map 2 uses a 4x3 patch for dP/dv • This map is the difference of adjacent rows from map 0 • Map 8 uses a 2x2 patch for texture coordinates • The tessellation scheme is irrelevant -- that’s the point!

  6. NV_vertex_program • The vertex program used to compute all the relevant values is shown • Note the following program parameter settings • c[0-3]: GL_MODELVIEW_PROJECTION_NV, GL_IDENTITY_NV • c[4]: (1, 2, 0, -1) // misc constants • c[5]: (refract_term, refract_term, 1, bump_scale) • c[8-11]: GL_MODELVIEW, GL_IDENTITY_NV • c[12-15]: GL_MODELVIEW, GL_INVERSE_NV • c[20-22]: modelview_cubemap matrix(object-space -> cubemap-space transform) • c[43-45]: modelview_negate_cubemap matrix(object-space position -> cubemap-space eye vector)

  7. NV_vertex_program (2) !!VP1.0# positionDP4 o[HPOS].x, c[0], v[OPOS] ;DP4 o[HPOS].y, c[1], v[OPOS] ;DP4 o[HPOS].z, c[2], v[OPOS] ;DP4 o[HPOS].w, c[3], v[OPOS] ; # R0 = normalize3(v[1]) --- tangentDP3 R0.w, v[1], v[1] ;RSQ R0.w, R0.w ;MUL R0.xyz, v[1], -R0.w ;# R2 = cross(R0,v[2]) --- normalMUL R2, R0.zxyw, v[2].yzxw ;MAD R2, R0.yzxw, v[2].zxyw, -R2 ;# R2 = normalize(R2)DP3 R2.w, R2, R2 ;RSQ R2.w, R2.w ;MUL R2.xyz, R2, R2.w ;# R1 = cross(R0,R2) --- binormalMUL R1, R0.zxyw, R2.yzxw ;MAD R1, R0.yzxw, R2.zxyw, -R1 ;

  8. NV_vertex_program (3) # We need the "texel matrix" to be (C)(MV)(S)(B), where C is the cubemap# rotation, MV is the modelview matrix and S is the matrix that transforms# vectors from texture space to object space, and B is a simple uniform# scaling matrix. Specifically it is:# | b 0 0 |# B = | 0 b 0 |# | 0 0 1 |## | Tx Bx Nx | | R0.x R1.x R2.x |# S = | Ty By Ny | = | R0.y R1.y R2.y |# | Tz Bz Nz | | R0.z R1.z R2.z |## and (C)(MV) is pre-computed ## | c[20].x c[20].y c[20].z |# (C)(MV) = | c[21].x c[21].y c[21].z |# | c[22].x c[22].y c[22].z |## so (S)(B) is## | R3.x R3.y R3.z | | b*R0.x b*R1.x R2.x |# (S)(B) = | R4.x R4.y R4.z | = | b*R0.y b*R1.y R2.y |# | R5.x R5.y R5.z | | b*R0.z b*R1.z R2.z |#

  9. NV_vertex_program (4) # so (C)(MV)(S)(B) is## | DP3( c[20], R3) DP3( c[20], R4) DP3( c[20], R5) |# (C)(MV)(S)(B) = | DP3( c[21], R3) DP3( c[21], R4) DP3( c[21], R5) |# | DP3( c[22], R3) DP3( c[22], R4) DP3( c[22], R5) |## | o[TEX1].x o[TEX1].y o[TEX1].z |# = | o[TEX2].x o[TEX2].y o[TEX2].z |# | o[TEX3].x o[TEX3].y o[TEX3].z |

  10. NV_vertex_program (5) # calculate (S)(B) -- c[5].x = b (bump scale term)MUL R3, R0, c[5].w;MUL R4, R1, c[5].w;# compute (C)(MV)(S)(B) and put it in the correct texture coordinates# c[20-23] == modelview_cubemap matrix (object-space -> cubemap-space transform)DP3 o[TEX1].x, c[20], R3; DP3 o[TEX1].y, c[20], R4; DP3 o[TEX1].z, c[20], R2;DP3 o[TEX2].x, c[21], R3; DP3 o[TEX2].y, c[21], R4; DP3 o[TEX2].z, c[21], R2;DP3 o[TEX3].x, c[22], R3; DP3 o[TEX3].y, c[22], R4; DP3 o[TEX3].z, c[22], R2;# calculate cubemap-space eye vectorDP4 o[TEX1].w, v[OPOS], c[43];DP4 o[TEX2].w, v[OPOS], c[44];DP4 o[TEX3].w, v[OPOS], c[45];# col0 = white and pass tex0 coordinates throughMOV o[COL0], c[4]; MOV o[TEX0], v[TEX0];END

  11. NV_texture_shader • Configure the texture shader stages as follows // stage 0 -- normal mapglActiveTextureARB( GL_TEXTURE0_ARB );normalmap.bind();glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_2D);// stage 1 -- dot productglActiveTextureARB( GL_TEXTURE1_ARB );glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_DOT_PRODUCT_NV);glTexEnvi(GL_TEXTURE_SHADER_NV, GL_PREVIOUS_TEXTURE_INPUT_NV, GL_TEXTURE0_ARB);// stage 2 -- dot productglActiveTextureARB( GL_TEXTURE2_ARB );glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_DOT_PRODUCT_NV);glTexEnvi(GL_TEXTURE_SHADER_NV, GL_PREVIOUS_TEXTURE_INPUT_NV, GL_TEXTURE0_ARB);// stage 3 -- dot product, cube map lookupglActiveTextureARB( GL_TEXTURE3_ARB );cubemap.bind();glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_DOT_PRODUCT_REFLECT_CUBE_MAP_NV);glTexEnvi(GL_TEXTURE_SHADER_NV, GL_PREVIOUS_TEXTURE_INPUT_NV, GL_TEXTURE0_ARB);glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

  12. The Bump Map and Gloss Map

  13. The Environment Map

  14. The Results

  15. Note • In this example, the upper-left 3x3 of the modelview matrix (M) and the upper-left 3x3 of the inverse transpose of the modelview matrix(M-t) are used interchangeably. This is because the modelview matrix contains only rigid-body transformations (rotation and translation), and in this case the matrices are identical.

  16. Related Information • See “The dot_product_reflect and dot_product_reflect_torus Demos” presentation and the corresponding demos for simple examples of object-space and tangent-space reflective bump mapping

  17. Questions, comments, feedback • Cass Everitt, ceveritt@nvidia.com • www.nvidia.com/developer

More Related