去年因为去Moto上海研发中心研究人机交互的部门去面试, 临时学了一个星期的CG 编程,后来就束之高阁了,现在重新拾起来,在这里给自己学习历程留下一个回忆,若能给初学者一些借鉴,不胜荣幸。

学一门编程语言,首先需了解其发展历史,才能更全面把握它,了解其适用范围、优势。CG Shading Language  规范由M$和NVidia两强联合开发,NVidia的实现叫CG,MS的实现叫HLSL。HLSL是MS DirectX3D(简写D3D)的一部分,而CG则是跨平台的,即可用于D3D,又可用于OpenGL(OGL)。OGL下也有一个Shading Languge,叫GLSL,据说(这里只是道听途说,没证明过,没有贬低的意思)GLSL在NV的卡上和ATI的卡上效果可能会不一致,不是太稳定,而CG的效果比较稳定。GLSL的优势是跟OGL结合紧密,跟OGL一样也是跨平台的。学CG的好处是CG shader可以不经修改的用于D3D和OGL,到时转到D3D下也方便一些。其实CG、HLSL及GLSL都是类C 的 Shading Language,好多地方大同小异。

下面就了解一下CG的形成过程,为以后找工作笔试和面试考虑,就摘抄一些《 The CG Tutorial 》里面的一些句子,并根据自己理解,提炼总结一些东西,用英文写。很多大公司笔试都要求英文作答,就练练笔了。

Cg stands for "C for Graphic". The Cg language enables you to control the shape, appearance, and motion of objects drawn using GPU. It also enables you to modify the traditional graphics pipeline. A conventional graphics hardware pipelines processes a multitude of vertices, geometric primitives, and fragments in a pipelined form. Vertex transformation is the first processing stage in the graphics hardware pipeline, in this stage GPU performs a sequence of math operations on each vertex, including transforming the vertex position to a screen position used by the rasterizer, generating texture coordinates for texturing and lighting the vertex. The second stage is "primitive assembly and rasterization", in this stage GPU assembles vertices into geometric primitives. This results in a sequence of triangles, lines, or points. These primivives may require view frustum clipping, as well as application-specified clipping. The surviving polygons will be rasterized. The rasterizer may also discard polygons based on whether they face forward or backword. The rasterization will light a set of pixels and generate a set of fragments. A fragment has an associated pixel position, a depth value, and a set of interpolated parameters, such as a color, one or more texture coordinate.

GPU designs have evolved, and the vertex and fragment processors within the GPU have transitioned from being configurable to being programmable. The data-flow model for vetex processing begins by loading each vetex's attributes into vertex processor. When the vertex processor terminates, the output result registers contain the newly transformed vertex. After trianle setup and rasterization, the interpolated values for each register are passed to the fragment processor. The fragment processor has additional capability that it supports texturing operations.

CG inherits from three sources. First, Cg bases its syntax and semantics on the general-purpose C Language. Second, Cg incorporates many concepts from offline shading languages such as the RenderMan Shading Language, as well as prior hardware shading languages developed by academia. Third, Cg bases its graphics functionality on the OGL and D3D programming interfaces for real-time 3D.

下篇将会学习CG的基本语法、语义,然后做一个顶点光照实例,框架用 dot net Managed C++ 建立,并把CG 渲染部分封装成一个CGShader 及 CGShaderManager类,以方便按面向对象的方式运用CG。

CG 学习 (1)——CG概览相关推荐

  1. Cg学习之01_vertex_program

    电脑上有NVIDIA的伙伴可以在该路径"某盘:\NVIDIA Corporation\Cg\examples\OpenGL\basic"中找到官方的实例: 以01_vertex_p ...

  2. Shader学习之Cg语言一(Cg语言概述)

    该篇博客是我自己在学习Shader时,看<GPU编程与CG语言之阳春白雪下里巴人 >Cg语言概述这章,觉得有些东西自己记不住,因此记录下来. Cg ToolKit下载地址: NVIDIA ...

  3. OGRE+CG学习日记[1]-简单的3D程序

    OGRE+CG学习日记[1]-简单的3D程序 终于有时间开始研究OGRE和CG这些3D技术方面的东西了 先对今天的成果进行一下简单介绍 ­ 创建一个OGRE窗口,在里面放入一个怪兽头模型 ­ 写一个输 ...

  4. Shader学习之Cg语言二(Cg数据类型)

    由于在用Cg语言写代码的时候,没有好用的编辑器,也不可以像Java,C++,C#这类语言的断点调试,所有逻辑需要写得很小心,变量名字也需要自己全部记住,相当于在文本编辑器上写代码,这样一些数据类型名称 ...

  5. 2月份隐私计算、联邦学习的市场概览

    2月份隐私计算.联邦学习的市场概览 摘要:在隐私计算市场中,三股信息流如清风拂面,流转不息.采购意向,犹如花开满园,为供应商和服务提供商探明商机:招标信息,如云卷云舒,为客户了解市场动态提供重要参考: ...

  6. Cg学习记录002 之Uniform参数

    Uniform参数这一节书中给出的cg顶点程序参考代码如下: // This is C2E2f_passthru from "The Cg Tutorial" (Addison-W ...

  7. Shader学习之Cg语言三(Cg表达式与控制语句)

    Cg中的操作符与C语言中很类似,所以下面我就只是记录操作符对应的符号,细节和用法看着符号就会了. 关系操作符:<,<=,!=,==,>=,> 逻辑操作符:&&, ...

  8. Cg学习记录003 之Varying参数

    其实在Cg中是没有varying这种类型限制符的. 如何让程序不仅仅输出一个单一的颜色,而是可以随顶点改变的颜色或纹理坐标集呢? Cg教程中给出如下范例: // This is C3E2v_varyi ...

  9. CG学习prepare

    Shader 开发工具 FX Composer Render Monkey MonoDevelop 第三方IDE

最新文章

  1. 断点续传---多线程下载进阶(一)
  2. Markdown拾遗
  3. CRM Interactive Report的UI设计
  4. 依附B2B平台照样做搜索营销
  5. dhl:使用return RedirectToAction()和 return view()
  6. 图解浏览器缓存,教你提高用户体验
  7. vue和小程序哪个好学一点_litemall,Spring Boot后端,微信小程序用户前端 + Vue用户移动端...
  8. 定义表格的指定列的属性
  9. 回顾︱DeepAR 算法实现更精确的时间序列预测(二)
  10. Excel 2010的新功能简介
  11. 数字电子技术基础笔记(精简)
  12. Mac 安装JDK 8
  13. jsp post中文乱码
  14. 【PI调节】对PI调节的一些认识
  15. HDMI/DVI分配器芯片
  16. 聚簇索引,非聚簇索引
  17. WinForm分页控件
  18. chrome 谷歌浏览器模拟各种手机设置userAgent
  19. .mat图像显示(MATLAB实现)
  20. 机器学习-情感分析小案例

热门文章

  1. Java-JSOUP(爬虫)
  2. c语言散转指令,按键C语言.doc
  3. 【约束 约束 约束】
  4. 通信原理 | 通信的基本概念和通信系统的组成
  5. 超融合架构和服务器虚拟化是什么关系?主流超融合厂商服务器虚拟化产品对比分析
  6. pycharm 在 Clash模式下无法联网的解决办法
  7. 一条SQL语句查询所有任务分数都在60以上的用户名字
  8. 高并发基础之Java并发包
  9. 迷宫寻宝(自编简单版)
  10. 程序员应该学习如何学习