You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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 uses glBindAttribLocation to link the position and texcoord attributes 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 vTexCoord to receive the texture coordinate, you'll need to change that to varying vec2 vTexCoord to 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 07:22:03