# Creating a simple Shadow Shader

**URL:** <https://discourse.processing.org/t/creating-a-simple-shadow-shader/43690>\
**Category:** Coding Questions\
**Created:** [January 15, 2024, 1:29am UTC](https://discourse.processing.org/t/creating-a-simple-shadow-shader/43690 "2024-01-15T01:29:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Noodlybanan](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noodlybanan/32/18897_2.png) [@Noodlybanan](https://discourse.processing.org/u/Noodlybanan)\
**Post date:** [January 15, 2024, 1:29am UTC](https://discourse.processing.org/t/creating-a-simple-shadow-shader/43690/1 "2024-01-15T01:29:45Z")

</div>

Hello,

I wanted to add shadows to my sketch, however I only found ways in P2D to use the blur shader examples, and i don’t know on how a shader could be translated to processing.

This is my code (i wanted to add shadows):

```auto
float angleX = 0;
float angleY = 0;
float cameraDistance = 300;

PShader shadowShader;

void setup() {
  size(800, 600, P3D);

  shadowShader = loadShader("shadow_shader.glsl");
}

void draw() {
  background(255);
  
  shader(shadowShader);

  perspective(radians(45), float(width) / float(height), 1, 1000);

  float camX = cameraDistance * cos(radians(angleY)) * sin(radians(angleX));
  float camY = cameraDistance * sin(radians(angleY));
  float camZ = cameraDistance * cos(radians(angleY)) * cos(radians(angleX));
  camera(camX, camY, camZ, 0, 0, 0, 0, 1, 0);

  fill(200);
  beginShape();
  vertex(-100, 0, -100);
  vertex(100, 0, -100);
  vertex(100, 0, 100);
  vertex(-100, 0, 100);
  endShape(CLOSE);

  translate(0, -50, 0);
  box(30);
  
  resetShader();
}

void mouseDragged() {
  angleX += radians((pmouseX - mouseX) * 5);
  angleY += radians((mouseY - pmouseY) * 5);
}

```

Thanks for any help 🙂
