shader does work at least...

This commit is contained in:
minjaesong
2017-07-04 22:04:07 +09:00
parent 2ac7efeaac
commit bba2f3ce20
3 changed files with 18 additions and 70 deletions

View File

@@ -1,73 +1,12 @@
#ifdef GL_ES
#define LOWP lowp
precision mediump float;
#else
#define LOWP
precision mediump float;
#endif
varying vec4 v_color;
varying vec2 v_texCoords;
uniform sampler2D u_texture;
varying vec4 vertexWorldPos;
uniform vec4 backColor;
uniform float width;
uniform float height;
void main() {
vec2 tex;
vec4 color2=vec4(0.0,0.0,0.0,0);
float stepx=(1.0/width)*4.0;
float stepy=(1.0/height)*4.0;
vec4 color;
tex.x=v_texCoords.x+stepx;
tex.y=v_texCoords.y+stepy;
color=v_color * texture2D(u_texture, tex);
color2.r+=color.r;
color2.g+=color.g;
color2.b+=color.b;
color2.a+=color.a;
tex.x=v_texCoords.x-stepx;
tex.y=v_texCoords.y+stepy;
color=v_color * texture2D(u_texture, tex);
color2.r+=color.r;
color2.g+=color.g;
color2.b+=color.b;
color2.a+=color.a;
tex.x=v_texCoords.x-stepx;
tex.y=v_texCoords.y-stepy;
color=v_color * texture2D(u_texture, tex);
color2.r+=color.r;
color2.g+=color.g;
color2.b+=color.b;
color2.a+=color.a;
tex.x=v_texCoords.x+stepx;
tex.y=v_texCoords.y-stepy;
color=v_color * texture2D(u_texture, tex);
color2.r+=color.r;
color2.g+=color.g;
color2.b+=color.b;
color2.a+=color.a;
tex.x=v_texCoords.x;
tex.y=v_texCoords.y;
color=v_color * texture2D(u_texture, tex);
color2.r+=color.r;
color2.g+=color.g;
color2.b+=color.b;
color2.a+=color.a;
color2.r/=5.0;
color2.g/=5.0;
color2.b/=5.0;
color2.a/=5.0;
gl_FragColor = color2;
//gl_FragColor = v_color * texture2D(u_texture, v_texCoords);
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}

View File

@@ -1,7 +1,14 @@
precision mediump float;
attribute vec4 a_position;
attribute vec4 a_color;
attribute vec2 a_texCoord0;
attribute vec2 position;
uniform mat4 u_projTrans;
varying vec4 v_color;
varying vec2 v_texCoords;
void main() {
gl_Position = vec4(position, 1, 1);
v_color = a_color;
v_texCoords = a_texCoord0;
gl_Position = u_projTrans * a_position;
}

View File

@@ -402,10 +402,12 @@ class StateInGameGDX(val batch: SpriteBatch) : Screen {
// now the actual drawing part //
lightmapFrameBuffer.inAction {
// TODO gaussian blur p=8
TerrarumGDX.shaderBlur.setUniformf("width", lightmapFrameBuffer.width.toFloat())
TerrarumGDX.shaderBlur.setUniformf("height", lightmapFrameBuffer.height.toFloat())
batch.shader = TerrarumGDX.shaderBlur
batch.inUse {
batch.shader = null//TerrarumGDX.shaderBlur
//batch.shader.setUniform3fv("iResolution", floatArrayOf(lightmapFrameBuffer.width.toFloat(), lightmapFrameBuffer.height.toFloat(), 0f), 0, 12)
//batch.shader.setUniformi("iChannel0", 0)
//batch.shader.setUniform2fv("direction", floatArrayOf(8f, 8f), 0, 8)
// using custom code for camera; this is obscure and tricky