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.
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.