use of org.rajawali3d.materials.textures.CubeMapTexture in project Rajawali by Rajawali.
the class Scene method updateSkybox.
/**
* Updates the sky box textures with a bitmap array of length 6.
* @param bitmaps {@link Bitmap} array containing the cube map textures.
* The sequence of the bitmaps in array should be
* front, right, back, left, up, down, the same as in setSkybox(Bitmap[] bitmaps)
* @throws Exception
*/
public void updateSkybox(Bitmap[] bitmaps) throws Exception {
if (mSkyboxTexture.getClass() != CubeMapTexture.class)
throw new Exception("The skybox texture cannot be updated. It is not a cube map texture.");
CubeMapTexture cubemap = (CubeMapTexture) mSkyboxTexture;
cubemap.setBitmaps(bitmaps);
mRenderer.getTextureManager().replaceTexture(cubemap);
}
use of org.rajawali3d.materials.textures.CubeMapTexture in project Rajawali by Rajawali.
the class Scene method setSkybox.
/**
* Creates a skybox with the specified 6 textures.
*
* @param posx int Resource id for the front face.
* @param negx int Resource id for the right face.
* @param posy int Resource id for the back face.
* @param negy int Resource id for the left face.
* @param posz int Resource id for the up face.
* @param negz int Resource id for the down face.
* @throws TextureException
*/
public boolean setSkybox(int posx, int negx, int posy, int negy, int posz, int negz) throws TextureException {
final AFrameTask task = new AFrameTask() {
@Override
protected void doTask() {
for (int i = 0, j = mCameras.size(); i < j; ++i) mCameras.get(i).setFarPlane(1000);
}
};
synchronized (mNextSkyboxLock) {
mNextSkybox = new Cube(700, true);
int[] resourceIds = new int[] { posx, negx, posy, negy, posz, negz };
mSkyboxTexture = new CubeMapTexture("skybox", resourceIds);
((CubeMapTexture) mSkyboxTexture).isSkyTexture(true);
Material mat = new Material();
mat.setColorInfluence(0);
mat.addTexture(mSkyboxTexture);
mNextSkybox.setMaterial(mat);
}
return internalOfferTask(task);
}
use of org.rajawali3d.materials.textures.CubeMapTexture in project Rajawali by Rajawali.
the class Scene method updateSkybox.
/**
* Updates the sky box textures with 6 new resource ids.
*
* @param front int Resource id for the front face.
* @param right int Resource id for the right face.
* @param back int Resource id for the back face.
* @param left int Resource id for the left face.
* @param up int Resource id for the up face.
* @param down int Resource id for the down face.
* @throws Exception
*/
public void updateSkybox(int front, int right, int back, int left, int up, int down) throws Exception {
if (mSkyboxTexture.getClass() != CubeMapTexture.class)
throw new Exception("The skybox texture cannot be updated. It is not a cube map texture.");
int[] resourceIds = new int[] { front, right, back, left, up, down };
CubeMapTexture cubemap = (CubeMapTexture) mSkyboxTexture;
cubemap.setResourceIds(resourceIds);
mRenderer.getTextureManager().replaceTexture(cubemap);
}
use of org.rajawali3d.materials.textures.CubeMapTexture in project Rajawali by Rajawali.
the class Material method createShaders.
/**
* Takes all material parameters and creates the vertex shader and fragment shader and then compiles the program.
* This method should only be called on initialization or when parameters have changed.
*/
protected void createShaders() {
if (!mIsDirty)
return;
if (mCustomVertexShader == null && mCustomFragmentShader == null) {
//
// -- Check textures
//
List<ATexture> diffuseTextures = null;
List<ATexture> normalMapTextures = null;
List<ATexture> envMapTextures = null;
List<ATexture> skyTextures = null;
List<ATexture> specMapTextures = null;
List<ATexture> alphaMapTextures = null;
boolean hasCubeMaps = false;
boolean hasVideoTexture = false;
for (int i = 0; i < mTextureList.size(); i++) {
ATexture texture = mTextureList.get(i);
switch(texture.getTextureType()) {
case VIDEO_TEXTURE:
hasVideoTexture = true;
// no break statement, add the video texture to the diffuse textures
case DIFFUSE:
case RENDER_TARGET:
if (diffuseTextures == null)
diffuseTextures = new ArrayList<>();
diffuseTextures.add(texture);
break;
case NORMAL:
if (normalMapTextures == null)
normalMapTextures = new ArrayList<>();
normalMapTextures.add(texture);
break;
case CUBE_MAP:
hasCubeMaps = true;
case SPHERE_MAP:
boolean isSkyTexture = false;
boolean isEnvironmentTexture = false;
if (texture.getClass() == SphereMapTexture.class) {
isSkyTexture = ((SphereMapTexture) texture).isSkyTexture();
isEnvironmentTexture = ((SphereMapTexture) texture).isEnvironmentTexture();
} else if (texture.getClass() == CubeMapTexture.class) {
isSkyTexture = ((CubeMapTexture) texture).isSkyTexture();
isEnvironmentTexture = ((CubeMapTexture) texture).isEnvironmentTexture();
}
if (isSkyTexture) {
if (skyTextures == null)
skyTextures = new ArrayList<>();
skyTextures.add(texture);
} else if (isEnvironmentTexture) {
if (envMapTextures == null)
envMapTextures = new ArrayList<>();
envMapTextures.add(texture);
}
break;
case SPECULAR:
if (specMapTextures == null)
specMapTextures = new ArrayList<>();
specMapTextures.add(texture);
break;
case ALPHA:
if (alphaMapTextures == null)
alphaMapTextures = new ArrayList<>();
alphaMapTextures.add(texture);
break;
default:
break;
}
}
mVertexShader = new VertexShader();
mVertexShader.enableTime(mTimeEnabled);
mVertexShader.hasCubeMaps(hasCubeMaps);
mVertexShader.hasSkyTexture(skyTextures != null && skyTextures.size() > 0);
mVertexShader.useVertexColors(mUseVertexColors);
onPreVertexShaderInitialize(mVertexShader);
mVertexShader.initialize();
mFragmentShader = new FragmentShader();
mFragmentShader.enableTime(mTimeEnabled);
mFragmentShader.hasCubeMaps(hasCubeMaps);
onPreFragmentShaderInitialize(mFragmentShader);
mFragmentShader.initialize();
if (diffuseTextures != null && diffuseTextures.size() > 0) {
DiffuseTextureFragmentShaderFragment fragment = new DiffuseTextureFragmentShaderFragment(diffuseTextures);
mFragmentShader.addShaderFragment(fragment);
}
if (normalMapTextures != null && normalMapTextures.size() > 0) {
NormalMapFragmentShaderFragment fragment = new NormalMapFragmentShaderFragment(normalMapTextures);
mFragmentShader.addShaderFragment(fragment);
}
if (envMapTextures != null && envMapTextures.size() > 0) {
EnvironmentMapFragmentShaderFragment fragment = new EnvironmentMapFragmentShaderFragment(envMapTextures);
mFragmentShader.addShaderFragment(fragment);
}
if (skyTextures != null && skyTextures.size() > 0) {
SkyTextureFragmentShaderFragment fragment = new SkyTextureFragmentShaderFragment(skyTextures);
mFragmentShader.addShaderFragment(fragment);
}
if (hasVideoTexture)
mFragmentShader.addPreprocessorDirective("#extension GL_OES_EGL_image_external : require");
checkForPlugins(PluginInsertLocation.PRE_LIGHTING);
if (mLightingEnabled && mLights != null && mLights.size() > 0) {
mVertexShader.setLights(mLights);
mFragmentShader.setLights(mLights);
mLightsVertexShaderFragment = new LightsVertexShaderFragment(mLights);
mLightsVertexShaderFragment.setAmbientColor(mAmbientColor);
mLightsVertexShaderFragment.setAmbientIntensity(mAmbientIntensity);
mVertexShader.addShaderFragment(mLightsVertexShaderFragment);
mFragmentShader.addShaderFragment(new LightsFragmentShaderFragment(mLights));
checkForPlugins(PluginInsertLocation.PRE_DIFFUSE);
if (mDiffuseMethod != null) {
mDiffuseMethod.setLights(mLights);
IShaderFragment fragment = mDiffuseMethod.getVertexShaderFragment();
if (fragment != null)
mVertexShader.addShaderFragment(fragment);
fragment = mDiffuseMethod.getFragmentShaderFragment();
mFragmentShader.addShaderFragment(fragment);
}
checkForPlugins(PluginInsertLocation.PRE_SPECULAR);
if (mSpecularMethod != null) {
mSpecularMethod.setLights(mLights);
mSpecularMethod.setTextures(specMapTextures);
IShaderFragment fragment = mSpecularMethod.getVertexShaderFragment();
if (fragment != null)
mVertexShader.addShaderFragment(fragment);
fragment = mSpecularMethod.getFragmentShaderFragment();
if (fragment != null)
mFragmentShader.addShaderFragment(fragment);
}
}
checkForPlugins(PluginInsertLocation.PRE_ALPHA);
if (alphaMapTextures != null && alphaMapTextures.size() > 0) {
AlphaMapFragmentShaderFragment fragment = new AlphaMapFragmentShaderFragment(alphaMapTextures);
mFragmentShader.addShaderFragment(fragment);
}
checkForPlugins(PluginInsertLocation.PRE_TRANSFORM);
checkForPlugins(PluginInsertLocation.POST_TRANSFORM);
mVertexShader.buildShader();
mFragmentShader.buildShader();
} else {
mVertexShader = mCustomVertexShader;
mFragmentShader = mCustomFragmentShader;
if (mVertexShader.needsBuild())
mVertexShader.initialize();
if (mFragmentShader.needsBuild())
mFragmentShader.initialize();
if (mVertexShader.needsBuild())
mVertexShader.buildShader();
if (mFragmentShader.needsBuild())
mFragmentShader.buildShader();
}
if (RajLog.isDebugEnabled()) {
RajLog.d("-=-=-=- VERTEX SHADER -=-=-=-");
RajLog.d(mVertexShader.getShaderString());
RajLog.d("-=-=-=- FRAGMENT SHADER -=-=-=-");
RajLog.d(mFragmentShader.getShaderString());
}
mProgramHandle = createProgram(mVertexShader.getShaderString(), mFragmentShader.getShaderString());
if (mProgramHandle == 0) {
mIsDirty = false;
return;
}
mVertexShader.setLocations(mProgramHandle);
mFragmentShader.setLocations(mProgramHandle);
for (String name : mTextureHandles.keySet()) {
setTextureHandleForName(name);
}
for (int i = 0; i < mTextureList.size(); i++) {
setTextureParameters(mTextureList.get(i));
}
mIsDirty = false;
}
use of org.rajawali3d.materials.textures.CubeMapTexture in project Rajawali by Rajawali.
the class Scene method setSkybox.
/**
* Creates a skybox with the specified 6 {@link Bitmap} textures.
*
* @param bitmaps {@link Bitmap} array containing the cube map textures.
*/
public boolean setSkybox(Bitmap[] bitmaps) {
final AFrameTask task = new AFrameTask() {
@Override
protected void doTask() {
for (int i = 0, j = mCameras.size(); i < j; ++i) mCameras.get(i).setFarPlane(1000);
}
};
final Cube skybox = new Cube(700, true);
final CubeMapTexture texture = new CubeMapTexture("bitmap_skybox", bitmaps);
texture.isSkyTexture(true);
final Material material = new Material();
material.setColorInfluence(0);
try {
material.addTexture(texture);
} catch (TextureException e) {
RajLog.e(e.getMessage());
}
skybox.setMaterial(material);
synchronized (mNextCameraLock) {
mNextSkybox = skybox;
}
return internalOfferTask(task);
}
Aggregations