use of org.rajawali3d.lights.ALight in project Rajawali by Rajawali.
the class LoaderFBX method parse.
@Override
public LoaderFBX parse() throws ParsingException {
super.parse();
BufferedReader buffer = null;
if (mFile == null) {
InputStream fileIn = mResources.openRawResource(mResourceId);
buffer = new BufferedReader(new InputStreamReader(fileIn));
} else {
try {
buffer = new BufferedReader(new FileReader(mFile));
} catch (FileNotFoundException e) {
RajLog.e("[" + getClass().getCanonicalName() + "] Could not find file.");
throw new ParsingException(e);
}
}
String line;
try {
while ((line = buffer.readLine()) != null) {
String repl = line.replaceAll(REGEX_CLEAN, REPLACE_EMPTY);
if (repl.length() == 0 || repl.charAt(0) == COMMENT)
continue;
readLine(buffer, line);
}
buffer.close();
} catch (Exception e) {
throw new ParsingException(e);
}
// -- get lights
Stack<Model> lights = mFbx.objects.getModelsByType(FBXValues.MODELTYPE_LIGHT);
int numLights = lights.size();
Renderer.setMaxLights(numLights == 0 ? 1 : numLights);
Stack<ALight> sceneLights = new Stack<ALight>();
for (int i = 0; i < numLights; ++i) {
Model l = lights.get(i);
// -- really need to add more light types
sceneLights.add(buildLight(l));
}
if (numLights == 0) {
ALight light = new DirectionalLight();
light.setPosition(2, 0, -5);
light.setPower(1);
sceneLights.add(light);
}
// -- check fog
//TODO: add fog support
/*if(mFbx.version5.fogOptions.fogEnable != null && mFbx.version5.fogOptions.fogEnable == 1) {
FogOptions fogOptions = mFbx.version5.fogOptions;
mRenderer.setFogEnabled(true);
Camera cam = mRenderer.getCamera();
cam.setFogEnabled(true);
cam.setFogNear(fogOptions.fogStart);
cam.setFogColor(fogOptions.fogColor.color);
mRenderer.setBackgroundColor(fogOptions.fogColor.color);
}*/
// -- get meshes
Stack<Model> models = mFbx.objects.getModelsByType(FBXValues.MODELTYPE_MESH);
try {
for (int i = 0; i < models.size(); ++i) {
buildMesh(models.get(i), sceneLights);
}
} catch (TextureException tme) {
throw new ParsingException(tme);
}
// -- get cameras
Stack<Model> cameras = mFbx.objects.getModelsByType(FBXValues.MODELTYPE_CAMERA);
Model camera = null;
for (int i = 0; i < cameras.size(); ++i) {
if (cameras.get(i).hidden == null || !cameras.get(i).hidden.equals("True")) {
camera = cameras.get(i);
break;
}
}
if (camera != null) {
//TODO: FIX
Camera cam = mRenderer.getCurrentCamera();
cam.setPosition(camera.position);
cam.setX(mRenderer.getCurrentCamera().getX() * -1);
cam.setRotation(camera.properties.lclRotation);
Vector3 lookAt = camera.lookAt;
// lookAt.x = -lookAt.x;
cam.setLookAt(lookAt);
cam.setNearPlane(camera.properties.nearPlane);
cam.setFarPlane(camera.properties.farPlane);
cam.setFieldOfView(camera.properties.fieldOfView);
}
return this;
}
use of org.rajawali3d.lights.ALight in project Rajawali by Rajawali.
the class Material method setLights.
/**
* The lights that affect the material. Lights shouldn't be managed by any other class
* than {@link Scene}. To add lights to a scene call {@link Scene#addLight(ALight).
*
* @param lights The lights collection
*/
public void setLights(List<ALight> lights) {
if (mLights != null) {
for (ALight light : lights) {
if (!mLights.contains(light)) {
break;
}
}
} else {
mIsDirty = true;
mLights = lights;
}
}
use of org.rajawali3d.lights.ALight in project Rajawali by Rajawali.
the class LightsFragmentShaderFragment method main.
@Override
public void main() {
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();
RVec3 lightDir = new RVec3("lightDir" + i);
if (t == ALight.SPOT_LIGHT || t == ALight.POINT_LIGHT) {
lightDir.assign(normalize(muLightPosition[i].subtract(mvEye.xyz())));
if (t == ALight.SPOT_LIGHT) {
//
// -- vec3 spotDir = normalize(-uLightDirection);
//
RVec3 spotDir = new RVec3("spotDir" + spotCount);
spotDir.assign(normalize(muLightDirection[lightDirCount].multiply(-1.0f)));
lightDirCount++;
//
// -- float spot_factor = dot(lightDir, spotDir);
//
RFloat spotFactor = new RFloat("spotFactor" + spotCount);
spotFactor.assign(dot(lightDir, spotDir));
//
// -- if(uSpotCutoffAngle < 180.0 ) {
//
startif(new Condition(muSpotCutoffAngle[spotCount], Operator.LESS_THAN, 180.0f));
{
//
// -- if(spotFactor >= cos(radians(uSpotCutoffAngle))) {
//
startif(new Condition(spotFactor, Operator.GREATER_THAN_EQUALS, cos(radians(muSpotCutoffAngle[spotCount]))));
{
//
// -- spotFactor = (1.0 - (1.0 - spotFactor * 1.0 / (1.0 - cos(radians(uSpotCutoffAngle))));
//
RFloat exponent = new RFloat("exponent");
exponent.assign(subtract(1.0f, cos(radians(muSpotCutoffAngle[spotCount]))));
exponent.assign(divide(1.0f, exponent));
RFloat facInv = new RFloat("facInv");
facInv.assign(subtract(1, spotFactor));
exponent.assign(facInv.multiply(exponent));
exponent.assign(subtract(1, exponent));
//
// -- spotFactor = pow(spotFactor, uSpotFalloff * 1.0 / spotFactor");
//
spotFactor.assign(pow(exponent, multiply(muSpotFalloff[spotCount], divide(1.0f, exponent))));
}
ifelse();
{
//
// -- spotFactor = 0.0;
//
spotFactor.assign(0);
}
endif();
//
// -- lightDir = vec3(L.x, L.y, L.z) * spotFactor;
//
lightDir.assign(multiply(castVec3(lightDir), spotFactor));
}
endif();
spotCount++;
}
} else if (t == ALight.DIRECTIONAL_LIGHT) {
//
// -- lightDir = normalize(-uLightDirection);
//
lightDir.assign(normalize(muLightDirection[lightDirCount].multiply(-1.0f)));
lightDirCount++;
}
}
}
use of org.rajawali3d.lights.ALight in project Rajawali by Rajawali.
the class LightsVertexShaderFragment method applyParams.
@Override
public void applyParams() {
super.applyParams();
int lightCount = mLights.size();
int dirCount = 0, spotCount = 0, attCount = 0;
for (int i = 0; i < lightCount; i++) {
ALight light = mLights.get(i);
int t = light.getLightType();
GLES20.glUniform3fv(muLightColorHandles[i], 1, light.getColor(), 0);
GLES20.glUniform1f(muLightPowerHandles[i], light.getPower());
GLES20.glUniform3fv(muLightPositionHandles[i], 1, ArrayUtils.convertDoublesToFloats(light.getPositionArray(), mTemp3Floats), 0);
if (t == ALight.SPOT_LIGHT) {
SpotLight l = (SpotLight) light;
GLES20.glUniform3fv(muLightDirectionHandles[spotCount], 1, ArrayUtils.convertDoublesToFloats(l.getDirection(), mTemp3Floats), 0);
GLES20.glUniform4fv(muLightAttenuationHandles[attCount], 1, l.getAttenuation(), 0);
//GLES20.glUniform1f(muSpotExponentHandles[spotCount], l.get)
GLES20.glUniform1f(muSpotCutoffAngleHandles[spotCount], l.getCutoffAngle());
GLES20.glUniform1f(muSpotFalloffHandles[spotCount], l.getFalloff());
spotCount++;
dirCount++;
attCount++;
} else if (t == ALight.POINT_LIGHT) {
PointLight l = (PointLight) light;
GLES20.glUniform4fv(muLightAttenuationHandles[attCount], 1, l.getAttenuation(), 0);
attCount++;
} else if (t == ALight.DIRECTIONAL_LIGHT) {
DirectionalLight l = (DirectionalLight) light;
GLES20.glUniform3fv(muLightDirectionHandles[dirCount], 1, ArrayUtils.convertDoublesToFloats(l.getDirection(), mTemp3Floats), 0);
dirCount++;
}
}
GLES20.glUniform3fv(muAmbientColorHandle, 1, mAmbientColor, 0);
GLES20.glUniform3fv(muAmbientIntensityHandle, 1, mAmbientIntensity, 0);
}
Aggregations