Ok, I'll do this tomorrow and see if the problem occurs again.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts Menu
Object3D towerTop = Primitives.getSphere(1);
//choosing the texture stuff here
//..
towerTop.setTexture(topTex); //texture chosen previously
towerTop.calcTextureWrapSpherical();
//towerTop.setSpecularLighting(true);
towerTop.build();
String uniformTime = mContext.getResources().getString(R.string.global_uniform_time);
ArrayList<ShaderUniform> uniformsTop = new ArrayList<ShaderUniform>();
uniformsTop.add(new ShaderUniform("colorMap", 1));
uniformsTop.add(new ShaderUniform("noiseMap", 1));
uniformsTop.add(new ShaderUniform(uniformTime, currentTime));
uniformsTop.add(new ShaderUniform("alpha", 1.0));
uniformsTop.add(new ShaderUniform("baseSpeed", 0.005));
uniformsTop.add(new ShaderUniform("noiseScale", 0.1337));
uniformsTop.add(new ShaderUniform("invRadius", 0.0005f));
ShaderUtils.setShader(mContext, towerTop, shadersDir+"towers/"+"vertexShader.glsl", shadersDir+"towers/"+"fragmentShader.glsl", uniformsTop);
//then I add the object to the world etc
public class ShaderUniform<T> {
private String name;
private T value;
public ShaderUniform(String name, T value) {
super();
this.name = name;
this.value = value;
}
//getters & setters...
ShaderUtils.setShader(mContext, towerTop, shadersDir+"towers/"+"vertexShader.glsl", shadersDir+"towers/"+"fragmentShader.glsl", uniformsTop);
private float currentTime, startTime;
currentTime = (float)( System.nanoTime() - startTime);
public static void setShader(Context mContext, Object3D obj, String vertPath, String fragPath, ArrayList<ShaderUniform> uniforms)
{
InputStream fragShader;
InputStream vertShader;
try
{
fragShader = mContext.getAssets().open(fragPath);
vertShader = mContext.getAssets().open(vertPath);
String fragmentShader = Loader.loadTextFile(fragShader);
String vertexShader = Loader.loadTextFile(vertShader);
GLSLShader shader = new GLSLShader(vertexShader, fragmentShader);
obj.setShader(shader);
for(ShaderUniform s : uniforms)
{
if (s.getValue() instanceof Integer)
{
Log.d("TAG", "UNIFORM INTEGER : "+s.getName());
shader.setStaticUniform(s.getName(), (Integer)s.getValue());
}
else if (s.getValue() instanceof Float)
{
Log.d("TAG", "UNIFORM FLOAT: "+s.getName());
shader.setStaticUniform(s.getName(), (Float)s.getValue());
}
else if (s.getValue() instanceof Float[])
{
shader.setStaticUniform(s.getName(), (float[])s.getValue());
}
...
...
if (System.currentTimeMillis() - time >= 1000) {
Logger.log(fps + "fps");
fps = 0;
time = System.currentTimeMillis();
currentTime = System.nanoTime() - startTime;//startTime is initialized in the class' constructor with : startTime = System.nanoTime();
animateTextures();
}
fps++;
...
...
String uniformTime = mContext.getResources().getString(R.string.global_uniform_time);
ArrayList<ShaderUniform> uniformsTop = new ArrayList<ShaderUniform>();
uniformsTop.add(new ShaderUniform("colorMap", 1));
uniformsTop.add(new ShaderUniform("noiseMap", 1));
uniformsTop.add(new ShaderUniform(uniformTime, currentTime));
uniformsTop.add(new ShaderUniform("alpha", 1.0));
uniformsTop.add(new ShaderUniform("baseSpeed", 0.005));
uniformsTop.add(new ShaderUniform("noiseScale", 0.1337));
uniformsTop.add(new ShaderUniform("invRadius", 0.0005f));
ShaderUtils.setShader(mContext, towerTop, shadersDir+"towers/"+"vertexShader.glsl", shadersDir+"towers/"+"fragmentShader.glsl", uniformsTop);
...
t.getTop().getShader().setUniform(uniformTime, currentTime); //uniformTime is the name of the variable
precision mediump float;
varying vec3 lightVec[2];
varying vec3 eyeVec;
varying vec2 texCoord;
uniform sampler2D colorMap;
uniform sampler2D noiseMap;
uniform float time;
uniform float baseSpeed;
uniform float noiseScale;
uniform float invRadius;
uniform float alpha;
uniform vec3 diffuseColors[8];
uniform vec3 specularColors[8];
uniform vec4 ambientColor;
float coef = 10.0;
void main ()
{
//Speed & direction of the texture
vec2 uvTimeShift = texCoord + vec2( -0.4, 0.5 ) * time * baseSpeed;
vec4 noise = texture2D( noiseMap, uvTimeShift );
vec2 uvNoisyTimeShift = texCoord + noiseScale * vec2( noise.r, noise.g ); //noise quantity
vec4 baseColor = texture2D( colorMap, uvNoisyTimeShift );
baseColor.a = alpha;
//...
gl_FragColor = baseColor;
}
deltaX = xEnd - xStart;
deltaY = yEnd - yStart;
cameraChanged = true;
@Override
public void onDrawFrame(GL10 gl) {
if(deltaX != 0)
{
SimpleVector xAxisVec = map.getCam().getXAxis();
map.getCam().moveCamera(xAxisVec, deltaX/50f);
deltaX = 0;
}
if(deltaY != 0)
{
SimpleVector yAxisVec = map.getCam().getYAxis();
map.getCam().moveCamera(yAxisVec, deltaY/50f);
deltaY = 0;
}
...
}
SimpleVector touchOrigin = Interact2D.reproject2D3DWS(map.getCam(), fb, (int)xStart, (int)yStart).normalize();
SimpleVector touchEnd = Interact2D.reproject2D3DWS(map.getCam(), fb, (int)xEnd, (int)yEnd).normalize();
SimpleVector moveDist = touchEnd.calcSub(touchOrigin);
cameraMovement = moveDist;
cameraChanged = true;
if(cameraChanged)
{
map.getCam().moveCamera(cameraMovement, 2);
cameraChanged = false;
}
Page created in 0.020 seconds with 11 queries.