简体   繁体   English

使用OpenGL Shader Language编写简单的着色器

[英]Using OpenGL Shader Language to write a simple shader

I'm going to start this off by saying that I am new to GLSL but have a decent amount of experience with OpenGL. 首先,我要说我是GLSL的新手,但对OpenGL有相当的经验。

I currently have a project that I want to practice shaders with. 我目前有一个要与之练习着色器的项目。 I am using gluTeapot and having it rotate around the xyz axis and I want to practice writing a basic shader with it. 我正在使用gluTeapot并使其绕xyz轴旋转,我想练习用它编写基本的着色器。

I currently have a sample shader and it works so I know that the OpenGL side of things is working well. 我目前有一个示例着色器,它可以正常工作,因此我知道OpenGL方面的工作很好。 All I need to do at this point is work with my vertex shader and fragment shader. 此时,我要做的就是使用我的顶点着色器和片段着色器。

I want to start out with something simple. 我想从简单的事情开始。 I want to write a shader that makes alternating stripes of red green and blue. 我想编写一个着色器,使红色,绿色和蓝色交替出现。

Here's what I know I need to do so far, but I'm not exactly sure how to actually implement it: 1) I know that I need to make constants for red, green, and blue that are of the type vec4 2) I know that I should probably just use mod(ycoord, 3.0) to determine which color belongs at a certain location 3) I know that I am going to have to figure out some way to get this pattern to rotate along with the teapot or else it will just look stupid. 这是到目前为止我需要做的事情,但是我不确定如何实现它:1)我知道我需要为vec4类型的红色,绿色和蓝色设置常量2)我知道我可能应该只使用mod(ycoord,3.0)来确定哪种颜色属于某个位置3)我知道我将必须找出某种方法来使该图案与茶壶一起旋转,否则只会显得愚蠢。

I have tried looking around the internet for some good tutorials for the basics of GLSL but I haven't understood any of the ones that I have read well enough to put them to use. 我曾尝试在互联网上浏览一些有关GLSL基础知识的好教程,但我还不了解我所读的内容,足以使用它们。 I also haven't been able to find any questions here that I have been able to put to use. 我也无法在这里找到任何我可以使用的问题。

Any help that you can give to a newbie at writing shaders would be appreciated. 您在编写着色器时可以给新手提供的任何帮助将不胜感激。

Thanks. 谢谢。

Try the Learning WebGL series. 尝试学习WebGL系列。 It'll give you examples of simple shaders and work you up to advanced topics. 它将为您提供简单着色器的示例,并为您介绍高级主题。 Everything uses standard GLSL and you can play with it in your web browser. 一切都使用标准GLSL,您可以在网络浏览器中使用它。

http://learningwebgl.com/ http://learningwebgl.com/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM