Revision f2367b75
Added by Leszek Koltunski over 8 years ago
| src/main/java/org/distorted/library/Distorted.java | ||
|---|---|---|
| 21 | 21 |
|
| 22 | 22 |
import android.content.Context; |
| 23 | 23 |
import android.content.res.Resources; |
| 24 |
import android.opengl.GLES30; |
|
| 25 | 24 |
import org.distorted.library.program.*; |
| 26 | 25 |
|
| 27 | 26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 30 | 29 |
*/ |
| 31 | 30 |
public class Distorted |
| 32 | 31 |
{
|
| 32 |
static final String glslVersion="#version 300 es\n"; |
|
| 33 | 33 |
/** |
| 34 | 34 |
* When creating an instance of a DistortedTexture from another instance, clone the Bitmap that's |
| 35 | 35 |
* backing up our DistortedTexture. |
| src/main/java/org/distorted/library/DistortedEffects.java | ||
|---|---|---|
| 110 | 110 |
final InputStream mainVertStream = resources.openRawResource(R.raw.main_vertex_shader); |
| 111 | 111 |
final InputStream mainFragStream = resources.openRawResource(R.raw.main_fragment_shader); |
| 112 | 112 |
|
| 113 |
String mainVertHeader= ("#version 100\n");
|
|
| 114 |
String mainFragHeader= ("#version 100\n");
|
|
| 113 |
String mainVertHeader= Distorted.glslVersion;
|
|
| 114 |
String mainFragHeader= Distorted.glslVersion;
|
|
| 115 | 115 |
|
| 116 | 116 |
EffectNames name; |
| 117 | 117 |
EffectTypes type; |
| ... | ... | |
| 156 | 156 |
final InputStream blitVertStream = resources.openRawResource(R.raw.blit_vertex_shader); |
| 157 | 157 |
final InputStream blitFragStream = resources.openRawResource(R.raw.blit_fragment_shader); |
| 158 | 158 |
|
| 159 |
String blitVertHeader= ("#version 100\n#define NUM_VERTEX 0\n" );
|
|
| 160 |
String blitFragHeader= ("#version 100\n#define NUM_FRAGMENT 0\n");
|
|
| 159 |
String blitVertHeader= (Distorted.glslVersion + "#define NUM_VERTEX 0\n" );
|
|
| 160 |
String blitFragHeader= (Distorted.glslVersion + "#define NUM_FRAGMENT 0\n");
|
|
| 161 | 161 |
|
| 162 |
mBlitProgram = new DistortedProgram(blitVertStream,blitFragStream,blitVertHeader,blitFragHeader); |
|
| 162 |
try |
|
| 163 |
{
|
|
| 164 |
mBlitProgram = new DistortedProgram(blitVertStream,blitFragStream,blitVertHeader,blitFragHeader); |
|
| 165 |
} |
|
| 166 |
catch(Exception e) |
|
| 167 |
{
|
|
| 168 |
android.util.Log.e("EFFECTS", "exception trying to compile BLIT program: "+e.getMessage());
|
|
| 169 |
throw new RuntimeException(e.getMessage()); |
|
| 170 |
} |
|
| 163 | 171 |
|
| 164 | 172 |
int blitProgramH = mBlitProgram.getProgramHandle(); |
| 165 | 173 |
mBlitTextureH = GLES30.glGetUniformLocation( blitProgramH, "u_Texture"); |
| ... | ... | |
| 169 | 177 |
final InputStream debugVertexStream = resources.openRawResource(R.raw.test_vertex_shader); |
| 170 | 178 |
final InputStream debugFragmentStream = resources.openRawResource(R.raw.test_fragment_shader); |
| 171 | 179 |
|
| 172 |
mDebugProgram = new DistortedProgram(debugVertexStream,debugFragmentStream, "#version 100\n", "#version 100\n"); |
|
| 180 |
try |
|
| 181 |
{
|
|
| 182 |
mDebugProgram = new DistortedProgram(debugVertexStream,debugFragmentStream, Distorted.glslVersion, Distorted.glslVersion); |
|
| 183 |
} |
|
| 184 |
catch(Exception e) |
|
| 185 |
{
|
|
| 186 |
android.util.Log.e("EFFECTS", "exception trying to compile DEBUG program: "+e.getMessage());
|
|
| 187 |
throw new RuntimeException(e.getMessage()); |
|
| 188 |
} |
|
| 173 | 189 |
|
| 174 | 190 |
int debugProgramH = mDebugProgram.getProgramHandle(); |
| 175 | 191 |
mDebugObjDH = GLES30.glGetUniformLocation( debugProgramH, "u_objD"); |
| src/main/java/org/distorted/library/DistortedFramebuffer.java | ||
|---|---|---|
| 171 | 171 |
super(width,height,NOT_CREATED_YET, (depthEnabled ? NOT_CREATED_YET:DONT_CREATE),NOT_CREATED_YET, type); |
| 172 | 172 |
} |
| 173 | 173 |
|
| 174 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 175 |
// For setting the Depth texture as input to fragment shaders that merge many planes. (currently: blur2) |
|
| 176 |
|
|
| 177 |
boolean setAsDepth() |
|
| 178 |
{
|
|
| 179 |
if( mDepthH[0]>0 ) |
|
| 180 |
{
|
|
| 181 |
GLES30.glActiveTexture(GLES30.GL_TEXTURE1); |
|
| 182 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mDepthH[0]); |
|
| 183 |
return true; |
|
| 184 |
} |
|
| 185 |
|
|
| 186 |
return false; |
|
| 187 |
} |
|
| 188 |
|
|
| 174 | 189 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 175 | 190 |
// PUBLIC API |
| 176 | 191 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 211 | 226 |
{
|
| 212 | 227 |
if( mColorH[0]>0 ) |
| 213 | 228 |
{
|
| 229 |
GLES30.glActiveTexture(GLES30.GL_TEXTURE0); |
|
| 214 | 230 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mColorH[0]); |
| 215 | 231 |
return true; |
| 216 | 232 |
} |
| src/main/java/org/distorted/library/DistortedTexture.java | ||
|---|---|---|
| 133 | 133 |
{
|
| 134 | 134 |
if( mColorH[0]>0 ) |
| 135 | 135 |
{
|
| 136 |
GLES30.glActiveTexture(GLES30.GL_TEXTURE0); |
|
| 136 | 137 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, mColorH[0]); |
| 137 | 138 |
return true; |
| 138 | 139 |
} |
| src/main/java/org/distorted/library/EffectQueuePostprocess.java | ||
|---|---|---|
| 98 | 98 |
private static float[] weightsCache = new float[MAX_BLUR + MAX_BLUR*MAX_BLUR/4]; |
| 99 | 99 |
private static float[] offsetsCache = new float[MAX_BLUR + MAX_BLUR*MAX_BLUR/4]; |
| 100 | 100 |
|
| 101 |
private static DistortedProgram mBlurProgram; |
|
| 102 |
private static int mRadiusH,mOffsetsH,mWeightsH,mDepthH; |
|
| 101 |
private static DistortedProgram mBlur1Program, mBlur2Program; |
|
| 102 |
private static int mRadius1H,mOffsets1H,mWeights1H,mDepth1H, mColorTexture1H; |
|
| 103 |
private static int mRadius2H,mOffsets2H,mWeights2H,mDepth2H, mColorTexture2H, mDepthTexture2H; |
|
| 103 | 104 |
private static float[] mWeights = new float[MAX_BLUR]; |
| 104 | 105 |
private static float[] mOffsets = new float[MAX_BLUR]; |
| 105 | 106 |
// another effect .... |
| ... | ... | |
| 116 | 117 |
static void createProgram(Resources resources) |
| 117 | 118 |
throws FragmentCompilationException,VertexCompilationException,VertexUniformsException,FragmentUniformsException,LinkingException |
| 118 | 119 |
{
|
| 119 |
final InputStream postVertexStream = resources.openRawResource(R.raw.blur_vertex_shader); |
|
| 120 |
final InputStream postFragmentStream = resources.openRawResource(R.raw.blur_fragment_shader); |
|
| 121 |
|
|
| 122 |
mBlurProgram = new DistortedProgram(postVertexStream,postFragmentStream, |
|
| 123 |
"#version 100\n", |
|
| 124 |
"#version 100\n#define MAX_BLUR "+MAX_BLUR); |
|
| 125 |
|
|
| 126 |
int blurProgramH = mBlurProgram.getProgramHandle(); |
|
| 127 |
mRadiusH = GLES30.glGetUniformLocation( blurProgramH, "u_Radius"); |
|
| 128 |
mOffsetsH = GLES30.glGetUniformLocation( blurProgramH, "u_Offsets"); |
|
| 129 |
mWeightsH = GLES30.glGetUniformLocation( blurProgramH, "u_Weights"); |
|
| 130 |
mDepthH = GLES30.glGetUniformLocation( blurProgramH, "u_Depth"); |
|
| 120 |
final InputStream blur1VertexStream = resources.openRawResource(R.raw.blur_vertex_shader); |
|
| 121 |
final InputStream blur1FragmentStream = resources.openRawResource(R.raw.blur1_fragment_shader); |
|
| 122 |
|
|
| 123 |
try |
|
| 124 |
{
|
|
| 125 |
mBlur1Program = new DistortedProgram(blur1VertexStream,blur1FragmentStream, |
|
| 126 |
Distorted.glslVersion, |
|
| 127 |
Distorted.glslVersion+"#define MAX_BLUR "+MAX_BLUR); |
|
| 128 |
} |
|
| 129 |
catch(Exception e) |
|
| 130 |
{
|
|
| 131 |
android.util.Log.e("EFFECTS", "exception trying to compile BLUR1 program: "+e.getMessage());
|
|
| 132 |
throw new RuntimeException(e.getMessage()); |
|
| 133 |
} |
|
| 134 |
|
|
| 135 |
int blur1ProgramH = mBlur1Program.getProgramHandle(); |
|
| 136 |
mRadius1H = GLES30.glGetUniformLocation( blur1ProgramH, "u_Radius"); |
|
| 137 |
mOffsets1H = GLES30.glGetUniformLocation( blur1ProgramH, "u_Offsets"); |
|
| 138 |
mWeights1H = GLES30.glGetUniformLocation( blur1ProgramH, "u_Weights"); |
|
| 139 |
mDepth1H = GLES30.glGetUniformLocation( blur1ProgramH, "u_Depth"); |
|
| 140 |
mColorTexture1H = GLES30.glGetUniformLocation( blur1ProgramH, "u_ColorTexture"); |
|
| 141 |
|
|
| 142 |
final InputStream blur2VertexStream = resources.openRawResource(R.raw.blur_vertex_shader); |
|
| 143 |
final InputStream blur2FragmentStream = resources.openRawResource(R.raw.blur2_fragment_shader); |
|
| 144 |
|
|
| 145 |
try |
|
| 146 |
{
|
|
| 147 |
mBlur2Program = new DistortedProgram(blur2VertexStream,blur2FragmentStream, |
|
| 148 |
Distorted.glslVersion, |
|
| 149 |
Distorted.glslVersion + "#define MAX_BLUR "+MAX_BLUR); |
|
| 150 |
} |
|
| 151 |
catch(Exception e) |
|
| 152 |
{
|
|
| 153 |
android.util.Log.e("EFFECTS", "exception trying to compile BLUR2 program: "+e.getMessage());
|
|
| 154 |
throw new RuntimeException(e.getMessage()); |
|
| 155 |
} |
|
| 156 |
|
|
| 157 |
int blur2ProgramH = mBlur2Program.getProgramHandle(); |
|
| 158 |
mRadius2H = GLES30.glGetUniformLocation( blur2ProgramH, "u_Radius"); |
|
| 159 |
mOffsets2H = GLES30.glGetUniformLocation( blur2ProgramH, "u_Offsets"); |
|
| 160 |
mWeights2H = GLES30.glGetUniformLocation( blur2ProgramH, "u_Weights"); |
|
| 161 |
mDepth2H = GLES30.glGetUniformLocation( blur2ProgramH, "u_Depth"); |
|
| 162 |
mColorTexture2H = GLES30.glGetUniformLocation( blur2ProgramH, "u_ColorTexture"); |
|
| 163 |
mDepthTexture2H = GLES30.glGetUniformLocation( blur2ProgramH, "u_DepthTexture"); |
|
| 131 | 164 |
} |
| 132 | 165 |
|
| 133 | 166 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 239 | 272 |
|
| 240 | 273 |
int offset = radius + radius*radius/4; |
| 241 | 274 |
radius = (radius+1)/2; |
| 242 |
for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]/h; |
|
| 243 | 275 |
|
| 244 |
mPostBuffer.resizeFast( (int)w, (int)h); |
|
| 245 |
mPostBuffer.setAsOutput(time); |
|
| 246 | 276 |
GLES30.glViewport(0, 0, (int)w, (int)h); |
| 247 | 277 |
|
| 248 |
mBlurProgram.useProgram(); |
|
| 249 |
GLES30.glUniform1fv( mWeightsH, radius+1, weightsCache,offset); |
|
| 250 |
GLES30.glUniform1i( mRadiusH, radius); |
|
| 251 |
GLES30.glUniform1f( mDepthH , 1.0f-surface.mNear); |
|
| 252 |
|
|
| 253 | 278 |
// horizontal blur |
| 254 |
GLES30.glUniform1fv( mOffsetsH ,radius+1, mOffsets,0); |
|
| 255 |
GLES30.glVertexAttribPointer(mBlurProgram.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions); |
|
| 256 |
GLES30.glVertexAttribPointer(mBlurProgram.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTextureInv); |
|
| 279 |
mBlur1Program.useProgram(); |
|
| 280 |
mPostBuffer.resizeFast( (int)w, (int)h); |
|
| 281 |
mPostBuffer.setAsOutput(time); |
|
| 282 |
|
|
| 283 |
GLES30.glUniform1fv( mWeights1H, radius+1, weightsCache,offset); |
|
| 284 |
GLES30.glUniform1i( mRadius1H, radius); |
|
| 285 |
GLES30.glUniform1f( mDepth1H , 1.0f-surface.mNear); |
|
| 286 |
GLES30.glUniform1f( mColorTexture1H , 0 ); |
|
| 287 |
for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]/h; |
|
| 288 |
GLES30.glUniform1fv( mOffsets1H ,radius+1, mOffsets,0); |
|
| 289 |
GLES30.glVertexAttribPointer(mBlur1Program.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions); |
|
| 290 |
GLES30.glVertexAttribPointer(mBlur1Program.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTextureInv); |
|
| 257 | 291 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4); |
| 258 | 292 |
|
| 259 | 293 |
// vertical blur |
| 294 |
mBlur2Program.useProgram(); |
|
| 260 | 295 |
mPostBuffer.setAsInput(); |
| 296 |
mMainBuffer.setAsDepth(); |
|
| 261 | 297 |
surface.setAsOutput(time); |
| 298 |
|
|
| 299 |
GLES30.glUniform1fv( mWeights2H, radius+1, weightsCache,offset); |
|
| 300 |
GLES30.glUniform1i( mRadius2H, radius); |
|
| 301 |
GLES30.glUniform1f( mDepth2H , 1.0f-surface.mNear); |
|
| 302 |
GLES30.glUniform1f( mColorTexture2H , 0 ); |
|
| 303 |
GLES30.glUniform1f( mDepthTexture2H , 1 ); |
|
| 262 | 304 |
for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]/w; |
| 263 |
GLES30.glUniform1fv( mOffsetsH ,radius+1, mOffsets,0); |
|
| 305 |
GLES30.glUniform1fv( mOffsets2H ,radius+1, mOffsets,0); |
|
| 306 |
GLES30.glVertexAttribPointer(mBlur2Program.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions); |
|
| 307 |
GLES30.glVertexAttribPointer(mBlur2Program.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTextureInv); |
|
| 264 | 308 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4); |
| 265 | 309 |
} |
| 266 | 310 |
|
| src/main/java/org/distorted/library/program/DistortedProgram.java | ||
|---|---|---|
| 105 | 105 |
if( currChar==';') break; |
| 106 | 106 |
} |
| 107 | 107 |
|
| 108 |
if( semicolon<len && semicolon-whiteSpace>=11 ) // "attribute a;" --> 11
|
|
| 108 |
if( semicolon<len && semicolon-whiteSpace>=4 ) // "in a;" --> 4
|
|
| 109 | 109 |
{
|
| 110 | 110 |
String subline = line.substring(whiteSpace,semicolon); |
| 111 | 111 |
int subLen = semicolon-whiteSpace; |
| 112 | 112 |
|
| 113 |
if( subline.startsWith("attribute"))
|
|
| 113 |
if( subline.startsWith("in "))
|
|
| 114 | 114 |
{
|
| 115 | 115 |
//android.util.Log.e("program", "GOOD LINE: " +subline+" subLen="+subLen);
|
| 116 | 116 |
|
| 117 |
for(nameBegin=subLen-1; nameBegin>8; nameBegin--)
|
|
| 117 |
for(nameBegin=subLen-1; nameBegin>1; nameBegin--)
|
|
| 118 | 118 |
{
|
| 119 | 119 |
currChar=subline.charAt(nameBegin); |
| 120 | 120 |
|
| src/main/res/raw/blit_fragment_shader.glsl | ||
|---|---|---|
| 19 | 19 |
|
| 20 | 20 |
precision lowp float; |
| 21 | 21 |
|
| 22 |
varying vec2 v_TexCoordinate; // Interpolated texture coordinate per fragment. |
|
| 22 |
in vec2 v_TexCoordinate; // Interpolated texture coordinate per fragment. |
|
| 23 |
out vec4 fragColor; // The output color |
|
| 23 | 24 |
uniform sampler2D u_Texture; // The input texture. |
| 24 | 25 |
|
| 25 | 26 |
////////////////////////////////////////////////////////////////////////////////////////////// |
| 26 | 27 |
|
| 27 | 28 |
void main() |
| 28 | 29 |
{
|
| 29 |
gl_FragColor = texture2D(u_Texture,v_TexCoordinate);
|
|
| 30 |
fragColor = texture(u_Texture,v_TexCoordinate);
|
|
| 30 | 31 |
} |
| src/main/res/raw/blit_vertex_shader.glsl | ||
|---|---|---|
| 19 | 19 |
|
| 20 | 20 |
precision lowp float; |
| 21 | 21 |
|
| 22 |
uniform float u_Depth; // distance from the near plane to render plane, in clip coords
|
|
| 23 |
attribute vec2 a_Position; // Per-vertex position.
|
|
| 24 |
varying vec2 v_TexCoordinate; //
|
|
| 22 |
uniform float u_Depth; // distance from the near plane to render plane, in clip coords |
|
| 23 |
in vec2 a_Position; // Per-vertex position.
|
|
| 24 |
out vec2 v_TexCoordinate; //
|
|
| 25 | 25 |
|
| 26 | 26 |
////////////////////////////////////////////////////////////////////////////////////////////// |
| 27 | 27 |
|
| src/main/res/raw/blur1_fragment_shader.glsl | ||
|---|---|---|
| 1 |
////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2016 Leszek Koltunski // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Distorted. // |
|
| 5 |
// // |
|
| 6 |
// Distorted is free software: you can redistribute it and/or modify // |
|
| 7 |
// it under the terms of the GNU General Public License as published by // |
|
| 8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
| 9 |
// (at your option) any later version. // |
|
| 10 |
// // |
|
| 11 |
// Distorted is distributed in the hope that it will be useful, // |
|
| 12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
| 14 |
// GNU General Public License for more details. // |
|
| 15 |
// // |
|
| 16 |
// You should have received a copy of the GNU General Public License // |
|
| 17 |
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. // |
|
| 18 |
////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 19 |
|
|
| 20 |
precision lowp float; |
|
| 21 |
|
|
| 22 |
in vec2 v_TexCoordinate; |
|
| 23 |
out vec4 fragColor; |
|
| 24 |
uniform sampler2D u_ColorTexture; |
|
| 25 |
uniform float u_Offsets[MAX_BLUR]; |
|
| 26 |
uniform float u_Weights[MAX_BLUR]; |
|
| 27 |
uniform int u_Radius; |
|
| 28 |
|
|
| 29 |
////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 30 |
|
|
| 31 |
void main() |
|
| 32 |
{
|
|
| 33 |
vec4 pixel= texture(u_ColorTexture,v_TexCoordinate) * u_Weights[0]; |
|
| 34 |
|
|
| 35 |
for (int i=1; i<=u_Radius; i+=1) |
|
| 36 |
{
|
|
| 37 |
pixel += ( texture(u_ColorTexture,vec2(v_TexCoordinate.x+u_Offsets[i],v_TexCoordinate.y)) + |
|
| 38 |
texture(u_ColorTexture,vec2(v_TexCoordinate.x-u_Offsets[i],v_TexCoordinate.y)) ) * u_Weights[i]; |
|
| 39 |
} |
|
| 40 |
|
|
| 41 |
fragColor = pixel; |
|
| 42 |
} |
|
| src/main/res/raw/blur2_fragment_shader.glsl | ||
|---|---|---|
| 1 |
////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2016 Leszek Koltunski // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Distorted. // |
|
| 5 |
// // |
|
| 6 |
// Distorted is free software: you can redistribute it and/or modify // |
|
| 7 |
// it under the terms of the GNU General Public License as published by // |
|
| 8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
| 9 |
// (at your option) any later version. // |
|
| 10 |
// // |
|
| 11 |
// Distorted is distributed in the hope that it will be useful, // |
|
| 12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
| 14 |
// GNU General Public License for more details. // |
|
| 15 |
// // |
|
| 16 |
// You should have received a copy of the GNU General Public License // |
|
| 17 |
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. // |
|
| 18 |
////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 19 |
|
|
| 20 |
precision lowp float; |
|
| 21 |
|
|
| 22 |
in vec2 v_TexCoordinate; |
|
| 23 |
out vec4 fragColor; |
|
| 24 |
uniform sampler2D u_ColorTexture; |
|
| 25 |
uniform sampler2D u_DepthTexture; |
|
| 26 |
uniform float u_Offsets[MAX_BLUR]; |
|
| 27 |
uniform float u_Weights[MAX_BLUR]; |
|
| 28 |
uniform int u_Radius; |
|
| 29 |
|
|
| 30 |
////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 31 |
|
|
| 32 |
void main() |
|
| 33 |
{
|
|
| 34 |
gl_FragDepth = 0.0;//texture(u_DepthTexture,v_TexCoordinate); |
|
| 35 |
|
|
| 36 |
vec4 pixel= texture(u_ColorTexture,v_TexCoordinate) * u_Weights[0]; |
|
| 37 |
|
|
| 38 |
for (int i=1; i<=u_Radius; i+=1) |
|
| 39 |
{
|
|
| 40 |
pixel += ( texture(u_ColorTexture,vec2(v_TexCoordinate.x+u_Offsets[i],v_TexCoordinate.y)) + |
|
| 41 |
texture(u_ColorTexture,vec2(v_TexCoordinate.x-u_Offsets[i],v_TexCoordinate.y)) ) * u_Weights[i]; |
|
| 42 |
} |
|
| 43 |
|
|
| 44 |
fragColor = pixel; |
|
| 45 |
} |
|
| src/main/res/raw/blur_fragment_shader.glsl | ||
|---|---|---|
| 1 |
////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2016 Leszek Koltunski // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Distorted. // |
|
| 5 |
// // |
|
| 6 |
// Distorted is free software: you can redistribute it and/or modify // |
|
| 7 |
// it under the terms of the GNU General Public License as published by // |
|
| 8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
| 9 |
// (at your option) any later version. // |
|
| 10 |
// // |
|
| 11 |
// Distorted is distributed in the hope that it will be useful, // |
|
| 12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
| 14 |
// GNU General Public License for more details. // |
|
| 15 |
// // |
|
| 16 |
// You should have received a copy of the GNU General Public License // |
|
| 17 |
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. // |
|
| 18 |
////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 19 |
|
|
| 20 |
precision lowp float; |
|
| 21 |
|
|
| 22 |
varying vec2 v_TexCoordinate; |
|
| 23 |
uniform sampler2D u_Texture; |
|
| 24 |
uniform float u_Offsets[MAX_BLUR]; |
|
| 25 |
uniform float u_Weights[MAX_BLUR]; |
|
| 26 |
uniform int u_Radius; |
|
| 27 |
|
|
| 28 |
////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 29 |
|
|
| 30 |
void main() |
|
| 31 |
{
|
|
| 32 |
vec4 pixel= texture2D(u_Texture,v_TexCoordinate) * u_Weights[0]; |
|
| 33 |
|
|
| 34 |
for (int i=1; i<=u_Radius; i+=1) |
|
| 35 |
{
|
|
| 36 |
pixel += ( texture2D(u_Texture,vec2(v_TexCoordinate.x+u_Offsets[i],v_TexCoordinate.y)) + |
|
| 37 |
texture2D(u_Texture,vec2(v_TexCoordinate.x-u_Offsets[i],v_TexCoordinate.y)) ) * u_Weights[i]; |
|
| 38 |
} |
|
| 39 |
|
|
| 40 |
gl_FragColor = pixel; |
|
| 41 |
} |
|
| src/main/res/raw/blur_vertex_shader.glsl | ||
|---|---|---|
| 19 | 19 |
|
| 20 | 20 |
precision lowp float; |
| 21 | 21 |
|
| 22 |
uniform float u_Depth; // distance from the near plane to render plane, in clip coords
|
|
| 23 |
attribute vec2 a_Position; // Per-vertex position.
|
|
| 24 |
attribute vec2 a_TexCoordinate; // Per-vertex texture coordinate information we will pass in.
|
|
| 25 |
varying vec2 v_TexCoordinate; //
|
|
| 22 |
uniform float u_Depth; // distance from the near plane to render plane, in clip coords |
|
| 23 |
in vec2 a_Position; // Per-vertex position.
|
|
| 24 |
in vec2 a_TexCoordinate; // Per-vertex texture coordinate information we will pass in.
|
|
| 25 |
out vec2 v_TexCoordinate; //
|
|
| 26 | 26 |
|
| 27 | 27 |
////////////////////////////////////////////////////////////////////////////////////////////// |
| 28 | 28 |
|
| src/main/res/raw/main_fragment_shader.glsl | ||
|---|---|---|
| 21 | 21 |
|
| 22 | 22 |
uniform sampler2D u_Texture; // The input texture. |
| 23 | 23 |
|
| 24 |
varying vec3 v_Position; // Interpolated position for this fragment. |
|
| 25 |
varying vec3 v_Normal; // Interpolated normal for this fragment. |
|
| 26 |
varying vec2 v_TexCoordinate; // Interpolated texture coordinate per fragment. |
|
| 24 |
in vec3 v_Position; // Interpolated position for this fragment. |
|
| 25 |
in vec3 v_Normal; // Interpolated normal for this fragment. |
|
| 26 |
in vec2 v_TexCoordinate; // Interpolated texture coordinate per fragment. |
|
| 27 |
out vec4 fragColor; // The output color |
|
| 27 | 28 |
|
| 28 | 29 |
#if NUM_FRAGMENT>0 |
| 29 | 30 |
uniform int fNumEffects; // total number of fragment effects |
| ... | ... | |
| 92 | 93 |
|
| 93 | 94 |
void main() |
| 94 | 95 |
{
|
| 95 |
vec4 pixel = texture2D(u_Texture,v_TexCoordinate);
|
|
| 96 |
vec4 pixel = texture(u_Texture,v_TexCoordinate); |
|
| 96 | 97 |
|
| 97 | 98 |
#if NUM_FRAGMENT>0 |
| 98 | 99 |
vec2 diff; |
| ... | ... | |
| 140 | 141 |
} |
| 141 | 142 |
#endif |
| 142 | 143 |
|
| 143 |
gl_FragColor = vec4(pixel.rgb * (1.0 + 7.0*v_Normal.z) * 0.125, pixel.a);
|
|
| 144 |
fragColor = vec4(pixel.rgb * (1.0 + 7.0*v_Normal.z) * 0.125, pixel.a);
|
|
| 144 | 145 |
} |
| src/main/res/raw/main_vertex_shader.glsl | ||
|---|---|---|
| 30 | 30 |
uniform mat4 u_MVPMatrix; // the combined model/view/projection matrix. |
| 31 | 31 |
uniform mat4 u_MVMatrix; // the combined model/view matrix. |
| 32 | 32 |
|
| 33 |
attribute vec3 a_Position; // Per-vertex position.
|
|
| 34 |
attribute vec3 a_Normal; // Per-vertex normal vector.
|
|
| 35 |
attribute vec2 a_TexCoordinate; // Per-vertex texture coordinate.
|
|
| 33 |
in vec3 a_Position; // Per-vertex position.
|
|
| 34 |
in vec3 a_Normal; // Per-vertex normal vector.
|
|
| 35 |
in vec2 a_TexCoordinate; // Per-vertex texture coordinate.
|
|
| 36 | 36 |
|
| 37 |
varying vec3 v_Position; //
|
|
| 38 |
varying vec3 v_Normal; //
|
|
| 39 |
varying vec2 v_TexCoordinate; //
|
|
| 37 |
out vec3 v_Position; //
|
|
| 38 |
out vec3 v_Normal; //
|
|
| 39 |
out vec2 v_TexCoordinate; //
|
|
| 40 | 40 |
|
| 41 | 41 |
#if NUM_VERTEX>0 |
| 42 | 42 |
uniform int vNumEffects; // total number of vertex effects |
| src/main/res/raw/test_fragment_shader.glsl | ||
|---|---|---|
| 19 | 19 |
|
| 20 | 20 |
precision lowp float; |
| 21 | 21 |
|
| 22 |
out vec4 fragColor; |
|
| 23 |
|
|
| 22 | 24 |
////////////////////////////////////////////////////////////////////////////////////////////// |
| 23 | 25 |
|
| 24 | 26 |
void main() |
| 25 | 27 |
{
|
| 26 |
gl_FragColor = vec4(1.0,0.0,0.0,0.2);
|
|
| 28 |
fragColor = vec4(1.0,0.0,0.0,0.2);
|
|
| 27 | 29 |
} |
| src/main/res/raw/test_vertex_shader.glsl | ||
|---|---|---|
| 21 | 21 |
|
| 22 | 22 |
uniform vec2 u_objD; // object width X object height. |
| 23 | 23 |
uniform mat4 u_MVPMatrix; // the combined model/view/projection matrix. |
| 24 |
attribute vec2 a_Position; // Per-vertex position information we will pass in.
|
|
| 24 |
in vec2 a_Position; // Per-vertex position information we will pass in.
|
|
| 25 | 25 |
|
| 26 | 26 |
////////////////////////////////////////////////////////////////////////////////////////////// |
| 27 | 27 |
|
Also available in: Unified diff
Upgrade from GLSL 1.00 to GLSL 3.00 ES
Introduce separate BLUR1 and BLUR2 shaders, the second one marging (writing to gl_FragDepth still does not work)