use of com.android.scenegraph.VertexShader in project android_frameworks_base by ParanoidAndroid.
the class SceneManager method getDefaultVS.
// Provides the folowing inputs to fragment shader
// Assigned by default if nothing is present
// vec3 varWorldPos;
// vec3 varWorldNormal;
// vec2 varTex0;
public static VertexShader getDefaultVS() {
if (sSceneManager == null) {
return null;
}
if (sSceneManager.mDefaultVertex == null) {
RenderScriptGL rs = getRS();
Element.Builder b = new Element.Builder(rs);
b.add(Element.MATRIX_4X4(rs), "model");
Type.Builder objConstBuilder = new Type.Builder(rs, b.create());
b = new Element.Builder(rs);
b.add(Element.MATRIX_4X4(rs), "viewProj");
Type.Builder shaderConstBuilder = new Type.Builder(rs, b.create());
b = new Element.Builder(rs);
b.add(Element.F32_4(rs), "position");
b.add(Element.F32_2(rs), "texture0");
b.add(Element.F32_3(rs), "normal");
Element defaultIn = b.create();
final String code = "\n" + "varying vec3 varWorldPos;\n" + "varying vec3 varWorldNormal;\n" + "varying vec2 varTex0;\n" + "void main() {" + " vec4 objPos = ATTRIB_position;\n" + " vec4 worldPos = UNI_model * objPos;\n" + " gl_Position = UNI_viewProj * worldPos;\n" + " mat3 model3 = mat3(UNI_model[0].xyz, UNI_model[1].xyz, UNI_model[2].xyz);\n" + " vec3 worldNorm = model3 * ATTRIB_normal;\n" + " varWorldPos = worldPos.xyz;\n" + " varWorldNormal = worldNorm;\n" + " varTex0 = ATTRIB_texture0;\n" + "}\n";
VertexShader.Builder sb = new VertexShader.Builder(rs);
sb.addInput(defaultIn);
sb.setObjectConst(objConstBuilder.setX(1).create());
sb.setShaderConst(shaderConstBuilder.setX(1).create());
sb.setShader(code);
sSceneManager.mDefaultVertex = sb.create();
}
return sSceneManager.mDefaultVertex;
}
Aggregations