默认GLSL着色器的外观如何?对于版本330 [英] How does the default GLSL shaders look like? for version 330

查看:123
本文介绍了默认GLSL着色器的外观如何?对于版本330的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#330版本的默认顶点,片段和几何图形GLSL着色器是什么样的?

What do the default vertex, fragment and geometry GLSL shaders look like for version #330?

我将通过Cg编译器使用#version 330 GLSL 3.30版NVIDIA,因为这是我的图形卡所支持的.

I'll be using #version 330 GLSL Version 3.30 NVIDIA via Cg compiler, because that is what my graphics card supports.

对于默认着色器,我的意思是与着色器在关闭着色器程序时所做的功能完全相同.

With default shaders, I mean shaders that do the same exact thing as the graphics card would do when the shader program is turned off.

我找不到#version 330的好例子.整天都在谷歌搜索.不知道术语默认着色器是否被称为琐​​碎的或基本的,这就是为什么我找不到它的原因.

I can't find a good example for #version 330. Been googling all day. Not sure if the term default shader is called something else like trivial or basic and if that is why I can't find it.

对于330版本的书的任何建议,或对330版本的入门教程的简单链接,也都很好.

Any recommendations for a book with version 330 or link to an easy beginner tutorial with version 330 would be great as well.

#version 110中琐碎的顶点着色器的示例,执行默认的顶点转换

example of a trivial vertex shader in #version 110, does the default vertex transformation

#version 110

void main()
{
    gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex;
}

#version 110中的琐碎片段着色器示例,将颜色变成红色

example of a trivial fragment shader in #version 110, turns color into red

#version 110

void main()
{
    gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}

推荐答案

OpenGL没有默认"着色器.看起来就像您想要的一个非常简单的着色器示例,该示例可将顶点转换为剪切空间并为它们提供颜色,所以您可以开始:

There are no "default" shaders with OpenGL. It looks like what you want a very simple example of a shader that transforms vertices to clip space and gives them a color, so here you go:

顶点着色器:

#version 330

layout(location = 0)in vec4 vert;

uniform mat4 projection;
uniform mat4 view;
uniform mat4 model;

void main()
{
    gl_Position = projection * view * model * vert;
}

片段着色器:

#version 330

out vec4 fragColor;

void main()
{
    fragColor = vec4(1.0, 0.0, 0.0, 1.0);
}

核心OpenGL 3.3配置文件放弃了对许多旧的固定功能事物(如矩阵堆栈)的支持.您应该处理自己的矩阵并将其发送到着色器.没有ftransform,并且gl_Position几乎是唯一有效的gl_ *变量.

The core OpenGL 3.3 profile drops support for a lot of old fixed-function things like the matrix stack. You are expected to handle your own matrices and send them to your shaders. There is no ftransform, and gl_Position is pretty much the only valid gl_* variable.

虽然不建议使用glBindAttribLocation,但定义顶点属性位置的首选方法是通过GLSL中的"layout(location = x)".

While glBindAttribLocation is not deprecated, the preferred method of defining the location of vertex attributes is through "layout(location = x)" in GLSL.

在顶点着色器中,属性"现在为输入",变化"现在为输出".在片段着色器中,"varying"现在为"in","gl_FragColor"由"out"变量定义.我相信gl_FragColor仍然有效,但是现在可以使用out变量定义颜色了.

In the vertex shader, "attribute" is now "in" and "varying" is now "out". In the fragment shader, "varying" is now "in" and "gl_FragColor" is defined by an "out" variable. I believe that gl_FragColor is still valid, but now it's possible to use an out variable to define the color.

本教程非常好并且讲授了OpenGL和GLSL 3.30的核心,我建议您使用它来帮助您学习有关GLSL的更多信息.还请记住, GLSL参考页是您的朋友.

This tutorial is very good and teaches core OpenGL and GLSL 3.30, I would recommend you use it to help you learn more about GLSL. Also remember that the GLSL Reference Pages is your friend.

这篇关于默认GLSL着色器的外观如何?对于版本330的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆