欢迎来到淘文阁 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
淘文阁 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

    3D游戏编程OpenGL纹理和缓存.pdf

    • 资源ID:70321773       资源大小:6.79MB        全文页数:59页
    • 资源格式: PDF        下载积分:15金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要15金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    3D游戏编程OpenGL纹理和缓存.pdf

    OpenGL:Texture&Buffers Yanci Zhang Game Programming IIGame Programming II Concept of texture mapping Difficulties and solutions in texture mapping Texture mapping in OpenGL Buffers in OpenGL Game Programming IIGame Programming II Outline How to add more details to surfaces?Using more triangles Using texture mapping without increasing geometry complexity Game Programming IIGame Programming II Texture Mapping Shading Texture Mapping Advanced texture mapping techniques can add more details!Game Programming IIGame Programming II Texture Mapping Uses of texture mapping Simulate materials Reducing geometric complexity Image warping Reflection Game Programming IIGame Programming II Texture Mapping What we can do now Using vertex color to specify object color Using light sources and object materials to produce more realistic result But these are far from enough!Real objects have lots of details Texture mapping can Add details to surfaces Not increase#of vertices Game Programming IIGame Programming II Texture Mapping A texture is a bitmap of pixel colors that give an object the appearance of texture Mapping 2D images to 3D surfaces Texture can be 1D,2D even 3D Key question:how to build the connection between 2D texture coordinates and 3D object coordinates Game Programming IIGame Programming II What is Texture Mapping 1/2 Game Programming IIGame Programming II What is Texture Mapping 2/2 Images and geometry flow through separate pipelines that join at the rasterizer Textures do NOT affect geometric complexity Every vertex has its own texture coordinate Texture coordinates of fragments are interpolated from vertices in rasterizztion stage Texture lookups are executed in fragment processing stage Game Programming IIGame Programming II Texture Mapping in Pipeline Screen Coordinates Where the final image is produced World Coordinates Conceptually,where the mapping takes place Texture coordinates Used to identify points in the image to be mapped Parametric coordinates May be used to model curved surfaces Game Programming IIGame Programming II Coordinate Systems The map from texture coordinates to geometric coordinates may be a complex function or may have undesirable properties Prefer the inverse map from screen coordinates to texture coordinates Antialiasing problem Game Programming IIGame Programming II Difficulties Forward mapping Texture coordinate(s,t)geometric coordinate(x,y,z,w)Such mapping maybe hard to be built in practice Backward mapping Texture coordinate(s,t)geometric coordinate(x,y,z,w)s=s(x,y,z,w),t=t(x,y,z,w)Game Programming IIGame Programming II Forward and Backward Mapping Two approaches:Mapping texture onto parametric surface Two-part mapping Game Programming IIGame Programming II Solutions to Mapping Problem The 3D coordinates of surface point p is given in terms of some parameters u,v Game Programming IIGame Programming II Parametric Surface Map texel coordinates(s,t)onto the surface parameters(u,v)Often use linear map Simple If ae!=bd,this mapping is invertible;May distort the texture shape Game Programming IIGame Programming II Mapping Texture First Step(S Mapping)Mapping texture to a simple 3D intermediate surface(Cylinder,box,sphere)Second Step(O Mapping)Mapping texture values on the intermediate object to the desired surface Game Programming IIGame Programming II Two-Part Mapping Parametric representation Maps rectangle in u,v space to cylinder of radius r and height h in world coordinates Map from(u,v)to(s,t)Game Programming IIGame Programming II S Mapping Example:Cylinder Easy to use with simple orthographic projection Also used in environmental maps Game Programming IIGame Programming II S Mapping Example:Box Parametric representation In a similar manner to the cylinder but have to decide where to put the distortion Spheres are used in environmental maps Game Programming IIGame Programming II S Mapping Example:Sphere Three possible strategies Intermediate surface normal Object normal Object centroid Game Programming IIGame Programming II O Mapping May introduce undesired texture distortions if the intermediate surface differs much from the destination surface Game Programming IIGame Programming II Problem of Two-Part Mapping A single screen pixel can correspond to anything from a tiny portion of a texel(magnification)to a large collection of texels(minification)Point Sampling vs.Area Averaging Game Programming IIGame Programming II Aliasing Problem Game Programming IIGame Programming II Artifacts in Point Sampling Texture image Game Programming IIGame Programming II Another Example A better but slower option is to use area averaging Game Programming IIGame Programming II Area Averaging Pixel size texel size Game Programming IIGame Programming II Minification Game Programming IIGame Programming II Mip Mapping Game Programming IIGame Programming II Applying Textures Three steps Specify texture Read or generate image Assign to texture Enable texturing Assign texture coordinates to vertices Specify texture parameters Warping,filtering Game Programming IIGame Programming II Applying Textures Detailed steps specify textures in texture objects set texture filter set texture function set texture wrap mode set optional perspective correction hint bind texture object enable texturing supply texture coordinates for vertex coordinates can also be generated One image per texture object Generate texture names glGenTextures(GLsizei n,GLuint*textures);Returns n texture names in the textures parameter Texture names are not necessarily a contiguous set of integers Game Programming IIGame Programming II Texture Objects Create texture objects with texture data and state glBindTexture(GLenum target,GLuint texture);Bind textures before using glBindTexture(GLenum target,GLuint texture);Game Programming IIGame Programming II Texture Objects Define a texture image from an array of texels in CPU memory glTexImage2D(GLenum target,GLint level,GLint internalformat,GLsizei width,GLsizei height,GLint border,GLenum format,GLenum type,const GLvoid*pixels );Game Programming IIGame Programming II Specify Texture Image Contains 1-4 components(s,t,r,q)The range of each component is normally 0,1 glTexCoord*()specified at each vertex glTexCoord*()has to be called in a pair of glBegin()/glEnd()Game Programming IIGame Programming II Texture Coordinates s t 1,1 0,1 0,0 1,0(s,t)=(0.2,0.8)(0.4,0.2)(0.8,0.4)A B C a b c Texture Space Object Space OpenGL has a variety of parameters that determine how texture is applied Wrapping parameters determine what happens if s and t are outside the(0,1)range Filter modes allow us to use area averaging instead of point samples Mipmapping allows us to use textures at multiple resolutions Environment parameters determine how texture mapping interacts with shading Game Programming IIGame Programming II Texture Parameters glTexParameter(GLenum target,GLenum pname,Type param)target:GL_TEXTURE_1D,GL_TEXTURE2D,GL_TEXTURE_3D pname:name of texture parameter param:value of texture parameter Game Programming IIGame Programming II Specifying Texture Parameters Wrap mode determines what should happen if a texture coordinate lies outside of the 0,1 range Warp mode can be configured for each component of texture coordinate separately Two modes in OpenGL GL_CLAMP:value at the extreme(either 0 or 1)is used GL_REPEAT:the integer is ignored and only the fractional value is used Game Programming IIGame Programming II Wrapping Mode How to sample texture images to avoid artifacts?Two different situations Magnification:One texel covers multiple pixels Nearest sampling Bilinear sampling Minification:One pixel covers multiple texels Game Programming IIGame Programming II Filter Modes Texture Polygon Magnification Minification Polygon Texture Mipmap allows for prefiltered texture maps of decreasing resolutions Lessens interpolation errors for smaller textured objects Declare mipmap level during texture definition glTexImage*D(GL_TEXTURE_*D,level,)Game Programming IIGame Programming II Mipmapped Textures Specifying magnification or minification GL_TEXTURE_MAG_FILTER GL_TEXTURE_MIN_FILTER Specifying filter modes GL_NEAREST GL_LINEAR Mipmap(used for GL_TEXTURE_MIN_FILTER only)Using the same level GL_NEAREST_MIPMAP_NEAREST GL_LINEAR_MIPMAP_NEAREST Using two levels GL_NEAREST_MIPMAP_LINEAR GL_LINEAR_MIPMAP_LINEAR Game Programming IIGame Programming II Specifying Filter Mode How texels and fragment colors are combined?glTexEnvfiv(GLenum target,GLenum pname,Type param)target:Must be GL_TEXTURE_ENV pname:Name of texture environment parameter.Accepted values are GL_TEXTURE_ENV_MODE,GL_TEXTURE_ENV_COLOR param GL_MODULATE:multiply texel and fragment color GL_BLEND:linearly blend texel,fragment,env color GL_REPLACE:replace fragments color with texel Game Programming IIGame Programming II Texture Environment Automatically generate texture coordinates glEnable(GL_TEXTURE_GEN_STRQ)glTexGenifdv(GLenum coord,GLenum pname,TYPE param)Configure the generation mode for s,t,r,q coordinates separately Generation modes GL_OBJECT_LINEAR GL_EYE_LINEAR GL_SPHERE_MAP Game Programming IIGame Programming II Texture Coordinates Generation Query largest dimension of texture image typically largest square texture doesnt consider internal format size glGetIntegerv(GL_MAX_TEXTURE_SIZE,&size)Texture proxy will memory accommodate requested texture size?no image specified;placeholder if texture wont fit,texture state variables set to 0 doesnt know about other textures only considers whether this one texture will fit all of memory Game Programming IIGame Programming II Is There Room for a Texture?Tricking eye into seeing smooth animation of rendered scenes Two buffers:front buffer and back buffer The front buffer is displayed while the application renders into the back buffer When application completes rendering,it requests hardware to swap the roles of the buffers Game Programming IIGame Programming II Double Buffering Request a double buffered color buffer glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE);Clear color buffer Render scene Request swap of front and back buffer glutSwapBuffers();Game Programming IIGame Programming II Double Buffering Determine which primitives in scene are occluded by other primitives Store pixels depth values(distance from camera)in depth buffer Only when a pixels depth is less than the stored value,its depth and color is written to buffers Depth value range from 0,1 After perspective projection Game Programming IIGame Programming II Depth Buffer if(pixel-z z)depthBuffer(x,y)-z=pixel-z;colorBuffer(x,y)-color=pixel-color;Incoming fragments have to pass the depth test before they are wrote to buffers Enable depth test:glEnable(GL_DEPTH_TEST)Determine whether writing depth value to buffer if fragment passes depth test glDepthMask(GLboolean flag)Game Programming IIGame Programming II Depth Test 1/2 Specify depth comparison function glDepthFunc(GLenum func)Game Programming IIGame Programming II Depth Test 2/2 Buffers are often cleared at the start of a frame The clear value can be specified by glClearColor(),glClearDepth()Clear the specified buffers by glClear()Game Programming IIGame Programming II Clearing Buffers Fragments generated in rasterization stage have to pass a serious of tests before wrote to buffers Fragment process and test Alpha test Depth test Alpha blending Game Programming IIGame Programming II Fragment Test Measure of opacity Valid range:0,1 Value 0:totally transparent Value 1:totally opaque Usages Simulating translucent objects like glass,water,etc.Blending and compositing images Antialiasing geometric primitives Game Programming IIGame Programming II Alpha:the 4th Color Component Reject pixels based on their alpha value Enable alpha test:glEnable(GL_ALPHA_TEST)Specify alpha function glAlphaFunc(GLenum func,GLclampf ref)Game Programming IIGame Programming II Alpha Test Cloud rendering in computer games A popular solution:texture mapping+billboard+alpha test Similar technique is adopted in plants rendering Game Programming IIGame Programming II Alpha Test:Application Check a cool picture Game Programming IIGame Programming II Alpha Blending Blend color of incoming fragment with value stored in color buffer,and write the blended color back to buffer Enable alpha blending:glEnable(GL_BLEND)How to blend?Source:incoming RGB Destination:RGB that are already in the framebuffer Game Programming IIGame Programming II Alpha Blending in OpenGL 1/2 Ccomposite=src*Csrc+dst*Cdst Specify the blending factor glBlendFunc(GLenum sfactor,GLenum dfactor)Source factor:GL_ZERO,GL_ONE,GL_DST_COLOR,GL_ONE_MINUS_DST_COLOR,GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA,GL_DST_ALPHA,GL_ONE_MINUS_DST_ALPHA,and GL_SRC_ALPHA_SATURATE Destination factor:GL_ZERO,GL_ONE,GL_SRC_COLOR,GL_ONE_MINUS_SRC_COLOR,GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA,GL_DST_ALPHA,and GL_ONE_MINUS_DST_ALPHA Game Programming IIGame Programming II Alpha Blending in OpenGL 2/2 Render several transparent objects Steps Objects have to been rendered from back to front in camera space Sort objects before rendering How to implement it?Blending factor Source factor:GL_SRC_ALPHA Destination factor:GL_ONE_MINUS_SRC_ALPHA Game Programming IIGame Programming II Application 1/2 Render several objects and opaque objects together Steps:Render all opaque objects Depth test has to be enabled Render transparent objects Render objects from back to front in camera space Keep depth test on but disable depth write Blending factor Source factor:GL_SRC_ALPHA Destination factor:GL_ONE_MINUS_SRC_ALPHA Game Programming IIGame Programming II Application 2/2 Target:Render several objects and opaque objects together Render 5 teapots 4 transparent teapots locating at the corner of a square 1 opaque teapot in the center of square Deadline:2011-11-6 Please submit your assignment to teach assistants by email Game Programming IIGame Programming II Assignment

    注意事项

    本文(3D游戏编程OpenGL纹理和缓存.pdf)为本站会员(asd****56)主动上传,淘文阁 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知淘文阁 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于淘文阁 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

    本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

    工信部备案号:黑ICP备15003705号 © 2020-2023 www.taowenge.com 淘文阁 

    收起
    展开