Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (799)
Games in Android Showcase (237)
games submitted by our members
Games in WIP (865)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [GLSL] Simplify this vertex passthrough  (Read 1423 times)
0 Members and 1 Guest are viewing this topic.
Offline orange451

JGO Kernel


Medals: 544
Projects: 8
Exp: 8 years


Your face? Your ass? What's the difference?


« Posted 2014-07-02 23:25:51 »

In a shader I'm making for a simple little side-project, I ended up needing to do this to make the shader be more flexible:
1  
2  
3  
4  
5  
if (useViewMatrix == 1) {
   gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position, 1.0);
} else {
   gl_Position = projectionMatrix * modelMatrix * vec4(position, 1.0);
}


I was wondering, however, if there was a way to simplify this down to 1 line.

First Recon. A java made online first person shooter!
Offline The Lion King
« Reply #1 - Posted 2014-07-02 23:31:31 »

You could look into using subroutines, which wont make this into one line but will remove the if statement. (probably overkill)

If you are using the same ViewMatrix across the board then you could mutliply the Projection and View matrix on the CPU side and send a ViewProjectionMatrix. If you are not using the view matrix just send the Projection Matrix as is for the ViewProjectionMatrix

edit:

1  
if (useViewMatrix == 1) {gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position, 1.0);} else {gl_Position = projectionMatrix * modelMatrix * vec4(position, 1.0);}


1 line, problem solved Smiley

"You have to want it more than you want to breath, then you will be successful"
Offline pitbuller
« Reply #2 - Posted 2014-07-02 23:49:30 »

Pre multiply this
1  
projectionMatrix * viewMatrix * modelMatrix
at cpu. Cpu can then decide per draw call is view matrix used or not. You can't get simpler than that.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline orange451

JGO Kernel


Medals: 544
Projects: 8
Exp: 8 years


Your face? Your ass? What's the difference?


« Reply #3 - Posted 2014-07-02 23:54:14 »

Yah I just figured that Smiley
Makes everything much faster.

First Recon. A java made online first person shooter!
Pages: [1]
  ignore  |  Print  
 
 

 
Riven (189 views)
2019-09-04 15:33:17

hadezbladez (4875 views)
2018-11-16 13:46:03

hadezbladez (1790 views)
2018-11-16 13:41:33

hadezbladez (5147 views)
2018-11-16 13:35:35

hadezbladez (1018 views)
2018-11-16 13:32:03

EgonOlsen (4369 views)
2018-06-10 19:43:48

EgonOlsen (5220 views)
2018-06-10 19:43:44

EgonOlsen (2949 views)
2018-06-10 19:43:20

DesertCoockie (3868 views)
2018-05-13 18:23:11

nelsongames (4294 views)
2018-04-24 18:15:36
Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!