Jump to content

  • Log In with Google      Sign In   
  • Create Account

All matrix operations in shader?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 nkarasch   Members   -  Reputation: 171

Like
0Likes
Like

Posted 30 September 2013 - 04:51 PM

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



Sponsor:

#2 Ravyne   GDNet+   -  Reputation: 7410

Like
2Likes
Like

Posted 30 September 2013 - 05:06 PM

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.



#3 nkarasch   Members   -  Reputation: 171

Like
0Likes
Like

Posted 30 September 2013 - 05:12 PM

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.



#4 Ravyne   GDNet+   -  Reputation: 7410

Like
0Likes
Like

Posted 30 September 2013 - 05:23 PM

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.


Edited by Ravyne, 30 September 2013 - 05:24 PM.


#5 nkarasch   Members   -  Reputation: 171

Like
0Likes
Like

Posted 30 September 2013 - 05:34 PM

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.



#6 Kaptein   Prime Members   -  Reputation: 2152

Like
0Likes
Like

Posted 30 September 2013 - 09:53 PM

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..



#7 kalle_h   Members   -  Reputation: 1389

Like
0Likes
Like

Posted 01 October 2013 - 11:58 AM

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS