public void updateMaterial() { float[] mat = this.getTransform().getModelMatrix(); float[] light = new float[4]; light[0] = 0; light[1] = 6; light[2] = 6; light[3] = 1.0f; float lX = mat[0] * light[0] + mat[1] * light[1] + mat[2] * light[2] + mat[3] * light[3]; float lY = mat[4] * light[0] + mat[5] * light[1] + mat[6] * light[2] + mat[7] * light[3]; float lZ = mat[8] * light[0] + mat[9] * light[1] + mat[10] * light[2] + mat[11] * light[3]; float x = 0; float y = 0; float z = 0; this.getRenderData().getMaterial().setVec3(SphereShader.LIGHT_KEY, lX - this.getTransform().getPositionX(), lY - this.getTransform().getPositionY(), lZ - this.getTransform().getPositionZ()); this.getRenderData().getMaterial().setVec3(SphereShader.EYE_KEY, x, y, z); }
private GVRMaterial getMaterial() { GVRMaterial material = new GVRMaterial(gvrContext, new GVRShaderId(SphereShader.class)); material.setTexture(SphereShader.TEXTURE_KEY, gvrContext.getAssetLoader().loadTexture(new GVRAndroidResource(gvrContext, mTexture))); material.setFloat("blur", 0); material.setFloat(SphereShader.ANIM_TEXTURE, 0.0f); material.setTexture(SphereShader.SECUNDARY_TEXTURE_KEY, gvrContext.getAssetLoader().loadTexture(new GVRAndroidResource(gvrContext, mResultTexture))); material.setVec3(SphereShader.TRANSITION_COLOR, 1, 1, 1); material.setVec3(SphereShader.EYE_KEY, 0, 0, 0); // Light config GVRTexture hdriTexture = gvrContext.getAssetLoader().loadTexture(new GVRAndroidResource(gvrContext, R.drawable.hdri_reflex)); material.setTexture(SphereShader.HDRI_TEXTURE_KEY, hdriTexture); return material; }
@Override public void run() { if (getAnswer().equalsIgnoreCase(answer)) { AudioClip.getInstance(getGVRContext().getContext()).playSound( AudioClip.getSucessSoundID(), 1.0f, 1.0f); getRenderData().getMaterial().setVec3(SphereShader.TRANSITION_COLOR, 0.2f, 0.675f, 0.443f); getRenderData().getMaterial().setTexture( SphereShader.SECUNDARY_TEXTURE_KEY, getGVRContext().getAssetLoader().loadTexture( new GVRAndroidResource(getGVRContext(), R.drawable.check))); } else { AudioClip.getInstance(getGVRContext().getContext()).playSound( AudioClip.getWrongSoundID(), 1.0f, 1.0f); getRenderData().getMaterial().setVec3(SphereShader.TRANSITION_COLOR, 1, 0, 0); getRenderData().getMaterial().setTexture( SphereShader.SECUNDARY_TEXTURE_KEY, getGVRContext().getAssetLoader().loadTexture( new GVRAndroidResource(getGVRContext(), R.drawable.error))); } } });
mWidgetMaterial.setVec4(PhongShader3.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]); mWidgetMaterial.setVec4(PhongShader3.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]); mWidgetMaterial.setVec3(PhongShader3.LIGHT_KEY, light[0], light[1], light[2]); mWidgetMaterial.setVec3(PhongShader3.EYE_KEY, eye[0], eye[1], eye[2]); mWidgetMaterial2.setVec4(PhongShader3.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]); mWidgetMaterial2.setVec4(PhongShader3.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]); mWidgetMaterial2.setVec3(PhongShader3.LIGHT_KEY, light[0], light[1], light[2]); mWidgetMaterial2.setVec3(PhongShader3.EYE_KEY, eye[0], eye[1], eye[2]);