Renderscript 固定功能着色器是什么样的?
我最近选择了 renderscript 并且非常喜欢它,但是缺乏文档和示例并没有帮助。我已经设法使用动态壁纸和示例来运行我自己的动态壁纸,但为了纹理化,我一直在使用固定功能着色器。
我看过 GLSL 教程,但似乎翻译得不太准确。我已经研究了 renderscript 源代码,但它仍然没有太多帮助。
以下是我从渲染脚本源中挖掘出来的一些代码,看起来像是固定函数正在执行的操作:
程序顶点
shaderString.append("varying vec4 varColor;\n");
shaderString.append("varying vec2 varTex0;\n");
shaderString.append("void main() {\n");
shaderString.append(" gl_Position = UNI_MVP * ATTRIB_position;\n");
shaderString.append(" gl_PointSize = 1.0;\n");
shaderString.append(" varColor = ATTRIB_color;\n");
shaderString.append(" varTex0 = ATTRIB_texture0;\n");
shaderString.append("}\n");
程序片段
shaderString.append("varying lowp vec4 varColor;\n");
shaderString.append("varying vec2 varTex0;\n");
shaderString.append("void main() {\n");
shaderString.append(" lowp vec4 col = UNI_Color;\n");
shaderString.append(" gl_FragColor = col;\n");
shaderString.append("}\n");
我认为这些不是最好的示例,因为该片段似乎没有触及 varTex0 变量。我尝试编写自己的程序片段并使用固定功能顶点着色器。
这是我的片段着色器:
ProgramFragment.Builder b = new ProgramFragment.Builder(mRS);
String s = "void main() {" +
" gl_FragColor = vec4(1.0,1.0,1.0,0.5);" +
"}";
b.setShader(s);
pf = b.create();
mScript.set_gPFLights(pf);
非常基本,但任何绑定纹理的尝试都失败了。我不知道纹理需要什么变量。
任何人都可以提供使用纹理的基本程序顶点和程序片段的示例吗?提前致谢。
I've recently picked up renderscript and really loving it but the lack of documentation and examples isn't helping. I've managed to use the live wallpapers and examples to get my own live wallpaper running but have been for texturing I have been using the fixed function shaders.
I've looked at GLSL tutorials but it doesn't seem to translate over exactly. I've looked into the renderscript source code but it still hasn't been of too much help either.
Here is some code that I dug up from the renderscript sources that seems like what the fixed function is doing:
Program vertex
shaderString.append("varying vec4 varColor;\n");
shaderString.append("varying vec2 varTex0;\n");
shaderString.append("void main() {\n");
shaderString.append(" gl_Position = UNI_MVP * ATTRIB_position;\n");
shaderString.append(" gl_PointSize = 1.0;\n");
shaderString.append(" varColor = ATTRIB_color;\n");
shaderString.append(" varTex0 = ATTRIB_texture0;\n");
shaderString.append("}\n");
Program fragment
shaderString.append("varying lowp vec4 varColor;\n");
shaderString.append("varying vec2 varTex0;\n");
shaderString.append("void main() {\n");
shaderString.append(" lowp vec4 col = UNI_Color;\n");
shaderString.append(" gl_FragColor = col;\n");
shaderString.append("}\n");
I don't think these are the best examples because the fragment doesn't seem to touch the varTex0 variable. I've tried to write my own program fragment and use the fixed function vertex shader.
Here's my fragment shader:
ProgramFragment.Builder b = new ProgramFragment.Builder(mRS);
String s = "void main() {" +
" gl_FragColor = vec4(1.0,1.0,1.0,0.5);" +
"}";
b.setShader(s);
pf = b.create();
mScript.set_gPFLights(pf);
Extremely basic but any attempt at binding a texture has failed. I don't know what variable is needed for the texture.
Could anyone provide an example of a basic program vertex and program fragment that uses textures? Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看 FountainFBO 示例。它使用带有纹理的程序片段作为帧缓冲区对象。
Check out the FountainFBO sample. It uses a program fragment with a texture that is used as a frame buffer object.
我终于找到了用于创建 GLSL 着色器的 FixFunction 类的源代码。位于“android_frameworks_base/graphics/java/android/renderscript”内。
以下是具有这些 FixFunction 设置的片段着色器:
该
片段着色器与 ProgramVertexFixedFunction 配合使用。
我还没有抽出时间看看固定函数顶点着色器是什么样子,但我会在看到时更新这个答案。
I finally managed to find the sources for the FixedFunction classes that are used to create GLSL shaders. There are located within "android_frameworks_base / graphics / java / android / renderscript".
Here is what the fragment shader with these FixedFunction settings :
would look like :
This fragment shader works with the ProgramVertexFixedFunction.
I haven't gotten around to seeing what the FixedFunction vertex shader looks like but I will update this answer when I do.