0

In HLSL, how can I calculate lighting based on pixels of a texture, instead of pixels that make up the object?

In other words, if I have a 64x64px texture being rendered on a 1024x768px screen, I want to calculate the lighting as it affects the 64x64px space, resulting in jagged pixels instead of a smooth line.

I've researched dozens of answers but I'm not sure how I can determine at all times if a fragment is a part of a pixel that should be fully lit or not. Maybe this is the wrong approach?

The current implementation uses a diffuse texture and a normal map. It results in what appear as artifacts (diagonal lines) in the output:

enter image description here

enter image description here

Note: The reason it almost looks correct is because of the normal map, which causes some adjacent pixels to have normals that are angled just enough to light some pixels and not others.

Felipe
  • 10,606
  • 5
  • 40
  • 57
  • you are already doing point sampling on both the diffuse texture and the normal textures right? – Brice V. Jun 27 '18 at 13:30
  • @BriceV. yes. I also [posted this on the gamedev](https://gamedev.stackexchange.com/questions/159699/half-shaded-pixel-artifacts-on-2d-dynamic-lighting-shader) stack as well and shared the code there. It was written as a surface shader but I've since changed it to vert/frag shader. – Felipe Jun 28 '18 at 14:17
  • I've decided to render to a texture and blow up the image into the camera in order to retain a pixel-perfect old-school look and it solves the problem, but it doesn't answer how this can be done in a shader u__u – Felipe Jun 28 '18 at 14:18

0 Answers0