Yesterday I realized I sat down and worked on one shader for over 6 hours for one of the homework questions... when you look up from your monitor and the room is pitch dark it's time to take a break. The shader I was working on was actually very very simple, just a fragment based one that can implement a texture and a specular map. However, I was having a
lot of problems because of the program I was working in that I still haven`t resolved.
I was working with OpenGL Shader Designer, a cool little program that lets you see how your shaders would look in realtime without having to write all the base code (viewports, rotation controls, etc.). It just lets you put some textures in there and loads up one of a couple of default meshes for you to work with. Super cool idea! Not so great in practice.
I continually ran into issues that I couldn`t resolve without access to the base part of the program (not the .vert or .frag) but that wasn`t included in the software, meaning I was constantly finding work arounds. The other problem was a lot of the syntax we learned in class had to be thrown out the window because the software works in version 1.8ish. It never actually said what version, but whenever I tried something from the newer version it would yell at me in confusion.
 |
| Final sphere result |
So in the end this is what I settled on as being good enough. I was tired of working on it and the thought of trying to add in displacement/normal mapping... again.... *shudder*
I'm pretty pleased with it overall though, it's a fairly basic Phong shader that
ought to have a specular map but for whatever reason doesn't show it. I honestly think that's a flaw in the software though, not my shader's code. I guess I'll find out when I get our TA to take a look at it on Thursday/Friday but it was such a pain in the butt I doubt I'll finish it up unless it's the easiest fix.
On the plus side, this has really helped reinforce all the practical stuff we've learned in Graphics this semester. Before yesterday shader programming was a huge mystery to me, not with the theory but the code itself. It still boggles my mind where this information comes from to get into the program but hey, who am I to argue if it works!
 |
| Code Screenshot (.frag) |
I might as well talk a little bit about the code! I thought it's about time for a more hardcore blog. Rather than going into full detail, as that would take... a while, I'll just explain the basics of the program. In any shader that takes lighting into account, the 3 main types of light need to be considered: diffuse, ambient, and specular. Specular was what I dealt with most in this particular .frag as I was trying to implement a specular/gloss map. The map that I was using was loaded on line 26, with "vec3 glossTexel = normalize(texture2D(texture2, gl_TexCoord[0].st).rgb & 2.0 - 1.0);". This line gets the texture from within gl_TexCoord as a 3D vector, then normalizes it. Calculations are done to determine how the object interacts with diffuse lighting and how it's affected by the glossiness, and the specular lighting and how it's affected if the shininess is > 0.0;
Side note: f this is considered a 2/2 blog, and my other ones all aren't, please let me know! I'd really like to know what is being looked for in order to do well in this portion of the course, and without feedback we're all feeling rather in the dark. Even just a heads-up of how many points we all have so far would be super appreciated!! :-)