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

JGO Kernel

Medals: 564
Projects: 8
Exp: 8 years

 « 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!
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

"You have to want it more than you want to breath, then you will be successful"
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.
orange451

JGO Kernel

Medals: 564
Projects: 8
Exp: 8 years

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

Yah I just figured that
Makes everything much faster.

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

 Riven (353 views) 2019-09-04 15:33:17 hadezbladez (5193 views) 2018-11-16 13:46:03 hadezbladez (2078 views) 2018-11-16 13:41:33 hadezbladez (5415 views) 2018-11-16 13:35:35 hadezbladez (1128 views) 2018-11-16 13:32:03 EgonOlsen (4552 views) 2018-06-10 19:43:48 EgonOlsen (5413 views) 2018-06-10 19:43:44 EgonOlsen (3091 views) 2018-06-10 19:43:20 DesertCoockie (3986 views) 2018-05-13 18:23:11 nelsongames (4590 views) 2018-04-24 18:15:36
 A NON-ideal modular configuration for Eclipse with JavaFXby philfrei2019-12-19 19:35:12Java Gaming Resourcesby philfrei2019-05-14 16:15:13Deployment and Packagingby philfrei2019-05-08 15:15:36Deployment and Packagingby philfrei2019-05-08 15:13:34Deployment and Packagingby philfrei2019-02-17 20:25:53Deployment and Packagingby mudlee2018-08-22 18:09:50Java Gaming Resourcesby gouessej2018-08-22 08:19:41Deployment and Packagingby gouessej2018-08-22 08:04:08
 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