【OpenGL】使用Unity来学习OpenGL

Shader "GLSL basic shader" { // defines the name of the shaderSubShader { // Unity chooses the subshader that fits the GPU bestPass { // some shaders require multiple passesGLSLPROGRAM // here begins the part in Unity's GLSL#ifdef VERTEX // here begins the vertex shadervoid 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 shadervoid 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 shaderENDGLSL // here ends the part in GLSL} }}这样Shader就编辑好了。观察一下发现,这里一个文件中包含了Vertex Shader和Fragment Shader,这个有别于GLSL,不过其他就没有变化了(以后可能会有些优化,比如varying变量,在传统的GLSL中,需要在Vertex和Fragment中都定义一下,而且变量名称要一致,在Unity中可以把varying变量起到前面,,写一份就可以了,减少了代码编写和错误的发生)

然后继续努力,把让自己跌倒的石头搬掉或绕过去,不就解决问题了吗?

【OpenGL】使用Unity来学习OpenGL

相关文章:

你感兴趣的文章:

标签云: