0

Hello I am Using GPUImage Library for iOS project where I am creating sketch of the Image using GLSL ES fragment shader as following:

public let SketchFragmentShader = "
precision mediump float;

varying vec2 textureCoordinate;
varying vec2 leftTextureCoordinate;
varying vec2 rightTextureCoordinate;

varying vec2 topTextureCoordinate;
varying vec2 topLeftTextureCoordinate;
varying vec2 topRightTextureCoordinate;
varying vec2 bottomTextureCoordinate;
varying vec2 bottomLeftTextureCoordinate;
varying vec2 bottomRightTextureCoordinate;
uniform float edgeStrength;

uniform sampler2D inputImageTexture;

void main()
{
    float bottomLeftIntensity = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r;
    float topRightIntensity = texture2D(inputImageTexture, topRightTextureCoordinate).r;
    float topLeftIntensity = texture2D(inputImageTexture, topLeftTextureCoordinate).r;
    float bottomRightIntensity = texture2D(inputImageTexture, bottomRightTextureCoordinate).r;
    float leftIntensity = texture2D(inputImageTexture, leftTextureCoordinate).r;
    float rightIntensity = texture2D(inputImageTexture, rightTextureCoordinate).r;
    float bottomIntensity = texture2D(inputImageTexture, bottomTextureCoordinate).r;
    float topIntensity = texture2D(inputImageTexture, topTextureCoordinate).r;

    float h = -topLeftIntensity - 2.0 * topIntensity - topRightIntensity + bottomLeftIntensity + 2.0 * bottomIntensity + bottomRightIntensity;
    float v = -bottomLeftIntensity - 2.0 * leftIntensity - topLeftIntensity + bottomRightIntensity + 2.0 * rightIntensity + topRightIntensity;
    float mag = 1.0 - (length(vec2(h, v)) * edgeStrength);

    gl_FragColor = vec4(vec3(mag), 1.0);
}"

Since this allows to change edgeStrength but how can I:

  1. alter thickness or heaviness in shader with float value?
  2. alter noise produced with float value?
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
Rakshit Korat
  • 1,159
  • 10
  • 23
  • 1. You can't because the shader detects edges on neighboring fragments only, it can't detect edges which are further away as the distance of one fragment. Probably you would have to look up more than the 9 texels as in the shader code. 2. [Random / noise functions for GLSL](https://stackoverflow.com/questions/4200224/random-noise-functions-for-glsl) – Rabbid76 Oct 28 '18 at 17:16
  • I am sorry It was GLES, so can do it with GLES fragment shader? – Rakshit Korat Oct 28 '18 at 18:19
  • You're wrong, the language is [OpenGL ES Shading Language (GLSL ES)](https://www.khronos.org/opengles/sdk/docs/manglsl/docbook4/). GLES means [OpenGL ES](https://www.khronos.org/opengles/) but not the shading language. – Rabbid76 Oct 28 '18 at 18:33
  • Ok, thanks a lot. Is there a ways to achieve such. Both edge thickness and noise where it’s compatible with iOS framework? – Rakshit Korat Oct 28 '18 at 19:25

0 Answers0