【OpenGL】使用Unity来学习OpenGL
来源:互联网 发布:北国光电淘宝网 编辑:程序博客网 时间:2024/05/15 14:07
转发,请保持地址:http://blog.csdn.net/stalendp/article/details/11492525
OpenGL是原理性和实践性比较强的一门技术,在学习的时候,如果能够跟着书中的例子,一边调试一边学习,效果将很好(这属于实验的一种类型吧,能够吧知识形象化,有助于学习兴趣的提高)。市面上有许多深入浅出的书籍讲的很好,比如《OpenGL SuperBible 5th Edition》、《OpenGL 4 Shanding Language Cookbook》等(前者的例子代码写的非常好,后者把OpenGL的原理讲的比较深入)。不过把这些书中的代码跑在特定的系统上,还是需要花一些代价的(比如在mac上,SLGL只支持到1.2,很多例子中的代码就需要改了;而且配置环境也是比较麻烦的)。在探寻了很久之后,发现Unity3D提供了很好的OpenGL的学习环境,并且还有一些很好的资料可以参考(强烈推荐Kenny Lammers的《Unity Shaders and Effects Cookbook》)。本文将介绍怎么在Unity3D上学习SLGL(关于OpenGL的pipeLine、VBO、PBO等其他一些,可以参考上面推荐的两本书,特别是把《OpenGL SuperBible 5th Edition》的那套工具类搞懂,就非常OK了)。这片文章源于对Minimal Shader的一个翻译和整理。
一、配置启动项(只有windows上需要)
- "C:\Program Files\Unity\Editor\Unity.exe" -force-opengl
二、创建Shader
- Shader "GLSL basic shader" { // defines the name of the shader
- SubShader { // Unity chooses the subshader that fits the GPU best
- Pass { // some shaders require multiple passes
- GLSLPROGRAM // here begins the part in Unity's GLSL
- #ifdef VERTEX // here begins the vertex shader
- void main() // all vertex shaders define a main() function
- {
- gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
- // this line transforms the predefined attribute
- // gl_Vertex of type vec4 with the predefined
- // uniform gl_ModelViewProjectionMatrix of type mat4
- // and stores the result in the predefined output
- // variable gl_Position of type vec4.
- }
- #endif // here ends the definition of the vertex shader
- #ifdef FRAGMENT // here begins the fragment shader
- void main() // all fragment shaders define a main() function
- {
- gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
- // this fragment shader just sets the output color
- // to opaque red (red = 1.0, green = 0.0, blue = 0.0,
- // alpha = 1.0)
- }
- #endif // here ends the definition of the fragment shader
- ENDGLSL // here ends the part in GLSL
- }
- }
- }
三、创建材质并绑定Shader
- Shader "GLSL basic shader" { // defines the name of the shader
- SubShader { // Unity chooses the subshader that fits the GPU best
- 。。。。。
四、把材质赋予游戏物体
关于OpenGL的资料:
Learning Modern 3D Graphics Programming
OpenGL Programming
Anton's OpenGL 4 Tutorials
一个开发者的博客:One-minute Dungeon: Behind the scenes
游戏中法线贴图的技巧:A game of Tricks-Normal mapped Scripts
- 【OpenGL】使用Unity来学习OpenGL
- 【OpenGL】使用Unity来学习OpenGL
- 【OpenGL】使用Unity来学习OpenGL
- 【OpenGL】使用Unity来学习OpenGL
- 【OpenGL】使用Unity来学习OpenGL
- 使用Unity来学习OpenGL
- OpenGL SuperBible --- 第三节:使用辅助库来学习OpenGL
- Unity中简单使用Opengl
- 用OpenGL来学习计算机图形学
- 使用DevIL来加载OpenGL纹理
- 使用DevIL来加载OpenGL纹理
- OpenGL 使用混合来实现半透明效果
- OpenGL 使用光照来表现立体感
- OpenGL使用混合来实现半透明效果
- OpenGL使用混合来实现半透明效果 .
- 学习OPENGL
- OpenGL学习
- opengl 学习
- dspace5.3中文化方法
- Caffe学习笔记二 Extracting Features
- ServletContextListener 使用。web启动监听启动和结束时的调用
- Android&Java经典面试题
- CoordinatorLayout AppBarLayout 结合下拉刷新 上拉加载更多 的滑动冲突解决
- 【OpenGL】使用Unity来学习OpenGL
- Retrofit使用教程(一)
- ipython notebook报错
- myeclipse打开时出现"Workspace in use or cannot be created, choose a different one."怎么解决
- [leetcode] 329. Longest Increasing Path in a Matrix
- dspace构建管理员
- AP聚类算法(1)
- 判断一个对象是否存在一些属性
- dns劫持与http劫持