All matrix operations in shader?

Started by
5 comments, last by kalle_h 10 years, 6 months ago

I ask my Graphics Programming professor if I could use something I am familiar with like GLM and he said no, we are supposed to do everything in the vertex shader. From my experience/understanding, it makes more sense to calculate the model-view-projection matrix once per model for this simple program and pass it in through a uniform.

I think he wants us to create all of the matrices in the shader code, can that ever make sense? I don't understand why you would EVER create your main view and projection matrices within a shader. Thanks

Advertisement

Whether or not you can think of a good reason to do it in production is an entirely separate question than why your professor wants you to do it in a particular way. It might feel a bit icky, but the professor might well have a good reason for doing things this way, for example, if the exercise intends to show that students know how to multiply matrices together, or matrices and vertices, inside a shader, then the instructor might (probably rightly) believe that this exercise is a simple way to demonstrate the students' abilities by using a concept everyone ought to know. If they chose a more "real-world" scenario, then he's no longer grading the students' ability to do matrix/vector math in a shader, but also in their ability to solve whatever other problem he presented, which might not be level-appropriate.

In short, programming in a educational environment has very different requirements than in a production environment. Just give the professor what they are asking for, and don't worry about demonstrating the "right" or "best" way of doing things -- that's not the assignment. If you're ahead of the game enough to know that there are better ways, you're already doing fine. And if you feel the need to scratch the itch of doing it right, no one's stopping you. That's what learning is all about.

throw table_exception("(? ???)? ? ???");

Thanks for the friendly reply. Yeah it is very frustrating, I have my 4000+ line "3D engine" I have been working on that would make this assignment take 10 minutes. I expected I could just strip it down to the essentials and reuse my code for these assignments. Now I'm having to start over, sweating over finding a new way to do the basics in the way he wants.

Well, to be fair, he's not asking for your old work, stripped down. He's asking for new work, the same he expects of everyone else. If you could hand in work you've already done, it wouldn't be fair to the other students, nor would it be a particularly good showing of how well you understand or retain the material currently -- that is, it doesn't say much that you were able to recycle some code you wrote last year over the course of perhaps weeks, compared to the other students who wrote their code last week in a few hours. College isn't about rubber-stamping you for knowing certain things, its also about vetting your ability to work to requirements, meet deadlines, and to some degree determine your performance relative to your peers.

And just to be additionally clear, there probably are plenty of reason you might want to do MVP in your shader -- for instance, if you do instanced rendering, V changes for each instance, possibly M, but probably not P. If you have a lot of instances, its probably more efficient to do it in the shader. You could precalculate the entire array if instance MVPs on the CPU and pass them up to the shader, but maybe its less efficient, or maybe you're CPU-bound, but not GPU-bound. Or, maybe you're re-deriving M, V, or P from a compressed form to save space in your constant buffers.

throw table_exception("(? ???)? ? ???");

Thanks, I don't know about instanced rendering yet but now I have something new to read about ohmy.png

I think it's all opinion but I disagree about me reusing my work being unfair to other students. If I have spent 12 hours a day working on this stuff since school resumed, I don't think it's unfair for me to get to reuse code. It's also NOT unfair to me that I have to start over, I wasn't trying to say that either.

Thanks, I don't know about instanced rendering yet but now I have something new to read about ohmy.png

I think it's all opinion but I disagree about me reusing my work being unfair to other students. If I have spent 12 hours a day working on this stuff since school resumed, I don't think it's unfair for me to get to reuse code. It's also NOT unfair to me that I have to start over, I wasn't trying to say that either.

If it makes you think, it was probably worth it

If it's so easy, add easter eggs :)

Or refactor your engine after your done.. It's a lifelong never-ending ever-changing profession

Try to avoid being like me though, i recently removed an extra space in a code line and comitted it..

Shader code is easy to review and everything is at one place. This make your professor life easier. Also it's make cheating harder because not many examples at internet do all canera related calculations at vertex shader.

This topic is closed to new replies.

Advertisement