我正试图在OpenGL中使用spirv。以前我用gl_VertexID
来计算矩形的紫外线,现在我用gl_VertexIndex
代替了它。
如果我使用gl_VertexID
,代码可以工作,如果我在spirv
中使用gl_VertexIndex
和vulkan
,那么代码可以工作,但是如果我在OpenGL中使用gl_VertexIndex
,那么gl_VertexIndex
总是0
。
下面是我使用的测试绘制命令:
glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, 6, 1, 2);
gl_VertexIndex
不应该从0
转到5
吗
发布于 2019-08-29 13:23:11
无论您使用的是什么阴影语言,在gl_VertexIndex
中都没有OpenGL。当为OpenGL将GLSL编译成SPIR-V时,您应该得到一个编译错误。
尽管如此,gl_VertexIndex
和gl_VertexID
的值并没有区别(与gl_InstanceIndex
和gl_InstanceID
不同)。
发布于 2021-11-27 23:14:29
如果使用vulkan 1.2:
命令行:
$ ./glslangValidator.exe my_input.vert.glsl -S vert --target-env vulkan1.2 -o my_output.vert.spv
my_input.vert.glsl
#version 450
//: -------------------------------------------------------- ://
//: How to compile: ://
//: $ ./glslangValidator.exe MCV.vert.glsl ://
//: -S vert ://
//: --target-env vulkan1.2 ://
//: -o mcv.vert.spv ://
//: ://
//: Formatted for readability. Command should all be on ://
//: one line when given to console. ://
//: -------------------------------------------------------- ://
//: ://
//: Got Help From Vulkan Discord: ://
//: ://
//: Rodrigo#1643 : ://
//: ://
//: gl_VertexIndex is gl_VertexID ://
//: gl_BaseVertex in other words,gl_VertexID ://
//: does not include the base vertex,which was ://
//: confusing for some people,specially because ://
//: D3D always included the base vertex ://
//: ://
//: ://
//: ://
//: Implodee#0345 : ://
//: ://
//: In Vulkan dialect glsl there's no gl_VertexID ://
//: and gl_InstanceID they are replaced by ://
//: gl_VertexIndex and gl_InstanceIndex as seen here ://
//: SC[ IMPLODE_GL_VERTEX_INDEX_SEEN_HERE_PDF ] ://
//: SC[ IMPLODE_GL_VERTEX_INDEX_SEEN_HERE_TXT ] ://
//: https://raw.githubusercontent.com/KhronosGroup/GLSL ://
//: /master/extensions/khr/GL_KHR_vulkan_glsl.txt ://
//: ://
//: ://
//: Me : ://
//: ://
//: $ ./glslangValidator MCV.vert.glsl -S vert ://
//: MCV.vert.glsl ://
//: ERROR: 0:45: 'gl_InstanceIndex' : undeclared identifier ://
//: ERROR: 0:45: '[]' : scalar integer expression required ://
//: ERROR: 0:45: '' : compilation terminated ://
//: ERROR: 3 compilation errors. No code generated. ://
//: ://
//: ://
//: Implodee#0345 : ://
//: ://
//: call it with --target-env vulkan1.2 ://
//: (or your used vulkan version rather) ://
//: see if that works ://
//: ://
//: ://
//: #define V_I ( gl_VertexID + gl_BaseVertex ) //:WRONG
//: #define V_I ( gl_VertexIndex + gl_InstanceIndex ) //:1.2
//: -------------------------------------------------------- ://
#define V_I gl_VertexIndex
layout( location = 0 ) out vec3 fragColor ;
vec2 positions[3] = vec2[](
vec2( 0.0 , -0.5 )
, vec2( 0.5 , 0.5 )
, vec2(-0.5 , 0.5 )
);
vec3 colors[3] = vec3[](
vec3( 1.0 , 0.0 , 0.0 )
, vec3( 0.0 , 1.0 , 0.0 )
, vec3( 0.0 , 0.0 , 1.0 )
);
void main(){
gl_Position = vec4(
positions[ V_I ] //: XY ://
, 0.0 //: Z ://
, 1.0 //: W ://
);;
fragColor = colors[ V_I ];
}
#undef V_I
原始源代码来自:模块
https://stackoverflow.com/questions/57704761
复制相似问题