• 9
• 10
• 10
• 11
• 16
• ### Similar Content

• Good evening everyone!

I was wondering if there is something equivalent of  GL_NV_blend_equation_advanced for AMD?
Basically I'm trying to find more compatible version of it.

Thank you!

• Hello guys,

How do I know? Why does wavefront not show for me?
I already checked I have non errors yet.

And my download (mega.nz) should it is original but I tried no success...
- Add blend source and png file here I have tried tried,.....

PS: Why is our community not active? I wait very longer. Stop to lie me!
Thanks !

• I wasn't sure if this would be the right place for a topic like this so sorry if it isn't.
I'm currently working on a project for Uni using FreeGLUT to make a simple solar system simulation. I've got to the point where I've implemented all the planets and have used a Scene Graph to link them all together. The issue I'm having with now though is basically the planets and moons orbit correctly at their own orbit speeds.
I'm not really experienced with using matrices for stuff like this so It's likely why I can't figure out how exactly to get it working. This is where I'm applying the transformation matrices, as well as pushing and popping them. This is within the Render function that every planet including the sun and moons will have and run.
if (tag != "Sun") { glRotatef(orbitAngle, orbitRotation.X, orbitRotation.Y, orbitRotation.Z); } glPushMatrix(); glTranslatef(position.X, position.Y, position.Z); glRotatef(rotationAngle, rotation.X, rotation.Y, rotation.Z); glScalef(scale.X, scale.Y, scale.Z); glDrawElements(GL_TRIANGLES, mesh->indiceCount, GL_UNSIGNED_SHORT, mesh->indices); if (tag != "Sun") { glPopMatrix(); } The "If(tag != "Sun")" parts are my attempts are getting the planets to orbit correctly though it likely isn't the way I'm meant to be doing it. So I was wondering if someone would be able to help me? As I really don't have an idea on what I would do to get it working. Using the if statement is truthfully the closest I've got to it working but there are still weird effects like the planets orbiting faster then they should depending on the number of planets actually be updated/rendered.

• Hello everyone,
I have problem with texture

• Hello everyone
For @80bserver8 nice job - I have found Google search. How did you port from Javascript WebGL to C# OpenTK.?
I have been searched Google but it shows f***ing Unity 3D. I really want know how do I understand I want start with OpenTK But I want know where is porting of Javascript and C#?

Thanks!

# OpenGL GLSL optimization. What is faster?

This topic is 733 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm using OpenGL ES.

And have two types of calculation "dir" vector, which code is fastest?

attribute vec2 order;


code1:

  if( abs(sinA) < 0.2 ) {
if(order.x == 1.0){
dir = sNormalPrev;
} else {
dir = sNormalNext;
}
} else {
dir *= order.x / sinA;
}


code2:

float k = step(0.2, abs(sinA));
dir = k * dir * order.x / sinA - (k-1.0) * (step(1.0, order.x + 1.0) * sNormalPrev + step(1.0, -order.x + 1.0) * sNormalNext);



##### Share on other sites

For element i of the return value, 0.0 is returned if x[i] < edge[i], and 1.0 is returned otherwise.

Parameters

edge

Specifies the location of the edge of the step function.

x

Specify the value to be used to generate the step function.

genType step( genType edge,

genType x);

now consider this

template <class T> T Max(T a, T b) { return (a > b ? a : b); } as an if if thats faster than normal if then we can debate on the thing, anyway if we dig in shit we end up with times for each gpu.

second thing seems to have more instructions than first one. since  i just converten it to asm on the flow i am not 100% sure but it seems so, fpu will do more work , and in the second line you hgave 3 ifs and on first only 2, we could rant about optimization that goes through glsl and end up that calculations (* /) are faster, but you don't always have  division in first line. someone more experienced should reply to that, but i thing for small scene without much data to process second should be faster than first one wheres first is faster for complicated scenes. , but yet not always, and again to answer the question there should be a specialist that knows how glsl optimization is done.,  thus this can vary on different gpus/cpus, and a mystery for 2016: if elses werent invented to screw the performance.

Edited by WiredCat

##### Share on other sites

Your second code can be rewritten as:

dir = mix(mix(sNormalNext, sNormalPrev, order.x), dir * order.x / sinA, step(0.2, abs(sinA)); // considering order.x == 1.0 or 0.0
// if it is not then mine code is incorrect as well as yours

Probably compiler itself will optimize your code to something similar?. But it is now much more clear that both of your options are pretty similar.

There are two things to consider:

1. Control divergence. GPU core is a SIMD processor and shaders are executed in packages (aka warps/wavefronts) and if execution follows different branches in one package then both branches are executed in the end (plus some overhead for masking shaders and conditional statements). First option will only be faster if there is no control divergence inside a package. Which depends on:

sinA - is it uniform? In that case there will be no divergence for the first 'if'.

order.x - it is vertex attribute so I'd replace second 'if' with mix(sNormalNext, sNormalPrev, order.x).

2. Execution latency of both versions might be hidden by memory operations. If subsequent code contains texture read then when execution of a package reaches texture read instruction, GPU core will switch to another package which will execute the code while texture unit is fetching data from memory for the first package. It is possible that there is no point in optimizing this code at all.

Edited by Alex Mekhed

##### Share on other sites

as you see its comples thing you need to poert shite into your own needs then we can talk about optimization, thus if else is the best thing you can use as far you dont use much else condition