ps_3_0 does not allow textures or samplers to be members of compound types

在 Fragment Shader中下面代码编译出错

precision lowp float;

struct Material  //替换顶点色
{
		sampler2D diffusetexture; //引入纹理;
};
uniform Material m_material;

void main()
{
	sampler2D tex=texture2D(m_material.diffusetexture;
}

message = 0x0034f334 "(17,19): error X3090:

ps_3_0 does not allow textures or samplers to be members of compound types\n\n

Warning: D3D shader compilation failed with default flags. Retrying with avoid flow control.\n(17,19): error X3090: ps_3_0 does not allow texture...


在 StackOverFlow 中找到相关帖子

http://stackoverflow.com/questions/28756125/glsl-fragment-shader-wont-compile-with-a-texture2d-call-uncommented

里面提到

Instantiating a struct with opaque types (sampler2D) is invalid (for anything other than a uniform) in GLSL.
Rather than passing a MaterialParameters, your function might work better if you used the Material uniform directly
这个说的就是不能再struct中用 sampler2D

但是在 learnopengl 教程中
http://learnopengl-cn.readthedocs.org/zh/latest/02%20Lighting/04%20Lighting%20maps/

确实是在 Struct 中用到 Sampler2D

觉得是 GLSL 版本的问题, learnopengl 教程中是 GLSL 3.3
对比下面的版本
ps_3_0 does not allow textures or samplers to be members of compound types_第1张图片
ps_3_0 does not allow textures or samplers to be members of compound types_第2张图片

原来 GLES 2.0 还是 GLSL1 的版本。是比较老了。。

那在 GLES2.0 中, Sample2D 还是要单独拿出来作为 uniform ,不能放在 struct 中 。



你可能感兴趣的:(OpenGL)