Introduced scalable obstacles, even though the texture could be polished a bit more
This commit is contained in:
@@ -177,7 +177,7 @@
|
||||
<obstacleData floating="false" moving="false" deadly="false" leftEdge="6.166328" rightEdge="7.1603284" height="0.293" y="-0.45350003">
|
||||
<moveComponent width="0.0" height="0.0" x="0.0" y="0.0" speed="0.0"/>
|
||||
</obstacleData>
|
||||
<obstacleData floating="true" moving="false" deadly="false" leftEdge="16.936665" rightEdge="19.076664" height="0.217" y="0.30666652">
|
||||
<obstacleData floating="true" moving="false" deadly="false" leftEdge="16.929998" rightEdge="19.069998" height="0.217" y="0.28666654">
|
||||
<moveComponent width="0.0" height="0.0" x="0.0" y="0.0" speed="0.0"/>
|
||||
</obstacleData>
|
||||
<obstacleData floating="true" moving="false" deadly="false" leftEdge="7.203003" rightEdge="8.6170025" height="0.127" y="-0.41333312">
|
||||
|
97
app/src/main/assets/shader/obstacleFragmentShader.glsl
Normal file
97
app/src/main/assets/shader/obstacleFragmentShader.glsl
Normal file
@@ -0,0 +1,97 @@
|
||||
precision mediump float;
|
||||
|
||||
uniform sampler2D texture;
|
||||
uniform float alpha;
|
||||
uniform vec2 texAtlasSize;
|
||||
uniform vec2 gridSize;
|
||||
uniform float deadly;
|
||||
uniform float floating;
|
||||
|
||||
varying vec2 pass_TexCoords;
|
||||
|
||||
const float clampBorder = 0.05;
|
||||
|
||||
float itermod(in float x, in float y);
|
||||
vec2 getInGridPos();
|
||||
vec2 getTexCoordsInGridSquare();
|
||||
vec2 getTexCoordsInAtlas(in vec2 texCoords, in float atlasIndex);
|
||||
|
||||
void main() {
|
||||
|
||||
vec2 gridPos = getInGridPos();
|
||||
float index = 0.0;
|
||||
|
||||
bool top = gridPos.y == 0.0;
|
||||
bool bottom = gridPos.y == gridSize.y - 1.0;
|
||||
bool left = gridPos.x == 0.0;
|
||||
bool right = gridPos.x == gridSize.x - 1.0;
|
||||
|
||||
if(top){
|
||||
if(left)
|
||||
index = 5.0 + itermod(gridSize.x, 2.0) + itermod(gridSize.y, 2.0);
|
||||
else if(right)
|
||||
index = 21.0 + itermod(gridSize.x, 2.0) + itermod(gridSize.y, 2.0);
|
||||
else
|
||||
index = itermod(gridPos.x, 3.0);
|
||||
if(deadly == 1.0)
|
||||
index += 8.0;
|
||||
} else if(bottom){
|
||||
if(left)
|
||||
index = 37.0 + itermod(gridSize.x, 2.0) + itermod(gridSize.y, 2.0);
|
||||
else if(right)
|
||||
index = 53.0 + itermod(gridSize.x, 2.0) + itermod(gridSize.y, 2.0);
|
||||
else
|
||||
index = 16.0 + itermod(gridPos.x, 3.0);
|
||||
if(floating == 1.0)
|
||||
index += 8.0;
|
||||
} else if(left){
|
||||
index = 32.0 + itermod(gridPos.y, 3.0);
|
||||
} else if(gridPos.x == gridSize.x - 1.0){
|
||||
index = 40.0 + itermod(gridPos.y, 3.0);
|
||||
} else{
|
||||
index = 48.0 + itermod(gridPos.x, 2.0) + itermod(gridPos.y, 2.0);
|
||||
}
|
||||
|
||||
vec2 texCoordsInGridSquare = getTexCoordsInGridSquare();
|
||||
texCoordsInGridSquare = clamp(texCoordsInGridSquare, clampBorder, 1.0 - clampBorder);
|
||||
vec2 texCoordsInAtlas = getTexCoordsInAtlas(texCoordsInGridSquare, index);
|
||||
gl_FragColor = texture2D(texture, texCoordsInAtlas);
|
||||
gl_FragColor.a = min(gl_FragColor.a, alpha);
|
||||
|
||||
}
|
||||
|
||||
float itermod(in float x, in float y){
|
||||
|
||||
while(x - y >= 0.0){
|
||||
x -= y;
|
||||
}
|
||||
return x;
|
||||
|
||||
}
|
||||
|
||||
vec2 getInGridPos(){
|
||||
|
||||
float gridX = floor(pass_TexCoords.x * gridSize.x);
|
||||
float gridY = floor(pass_TexCoords.y * gridSize.y);
|
||||
return vec2(gridX, gridY);
|
||||
|
||||
}
|
||||
|
||||
vec2 getTexCoordsInGridSquare(){
|
||||
|
||||
float x = mod(pass_TexCoords.x, 1.0 / gridSize.x) * gridSize.x;
|
||||
float y = mod(pass_TexCoords.y, 1.0 / gridSize.y) * gridSize.y;
|
||||
return vec2(x, y);
|
||||
|
||||
}
|
||||
|
||||
vec2 getTexCoordsInAtlas(in vec2 texCoords, in float atlasIndex){
|
||||
|
||||
vec2 texAtlasCoords = vec2(0.0, 0.0);
|
||||
texAtlasCoords.x = mod(texCoords.x, 1.0) / texAtlasSize.x;
|
||||
texAtlasCoords.x += mod(atlasIndex, texAtlasSize.x) / texAtlasSize.x;
|
||||
texAtlasCoords.y = mod(texCoords.y, 1.0) / texAtlasSize.y;
|
||||
texAtlasCoords.y += floor(atlasIndex / texAtlasSize.y) / texAtlasSize.y;
|
||||
return texAtlasCoords;
|
||||
|
||||
}
|
Reference in New Issue
Block a user