# Using PShader and GLSL to make swaying grass

**URL:** https://discourse.processing.org/t/using-pshader-and-glsl-to-make-swaying-grass/32666
**Category:** Coding Questions
**Created:** [October 7, 2021, 6:27am UTC](https://discourse.processing.org/t/using-pshader-and-glsl-to-make-swaying-grass/32666 "2021-10-07T06:27:35Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Vertexia](https://avatars.discourse-cdn.com/v4/letter/v/ee7513/32.png) [@Vertexia](https://discourse.processing.org/u/Vertexia)
#### Post date: [October 7, 2021, 6:27am UTC](https://discourse.processing.org/t/using-pshader-and-glsl-to-make-swaying-grass/32666/1 "2021-10-07T06:27:35Z")

</div>

I’m trying to add swaying grass using both a vector and a fragment shader in a 2d game, and I’m up to the point where i need to add the image to the fragment shader. Right now I’m using image() to render the image, but the fragment shader isn’t receiving the texture, I’m not very sure how it works anymore as in the rework of the [processing.org](http://processing.org) website they deleted the example of PShader 😕

Frag

```auto
precision mediump float;
precision mediump int;
#endif

#define PROCESSING_TEXTURE_SHADER

uniform sampler2D texture;
uniform vec2 texOffset;

varying vec4 vertColor;
varying vec4 vertTexCoord;

uniform float dW;
uniform float dH;

void main(void) {
    vec4 alpha = texture2D(texture, vertTexCoord.st);
    gl_FragColor = vec4(alpha.xyz, 1.0);
}

```

Vertex

```auto
precision mediump float;

uniform float dW;
uniform float dH;

attribute vec4 vertex;
void main() {
    vec4 newVecSet = vec4((vertex.x/dW*2)-1.0, -((vertex.y/dH*2)-1.0), vertex.z, vertex.w);
    gl_Position = newVecSet;
}

```

Base code

```auto
shader(sh);
image(Img, 0, 0);
resetShader();

```

---

<div class="post-metadata">

### Author: ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)
#### Post date: [October 7, 2021, 6:40am UTC](https://discourse.processing.org/t/using-pshader-and-glsl-to-make-swaying-grass/32666/2 "2021-10-07T06:40:15Z")

</div>

Do you have the rest of the code please

---

<div class="post-metadata">

### Author: ![Vertexia](https://avatars.discourse-cdn.com/v4/letter/v/ee7513/32.png) [@Vertexia](https://discourse.processing.org/u/Vertexia)
#### Post date: [October 7, 2021, 6:41am UTC](https://discourse.processing.org/t/using-pshader-and-glsl-to-make-swaying-grass/32666/3 "2021-10-07T06:41:03Z")

</div>

That’s all you need, if you want the rest of the code i will have to port 8000 lines

---

<div class="post-metadata">

### Author: ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)
#### Post date: [October 7, 2021, 6:43am UTC](https://discourse.processing.org/t/using-pshader-and-glsl-to-make-swaying-grass/32666/4 "2021-10-07T06:43:43Z")

</div>

I mean the draw method or is that long too?

---

<div class="post-metadata">

### Author: ![Vertexia](https://avatars.discourse-cdn.com/v4/letter/v/ee7513/32.png) [@Vertexia](https://discourse.processing.org/u/Vertexia)
#### Post date: [October 7, 2021, 6:44am UTC](https://discourse.processing.org/t/using-pshader-and-glsl-to-make-swaying-grass/32666/5 "2021-10-07T06:44:12Z")

</div>

Yeah lol, All of the image loading is fine, there are no issues in the base code, only in shader

---

<div class="post-metadata">

### Author: ![Vertexia](https://avatars.discourse-cdn.com/v4/letter/v/ee7513/32.png) [@Vertexia](https://discourse.processing.org/u/Vertexia)
#### Post date: [October 7, 2021, 6:45am UTC](https://discourse.processing.org/t/using-pshader-and-glsl-to-make-swaying-grass/32666/6 "2021-10-07T06:45:23Z")

</div>

It has been resolved by the discord lel, thanks for helping tho
