GLSL 150转120:FFT纹理着色器改写后异常问题排查
Fixing GLSL 150 to 120 Porting Issues for FFT Textures
Hey there, the problem you're hitting comes down to key differences in how GLSL versions handle vertex shader inputs and outputs—let's fix this step by step!
Core Version Difference That's Breaking Your Code
GLSL 150 introduced the in/out keywords for attribute inputs and shader-to-shader variable passing, but GLSL 120 still uses the older attribute and varying keywords for these purposes. Your original 150 code uses in for vertex attributes and out for the texture coordinate passed to the fragment shader, which GLSL 120 doesn't recognize.
Updated GLSL 120 Vertex Shader Code
Here's the corrected version that should work as expected:
// glsl120.vert #version 120 uniform mat4 modelViewProjectionMatrix; attribute vec4 position; attribute vec2 texcoord; varying vec2 vTexCoord; void main(){ vTexCoord = texcoord; gl_Position = modelViewProjectionMatrix * position; }
Additional Checks to Avoid Further Issues
- Attribute Binding: GLSL 120 doesn't support explicit attribute location declarations like
layout(location = X)in 150. Make sure your application code usesglBindAttribLocationto link thepositionandtexcoordattributes to the correct vertex buffer indices before linking the shader program. - Fragment Shader Update: Don't forget to update your fragment shader too! If it was using
in vec2 vTexCoordto receive the texture coordinate, you'll need to change that tovarying vec2 vTexCoordto match the 120 standard. - Uniform Consistency: Double-check that any uniforms used in your fragment shader (like texture samplers for your FFT data) are also compatible with GLSL 120—sampler handling is mostly the same, but it's worth verifying.
内容的提问来源于stack exchange,提问作者Kakuya
相关产品推荐
相关产品推荐

