use of org.rajawali3d.lights.ALight in project Rajawali by Rajawali.
the class LightsFragmentShaderFragment method initialize.
@Override
public void initialize() {
super.initialize();
int lightCount = mLights.size();
@SuppressWarnings("unused") int dirLightCount = 0, spotLightCount = 0, pointLightCount = 0;
for (int i = 0; i < lightCount; i++) {
if (mLights.get(i).getLightType() == ALight.DIRECTIONAL_LIGHT)
dirLightCount++;
else if (mLights.get(i).getLightType() == ALight.SPOT_LIGHT)
spotLightCount++;
else if (mLights.get(i).getLightType() == ALight.POINT_LIGHT)
pointLightCount++;
}
muLightPosition = new RVec3[lightCount];
muLightColor = new RVec3[lightCount];
muLightPower = new RFloat[lightCount];
muLightDirection = new RVec3[dirLightCount + spotLightCount];
muSpotCutoffAngle = new RFloat[spotLightCount];
muSpotFalloff = new RFloat[spotLightCount];
mvAttenuation = new RFloat[lightCount];
//mgLightDirection = (RVec3) addGlobal(LightsShaderVar.G_LIGHT_DIRECTION, DataType.VEC3);
mvEye = (RVec4) addVarying(LightsShaderVar.V_EYE);
dirLightCount = 0;
spotLightCount = 0;
pointLightCount = 0;
for (int i = 0; i < mLights.size(); i++) {
ALight light = mLights.get(i);
int t = light.getLightType();
muLightPosition[i] = (RVec3) addUniform(LightsShaderVar.U_LIGHT_POSITION, i);
muLightPower[i] = (RFloat) addUniform(LightsShaderVar.U_LIGHT_POWER, i);
muLightColor[i] = (RVec3) addUniform(LightsShaderVar.U_LIGHT_COLOR, i);
if (t == ALight.DIRECTIONAL_LIGHT || t == ALight.SPOT_LIGHT) {
muLightDirection[dirLightCount] = (RVec3) addUniform(LightsShaderVar.U_LIGHT_DIRECTION, dirLightCount);
dirLightCount++;
}
if (t == ALight.SPOT_LIGHT) {
muSpotCutoffAngle[spotLightCount] = (RFloat) addUniform(LightsShaderVar.U_SPOT_CUTOFF_ANGLE, spotLightCount);
muSpotFalloff[spotLightCount] = (RFloat) addUniform(LightsShaderVar.U_SPOT_FALLOFF, spotLightCount);
spotLightCount++;
}
mvAttenuation[i] = (RFloat) addVarying(LightsShaderVar.V_LIGHT_ATTENUATION, i);
}
addVarying(LightsShaderVar.V_AMBIENT_COLOR);
}
use of org.rajawali3d.lights.ALight in project Rajawali by Rajawali.
the class LightsVertexShaderFragment method setLocations.
@Override
public void setLocations(int programHandle) {
int lightDirCount = 0, lightAttCount = 0;
int spotCount = 0;
for (int i = 0; i < mLights.size(); i++) {
ALight light = mLights.get(i);
int t = light.getLightType();
muLightColorHandles[i] = getUniformLocation(programHandle, LightsShaderVar.U_LIGHT_COLOR, i);
muLightPowerHandles[i] = getUniformLocation(programHandle, LightsShaderVar.U_LIGHT_POWER, i);
muLightPositionHandles[i] = getUniformLocation(programHandle, LightsShaderVar.U_LIGHT_POSITION, i);
if (t == ALight.DIRECTIONAL_LIGHT || t == ALight.SPOT_LIGHT) {
muLightDirectionHandles[lightDirCount] = getUniformLocation(programHandle, LightsShaderVar.U_LIGHT_DIRECTION, lightDirCount);
lightDirCount++;
}
if (t == ALight.SPOT_LIGHT || t == ALight.POINT_LIGHT) {
muLightAttenuationHandles[lightAttCount] = getUniformLocation(programHandle, LightsShaderVar.U_LIGHT_ATTENUATION, lightAttCount);
lightAttCount++;
}
if (t == ALight.SPOT_LIGHT) {
muSpotExponentHandles[spotCount] = getUniformLocation(programHandle, LightsShaderVar.U_SPOT_EXPONENT, spotCount);
muSpotCutoffAngleHandles[spotCount] = getUniformLocation(programHandle, LightsShaderVar.U_SPOT_CUTOFF_ANGLE, spotCount);
muSpotFalloffHandles[spotCount] = getUniformLocation(programHandle, LightsShaderVar.U_SPOT_FALLOFF, spotCount);
spotCount++;
}
muAmbientColorHandle = getUniformLocation(programHandle, LightsShaderVar.U_AMBIENT_COLOR);
muAmbientIntensityHandle = getUniformLocation(programHandle, LightsShaderVar.U_AMBIENT_INTENSITY);
}
}
use of org.rajawali3d.lights.ALight in project Rajawali by Rajawali.
the class LightsVertexShaderFragment method initialize.
@Override
public void initialize() {
super.initialize();
int lightCount = mLights.size();
for (int i = 0; i < lightCount; i++) {
if (mLights.get(i).getLightType() == ALight.DIRECTIONAL_LIGHT)
mDirLightCount++;
else if (mLights.get(i).getLightType() == ALight.SPOT_LIGHT)
mSpotLightCount++;
else if (mLights.get(i).getLightType() == ALight.POINT_LIGHT)
mPointLightCount++;
}
muLightColor = new RVec3[lightCount];
muLightColorHandles = new int[muLightColor.length];
muLightPower = new RFloat[lightCount];
muLightPowerHandles = new int[muLightPower.length];
muLightPosition = new RVec3[lightCount];
muLightPositionHandles = new int[muLightPosition.length];
muLightDirection = new RVec3[mDirLightCount + mSpotLightCount];
muLightDirectionHandles = new int[muLightDirection.length];
muLightAttenuation = new RVec4[mSpotLightCount + mPointLightCount];
muLightAttenuationHandles = new int[muLightAttenuation.length];
mvAttenuation = new RFloat[lightCount];
muSpotExponent = new RFloat[mSpotLightCount];
muSpotExponentHandles = new int[muSpotExponent.length];
muSpotCutoffAngle = new RFloat[mSpotLightCount];
muSpotCutoffAngleHandles = new int[muSpotCutoffAngle.length];
muSpotFalloff = new RFloat[mSpotLightCount];
muSpotFalloffHandles = new int[muSpotFalloff.length];
mgLightDistance = (RFloat) addGlobal(LightsShaderVar.G_LIGHT_DISTANCE);
mvEye = (RVec4) addVarying(LightsShaderVar.V_EYE);
int lightDirCount = 0, lightAttCount = 0;
int spotCount = 0;
for (int i = 0; i < mLights.size(); i++) {
ALight light = mLights.get(i);
int t = light.getLightType();
muLightColor[i] = (RVec3) addUniform(LightsShaderVar.U_LIGHT_COLOR, i);
muLightPower[i] = (RFloat) addUniform(LightsShaderVar.U_LIGHT_POWER, i);
muLightPosition[i] = (RVec3) addUniform(LightsShaderVar.U_LIGHT_POSITION, i);
mvAttenuation[i] = (RFloat) addVarying(LightsShaderVar.V_LIGHT_ATTENUATION, i);
if (t == ALight.DIRECTIONAL_LIGHT || t == ALight.SPOT_LIGHT) {
muLightDirection[lightDirCount] = (RVec3) addUniform(LightsShaderVar.U_LIGHT_DIRECTION, lightDirCount);
lightDirCount++;
}
if (t == ALight.SPOT_LIGHT || t == ALight.POINT_LIGHT) {
muLightAttenuation[lightAttCount] = (RVec4) addUniform(LightsShaderVar.U_LIGHT_ATTENUATION, lightAttCount);
lightAttCount++;
}
if (t == ALight.SPOT_LIGHT) {
muSpotExponent[spotCount] = (RFloat) addUniform(LightsShaderVar.U_SPOT_EXPONENT, spotCount);
muSpotCutoffAngle[spotCount] = (RFloat) addUniform(LightsShaderVar.U_SPOT_CUTOFF_ANGLE, spotCount);
muSpotFalloff[spotCount] = (RFloat) addUniform(LightsShaderVar.U_SPOT_FALLOFF, spotCount);
spotCount++;
//TODO: Perhaps a problem will arrise if directional and spot lights are used together due to counting each separately?
}
}
muAmbientColor = (RVec3) addUniform(LightsShaderVar.U_AMBIENT_COLOR);
muAmbientIntensity = (RVec3) addUniform(LightsShaderVar.U_AMBIENT_INTENSITY);
mvAmbientColor = (RVec3) addVarying(LightsShaderVar.V_AMBIENT_COLOR);
}
use of org.rajawali3d.lights.ALight in project Rajawali by Rajawali.
the class LightsVertexShaderFragment method main.
@Override
public void main() {
int lightAttCount = 0;
RMat4 modelMatrix = (RMat4) getGlobal(DefaultShaderVar.U_MODEL_MATRIX);
RVec4 position = (RVec4) getGlobal(DefaultShaderVar.G_POSITION);
mvEye.assign(enclose(modelMatrix.multiply(position)));
mvAmbientColor.rgb().assign(muAmbientColor.rgb().multiply(muAmbientIntensity.rgb()));
for (int i = 0; i < mLights.size(); i++) {
ALight light = mLights.get(i);
int t = light.getLightType();
if (t == ALight.SPOT_LIGHT || t == ALight.POINT_LIGHT) {
//
// -- gLightDistance = distance(vEye.xyz, uLightPosition);
//
mgLightDistance.assign(distance(mvEye.xyz(), muLightPosition[i]));
//
// -- vAttenuation = 1.0 / (uLightAttenuation[1] + uLightAttenuation[2] * gLightDistance + uLightAttenuation[3] * gLightDistance * gLightDistance)
//
mvAttenuation[i].assign(new RFloat(1.0).divide(enclose(muLightAttenuation[lightAttCount].index(1).add(muLightAttenuation[lightAttCount].index(2)).multiply(mgLightDistance).add(muLightAttenuation[lightAttCount].index(3)).multiply(mgLightDistance).multiply(mgLightDistance))));
lightAttCount++;
} else if (t == ALight.DIRECTIONAL_LIGHT) {
//
// -- vAttenuation = 1.0
//
mvAttenuation[i].assign(1.0f);
}
}
}
use of org.rajawali3d.lights.ALight in project Rajawali by Rajawali.
the class WallpaperRenderer method initScene.
@Override
protected void initScene() {
ALight light = new DirectionalLight(-1, 0, -1);
light.setPower(2);
getCurrentScene().addLight(light);
getCurrentCamera().setPosition(0, 0, 7);
getCurrentCamera().setLookAt(0, 0, 0);
try {
Cube cube = new Cube(1);
Material material = new Material();
material.enableLighting(true);
material.setDiffuseMethod(new DiffuseMethod.Lambert());
material.addTexture(new Texture("rajawaliTex", R.drawable.rajawali_tex));
material.setColorInfluence(0);
cube.setMaterial(material);
getCurrentScene().addChild(cube);
Vector3 axis = new Vector3(3, 1, 6);
axis.normalize();
Animation3D anim = new RotateOnAxisAnimation(axis, 0, 360);
anim.setDurationMilliseconds(8000);
anim.setRepeatMode(Animation.RepeatMode.INFINITE);
anim.setInterpolator(new AccelerateDecelerateInterpolator());
anim.setTransformable3D(cube);
getCurrentScene().registerAnimation(anim);
anim.play();
} catch (ATexture.TextureException e) {
e.printStackTrace();
}
}
Aggregations