查看: 4429|回复: 1
打印 上一主题 下一主题

编写顶点和片段着色器:OpenGL着色语言

[复制链接]
.    

3797

主题

11

听众

5万

积分

首席设计师

Rank: 8Rank: 8

纳金币
32328
精华
41

活跃会员 优秀版主 荣誉管理 论坛元老

跳转到指定楼层
楼主
发表于 2013-2-24 09:55:48 |只看该作者 |倒序浏览
In addition to using Cg/HSL shader programs, OpenGL Shading Language (GLSL) shaders can be written directly.
除了使用Cg/HSL着色器程序,也可以直接编写OpenGL着色语言(GLSL)的着色器。
However, use of raw GLSL is only recommended for testing, or when you know you will only target Mac OS X or OpenGL ES 2.0 compatible mobile devices. In majority of normal cases, Unity will cross-compile Cg/HLSL into optimized GLSL (this is done by default for mobile platforms, and can be optionally turned on for desktop platforms via #pragma glsl).
然而使用原始的GLSL建议只在测试的时候用,或者你的着色器只以Mac OS X系统或者兼容OpenGL ES2.0的移动设备为使用目标。在大部分正常情况下,Unity将交叉编译Cg/HLSL成优化的GLSL(为了兼容移动平台而默认的。在桌面平台你可以通过 #pragma glsl命令随意的打开)。

GLSL snippets GLSL小片段
GLSL program snippets are written between GLSLPROGRAM and ENDGLSL keywords.
GLSL程序小片段是编写在GLSLPROGRAM和ENDGLSL关键字之间。
In GLSL, all shader function entry points have to be called main(). When Unity loads the GLSL shader, it loads the source once for the vertex program, with VERTEX preprocessor define, and once more for the fragment program, with FRAGMENT preprocessor define. So the way to separate vertex and fragment program parts in GLSL snippet is to surround them with #ifdef VERTEX .. #endif and #ifdef FRAGMENT .. #endif. Each GLSL snippet must contain both a vertex program and a fragment program.
在GLSL里,所有的着色器程序的入口点是一个叫做 main()的函数。当Unity加载GLSL着色器的时候,它加载一次资源(source),为顶点程序进行顶点预处理(VERTEX preprocessor)定义,然后为片段程序(fragment program)进行片段预处理( FRAGMENT preprocessor)定义。所以要对顶点和片段程序(vertex and fragment program)分开处理,在GLSL小片段里是通过 #ifdef VERTEX .. #endif 和 #ifdef FRAGMENT .. #endif命令包围住各部分。每个GLSL小片段必须包含一个顶点程序和一个片段程序。
Standard include files match those provided for Cg shaders; they just have .glslinc extension: UnityCG.glslinc.
标准的导入文件(include files)匹配提供的Cg着色器;它们只是有 .glslinc的扩展名,例如:UnityCG.glslinc.
Vertex shader inputs come from predefined GLSL variables (gl_Vertex, gl_MultiTexCoord0, ...) or are user defined attributes. Usually only the tangent vector needs a user defined attribute:
顶点着色器输入结构来自预先定义的GLSL变量(gl_Vertex, gl_MultiTexCoord0, ...)或者是用户自定义的属性。通常只有切线向量需要一个用户自定义属性:(attribute为限定符,使用在变量名前,表示该变量为用户自定义的。)
    attribute vec4 Tangent;
Data from vertex to fragment programs is passed through varying variables, for example:
数据从顶点程序到片段程序的传递是在变量类型前使用varying限定符,例如:
    varying vec3 lightDir; // vertex shader computes this, fragment shader uses this

【来源:互联网】

更多精彩教程,尽在web3D纳金网http://www.narkii.com/college/
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

wh    

0

主题

0

听众

20

积分

设计初学者

Rank: 1

纳金币
20
精华
0
沙发
发表于 2013-2-24 10:26:43 |只看该作者
你在说什么呢????????????????????????????????????????
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

手机版|纳金网 ( 闽ICP备2021016425号-2/3

GMT+8, 2024-9-20 12:30 , Processed in 0.088646 second(s), 38 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部