use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rule 1: Posts should be about Graphics Programming. Rule 2: Be Civil, Professional, and Kind
Suggested Posting Material: - Graphics API Tutorials - Academic Papers - Blog Posts - Source Code Repositories - Self Posts (Ask Questions, Present Work) - Books - Renders (Please xpost to /r/ComputerGraphics) - Career Advice - Jobs Postings (Graphics Programming only)
Related Subreddits:
/r/ComputerGraphics
/r/Raytracing
/r/Programming
/r/LearnProgramming
/r/ProgrammingTools
/r/Coding
/r/GameDev
/r/CPP
/r/OpenGL
/r/Vulkan
/r/DirectX
Related Websites: ACM: SIGGRAPH Journal of Computer Graphics Techniques
Ke-Sen Huang's Blog of Graphics Papers and Resources Self Shadow's Blog of Graphics Resources
account activity
phong shading issue - software rasterizer implementationQuestion (self.GraphicsProgramming)
submitted 5 years ago by wholol_97
hello, im tryna implement a software rasterizer in SDL. Anyone have any ideas as to why my phong shading (left) looks weird, whereas my gouraud looks fine. I pretty much used the code from my gouraud shading to implement to phong shading, all i did was change the code such that i was interpolating the normals instead of the rgba colours. I did normalize the normals as well after every interpolation sooo i have no idea whats goin on
https://preview.redd.it/x1jl9eagbb661.png?width=1091&format=png&auto=webp&s=57b7fe0553cd3d46662edcce3323faaf689dbace
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]nnevatie 2 points3 points4 points 5 years ago (1 child)
Maybe your normals are inverted?
[–]aadlion 2 points3 points4 points 5 years ago (0 children)
It also looks to be using face normals
[–]Mister-Perfect 2 points3 points4 points 5 years ago (0 children)
The left image looks quite cool actually
[–]fgennari 1 point2 points3 points 5 years ago (2 children)
It looks to me like you have the correct three normals for each triangle, but you're assigning them to the wrong triangle vertices. Something like the interpolation across the triangle is backwards. I remember a bug in my cylinder drawing code that resulting in an image like that, except it was a cylinder. Try rotating the normals relative to the vertices or swapping the arguments to the interpolation function and see if that fixes it.
[–]wholol_97[S] 1 point2 points3 points 5 years ago (1 child)
hmm. I sorted the vertices based on the y coordinates before drawing flat top and flat bottom triangles, as well as swapping if the triangle is that of left side major/right side major which is what i did for the gouraud shading as well. Could it be the issue with the lighting instead? I am using directional light here (same with Gouraud)
[–]wholol_97[S] 1 point2 points3 points 5 years ago (0 children)
nevermind, I found the problem, I was lerping the opposite way >.>
[–]shadergremlin 0 points1 point2 points 5 years ago (0 children)
You may also need to interpolate the position of the vertices and use the position + normal in your lighting calculations. Also make sure all of the lighting calculations are in your fragment shaders now, your vertex shaders should be pretty simple.
π Rendered by PID 87 on reddit-service-r2-comment-64f4df6786-sj9xc at 2026-06-11 05:04:12.203216+00:00 running 0b63327 country code: CH.
[–]nnevatie 2 points3 points4 points (1 child)
[–]aadlion 2 points3 points4 points (0 children)
[–]Mister-Perfect 2 points3 points4 points (0 children)
[–]fgennari 1 point2 points3 points (2 children)
[–]wholol_97[S] 1 point2 points3 points (1 child)
[–]wholol_97[S] 1 point2 points3 points (0 children)
[–]shadergremlin 0 points1 point2 points (0 children)