是否可以将着色器变量声明为输入和输出? [英] Is it possible to declare a shader variable as both input and output?

查看:38
本文介绍了是否可以将着色器变量声明为输入和输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我同时使用了顶点着色器和几何着色器.我的顶点着色器所做的只是将其输入转发到几何着色器.

I'm using both a vertex shader and a geometry shader. My vertex shader does nothing more than forward its input to the geometry shader.

#version 330 core
layout (location = 0) in uint xy;
layout (location = 1) in uint znt;

out uint out_xy;
out uint out_znt;

void main()
{
    out_xy = xy;
    out_znt = znt;
}

是否可以将 xy znt 声明为输入和输出,这样我就不必重命名它们了?

Is it possible to declare xy and znt as both an input and an output, so that I don't need to rename them?

推荐答案

您不能以这种方式声明"它们,但是可以使用接口块,它可以为您提供基本上相同的东西:

You cannot "declare" them that way, but you can use interface blocks, which can give you essentially the same thing:

//Vertex shader:

layout (location = 0) in uint xy;
layout (location = 1) in uint znt;

out VS
{
   uint xy;
   uint znt;
} to_gs;

void main()
{
    to_gs.xy = xy;
    to_gs.znt = znt;
}

//Geometry shader:

in VS
{
   uint xy;
   uint znt;
} from_vs[];

void main()
{
}

您必须在这些块上使用实例名称,以便GLSL知道您在说什么变量.但是否则,它们具有相同的名称.这还允许您使用 from_vs [X] 从几何体着色器中的图元选择第 X 个顶点,而不必将每个单独的输入变量声明为数组

You have to use instance names on these blocks so that GLSL knows what variables you're talking about. But otherwise, they have the same name. This also allows you to use from_vs[X] to select the Xth vertex from the primitive in the geometry shader, rather than having to declare each individual input variable as an array.

这篇关于是否可以将着色器变量声明为输入和输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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