• Advertisement

Archived

This topic is now archived and is closed to further replies.

OpenGL OpenGL vs. DirectX

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Okay, now I don''t want to start a flame war and I don''t want to cause any trouble, but I''m thinking of programming games and I''m not sure which API to use. I''ll probably use Allegro for the 2D, I have VC++ 6.0 Enterprise, and I''m going to try to learn Assembly language. I program on WinME, and I''m not sure which API to use. Advise please? If you would criticize another person, you must first walk a mile in their moccasins. That way, If they get mad, they''''ll be a mile away and barefoot.

Share this post


Link to post
Share on other sites
Advertisement
Direct X is much better documented than OpenGL. There are SO many more books:

www.PrimaGameDev.com

Theres alot of Direct X books there.

I use OpenGL but I might switch over..

For openGL, there is:

nehe.gamedev.net

for online tutorials

and "OpenGL Game Programming" is a great book to learn with.

Direct X is only for Windows, so Linux, Mac, etc dont support it.

OpenGL can be changed to suit most platforms if not all, I believe.

Direct X inlcudes:

D3D
DInput
DSound
DPlay ( for multplayer, so I am told )

and OpenGL only is for making the graphics. To tell you the truth, Direct X seems like the better choice but you should learn both.

Share this post


Link to post
Share on other sites
Since I don''t wanna start another flame war about Opengl vs. D3D I just want to mention that WinME will probably be your biggest concern. go with Win2K, WinNT 4.0 (like me), or even Linux, of course if you choose one of the last 2, you''ll have to go with OpenGL like me.... speed diffrence? none, at least not important for you...

cya,
Phil


Visit Rarebyte!
and no!, there are NO kangaroos in Austria (I got this questions a few times over in the states

Share this post


Link to post
Share on other sites
Gee. Thanks for your, um, ambiguity. Hey guys? I take back what I said about no flame wars, if it will help me come to a decision. (Come to think of it, it probably won''t)

If you would criticize another person, you must first walk a mile in their moccasins. That way, If they get mad, they''''ll be a mile away and barefoot.

Share this post


Link to post
Share on other sites
I''m not too familiar with OpenGL. I used it in school a little bit, but not enough to make a comment on it. I do recommend DirectX though. It includes code for sound, multiplayer, and input devices, so it is a good place to start. Once you understand the basics of how one part works(DirectDraw for example) its not too hard to learn one of the others(DirectPlay for example). While I''m sure there may be tons of arguments that there are better ways to do things such as networking, DirectX is a good encapsulation of them all, and at the very least a good place to start.

Share this post


Link to post
Share on other sites
quote:
Original post by Abcd_z
If you would criticize another person, you must first walk a mile in their moccasins. That way, If they get mad, they''ll be a mile away and barefoot.


I love that. I dont know why, but I do.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
OpenGL is only competing with Direct3D and not all of APIs in DirectX. Direct3D is certainly not better documented than OpenGL. If you go with OpenGL will you still need stuff like DirectSound. Another alternative is using allegro (allegrogl) with OpenGL.
Take a look at both but I think that OpenGL is little easier and much more fun to work with.

Share this post


Link to post
Share on other sites
Wow...and Furby hasn''t paid a visit to this thread yet....highly rare..

WinME blows big time. Avoid XP like the plague. Stick to vanilla Win98 or Win2k, as I''ve found them to be the best all round development machines that don''t make you reboot TOO often..

NT used to be good until a reboot was required after each installation of software...UGH..plus it won''t run anything higher than DX3. Nice.

hmmmmm I need some GOOD flame bait here....just can''t think of anything right now, other than WinME sucks.

Wazoo

Share this post


Link to post
Share on other sites
quote:
Original post by wazoo69
WinME blows big time.


Why? Am I missing out on something? I''ve got WinME, but I don''t see any problem with it. Is there something I should know that nobody is telling me?



~ There''s no substitute for failure ~

Share this post


Link to post
Share on other sites
I dont know what you guys are talking about when you say WinXP sucks. Its like the same thing as Windows 2000 except it boots like 2x as fast. Also I heard alot of bad heat on WinXP needing www activation so you couldn't pirate it? What's with that? My bro installed it no problem. You think he actually bought his OS ??

He installed the professional version though. I heard its only the home user verison that does that activation thingy. I would never run an OS that only does mono-processor.

I personally run Win2k, only cause I can't handle the WinXP Hot Wheels look


Back to the DX/GL topic, every person who posts here is obviously going to say "DX is better" cause its basically a DX fan site
Same goes for if you go next door to the GL forum, everyone is going to say GL is better.

My reasons for using DX is because it is more the industry standard for game programming. Also I coded for GL for a while and it was lacking utility functions (Mesh Loading, Particles, Animation, etc). GL is more geared towards 3D modeling programs than games.

Oh and the thing that I don't really understand is how ppl say that GL is better cause its portable? I understand that but if you want to port your game to Linux or Mac, you are going to have to change all the Windows API stuff anyway and its still going to be a pain to port.

Correct me if im wrong.


Edited by - Psionic on September 26, 2001 11:56:59 AM

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by PSioNiC
I dont know what you guys are talking about when you say WinXP sucks. Its like the same thing as Windows 2000 except it boots like 2x as fast. Also I heard alot of bad heat on WinXP needing www activation so you couldn''t pirate it? What''s with that? My bro installed it no problem. You think he actually bought his OS ??

He installed the professional version though. I heard its only the home user verison that does that activation thingy. Oh well I would never run an OS that only does mono-processor.

I personally run Win2k, only cause I can''t handle the WinXP Hot Wheels look


Back to the DX/GL topic, every person who posts here is obviously going to say "DX is better" cause its basically a DX fan site
Same goes for if you go next door to the GL forum, everyone is going to say GL is better.

My reasons for using DX is because it is more the industry standard for game programming. Also I coded for GL for a while and it was lacking utility functions (Mesh Loading, Particles, Animation, etc). GL is more geared towards 3D modeling programs than games.

Oh and the thing that I don''t really understand is how ppl say that GL is better cause its portable? I understand that but if you want to port your game to Linux or Mac, you are going to have to change all the Windows API stuff anyway and its still going to be a pain to port.

Correct me if im wrong.



Edited by - Psionic on September 26, 2001 11:54:56 AM


Share this post


Link to post
Share on other sites
quote:
Original post by PSioNiC
Oh and the thing that I don''t really understand is how ppl say that GL is better cause its portable? I understand that but if you want to port your game to Linux or Mac, you are going to have to change all the Windows API stuff anyway and its still going to be a pain to port.

Correct me if im wrong.


Using OpenGL alone, that would be true. I use OpenGL with the SDL and my engine will compile under Windows, Linux, BeOS, and MacOS without any changes. I''m also writing a library to abstract some less game oriented stuff that I may use in the future.

[Resist Windows XP''s Invasive Production Activation Technology!]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Okay, forget what I said about WinME. Also, I probably should have put this topic under general gaming. BUT, I''d also like to know if you have to know things like words and dwords to program in Directx.

If you would criticize another person, you must first walk a mile in their moccasins. That way, If they get mad, they''ll be a mile away and barefoot.

Share this post


Link to post
Share on other sites
Jesus, its so sad to see the poor OpenGL users stating the only reason to use opengl is portability to mac and linux. My god (yes I am praying for you) get a life, how many of you on this forum own a mac,linux box and a windows pc and are actually gonna port your own little projects and experiments to them? And how many of you have actually done it already?

So, yah, if your a professional game developer with a $5m budget and an entire staff and gonna release a mega hit game, then yes the argument to consider porting to mac (not linux) is a valid argument for opengl. Maybe I am wrong, but Abcd_z doesnt seem like a professional developer heading up a full developement studio making a real game.

And OpenGL is NOT easier then Directx. Direct3D8 is far easier to learn and understand then OpenGL is anyday, and the documentation available for it is about 10x more then available for opengl. Plus the DirectX SDK kicks ass, if opengl had one of equal quality and ease of use ... well it doesnt.

Possibility

Edited by - Possibility on September 27, 2001 3:06:22 AM

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by Possibility
Jesus, its so sad to see the poor OpenGL users stating the only reason to use opengl is portability to mac and linux. My god (yes I am praying for you) get a life, how many of you on this forum own a mac,linux box and a windows pc and are actually gonna port your own little projects and experiments to them? And how many of you have actually done it already?


I have, I still do. I hope your boss will never ask your to write a portable application, ''cause you''ll have no clue about it. Experience is a good thing. One could ask why the heck you''re developing games as an amateur if it''s not for fun and/or the sake of learning.

Because you don''t own a Linux or Mac doesn''t mean they suck, it just means you''ve got no right to criticize them, as you don''t know what they are capable of.


quote:

So, yah, if your a professional game developer with a $5m budget and an entire staff and gonna release a mega hit game, then yes the argument to consider porting to mac (not linux) is a valid argument for opengl. Maybe I am wrong, but Abcd_z doesnt seem like a professional developer heading up a full developement studio making a real game.


Neither do you. Writing portable and reusable code is what can make or break your project. What if MS chooses to change their Win32 API? Or change DirectX again? Or forget DX and move to something else, like they did with WinG a while ago? Will you be starting over, praying than they don''t change anymore while you rewrite your code base? Or will you be one of these smart, good programmers who made/used a library to abstract the platform specific code?

Best 3D engine in the world, right now is id''s Quake 3 engine. Why? Because of its advanced features, of course, because it''s portable, modular, etc. Oh and it uses OpenGL, even though it could just use D3D as well.. Can you say that about your game?

quote:
And OpenGL is NOT easier then Directx. Direct3D8 is far easier to learn and understand then OpenGL is anyday, and the documentation available for it is about 10x more then available for opengl. Plus the DirectX SDK kicks ass, if opengl had one of equal quality and ease of use ... well it doesnt.



its so sad to see the poor DirectX users stating the only reason to use DirectX is because it kicks ass.

Whether one sucks and the other kicks ass is a matter of point of vue. DirectX documentation and resources are dwarfed by their OpenGL equivalent, sorry.

As for ease of use, it is, once again, a matter of point of vue. Until very recently, OGL was easier. DX8 made DirectGraphics easy to learn, but IMO GL is still easier. Others will disagree.

Possibility

Share this post


Link to post
Share on other sites
Whichever API you choose is upto you. Personally I prefer OpenGL because I like its structure more, it''s faster on my gfx card, and I have access to features on it through extensions that D3D doesnt have. I also use DirectInput for my keyboard and mouse handling.

A quick rundown of the two will show that they are more or less equal.

D3D:
Cons - Windows only, requires a 45meg download to use, doesnt support some hardware features

Pros - Lots of hardware support for it, lots of software uses it, more tightly integrated into Windows.


OGL:
Cons - Some driver vendors have very nasty drivers, not as tightly integrated into the OS

Pros - Most hardware supports it, supports new hardware features through extensions, no big download required to use.

Look up both and choose which you wish to use. One is NOT better than the other, they both use the same hardware to do the same stuff. The biggest difference is the look of the code for them.

Share this post


Link to post
Share on other sites
I won''t disagree

OPENGL IS SO MUCH EASIER TO USE. Especially when it comes to initializing stuff and getting down to actual business. With direct3D (and I''m talking about DX 7, I haven''t really worked with 8) you have to write a whole heap of code, initializing primary and secondary surfaces, ZBuffer, the acutal D3D object, and the code to actually find a 3D device and...

With OpenGl its like 3 lines. eg all you have to do for ZBuffer to work is : glEnable (DEPTH_TEST)

Don''t get me wrong. I have used D3D more than I have used OpenGL. I find it that D3D gives you more control over little things and details of rendering. But when it comes to simplicity OpenGL is yet to be beaten.

I found this to be the same with OpenAL and DirectSound. It took me like an hour to figure what the main parts of OpenAL are and to write a decent 3D sound class. With DirectSound....Errr..I don''t think so...


Again these are my personal opinions

Share this post


Link to post
Share on other sites
quote:
Original post by Possibility
Jesus, its so sad to see the poor OpenGL users stating the only reason to use opengl is portability to mac and linux. My god (yes I am praying for you) get a life, how many of you on this forum own a mac,linux box and a windows pc and are actually gonna port your own little projects and experiments to them? And how many of you have actually done it already?


I''m running Linux, and my engine runs just fine in it as well as Windows, thank you. Get a life? You''re the one senselessly bashing an API, it isn''t even something someone forces you to use, how can you go out of your way to insult it? Have I used DirectGraphics? Yes, I didn''t like it more than OpenGL, so I use what I like and what works better for my porting.

[Resist Windows XP''s Invasive Production Activation Technology!]

Share this post


Link to post
Share on other sites
quote:
Original post by Poya
I won't disagree

OPENGL IS SO MUCH EASIER TO USE. Especially when it comes to initializing stuff and getting down to actual business. With direct3D (and I'm talking about DX 7, I haven't really worked with 8) you have to write a whole heap of code, initializing primary and secondary surfaces, ZBuffer, the acutal D3D object, and the code to actually find a 3D device and...

With OpenGl its like 3 lines. eg all you have to do for ZBuffer to work is : glEnable (DEPTH_TEST)




I know its your opinion, so im not bashing you here.

quote:

OPENGL IS SO MUCH EASIER TO USE.



What you should have said is that GL is so much easier to use than DX7. I have coded for both OpenGL and DirectX 8. DirectX 8 is about equal in simplicity as OpenGL.


quote:

With OpenGl its like 3 lines.



With DirectX 8 the init code actually also 3 lines. One to create the device, one to get the adapter properties, and one to create your device.


I have an OpenGL engine and a DirectX engine. In the init code, both do the bare basics (opening window, init the API, show the window) and both's init code is about equal in length and complexity.

quote:

all you have to do for ZBuffer to work is : glEnable (DEPTH_TEST)



all you have to do for DX ZBuffer is:

D3DDevice->SetRenderState(D3DRS_ZENABLE, true);


What im getting at is the the two API's are just the same in simplicity. There should be no argument in that because I have coded both and know both and know that they are equal in simplicity. Even if GL was more simple than DX, if you can't understand DX, you shouldn't be learning to use ANY 3D API. You should be learning C and/or basic math.

There is also no argument that one API is more/better documented than another. DirectX is FULLY documented by the SDK that comes with it. You shouldn't need any more documentation than that. OpenGL is fully documented at MSDN, and then the chipset specific functions are documented by the chipset company. Both are fully documented and I have had no problems with each finding sufficient information. Nobody else should. If they have had problems, then they should try actually LOOKING for information first rather than complaining about it.


The issue about portibility is also not an issue either. Where GL is portable to Linux, Mac and BeOS, and DX is not, DX is portable to the XBox, where GL is not. I would think that there are going to be alot more games made for the XBox than alternative OS's. So if anything, DX is more portable. However they have the same amount of portability in my eyes.


I said before, the only differences between the 2 API's is that DX has more utility functions than GL, and GL has more functions for 3D modelling programs.


quote:

D3D:
Cons - Windows only, requires a 45meg download to use, doesnt support some hardware features

Pros - Lots of hardware support for it, lots of software uses it, more tightly integrated into Windows.


OGL:
Cons - Some driver vendors have very nasty drivers, not as tightly integrated into the OS

Pros - Most hardware supports it, supports new hardware features through extensions, no big download required to use.



Who cares about download time???
That is so irrelevant to the functionality of the API that it shouldn't have even be said.

DX supports all relevant features provided by the card needed for games. With the introduction of High-Order primitives, it even does NURBS now. Correct me if im wrong, but if anything, GL doesn't support some hardware features seeing how it doesn't even do Vertex and Pixel shaders, which are in my opinion, the biggest advancement in ANY API i've ever seen in my life.

Edited by - Psionic on September 27, 2001 1:06:51 PM

Share this post


Link to post
Share on other sites
EXCELLENT - We''ve finally broken down into an argument. Here''s my two cents (coming from alot of experience with both):

1. Portability - if you need to run on multiple platforms, great, use OpenGL. If you only have a windows machine and are not realistically going to use another, great, use either because portability falls out of the equation.

2. Hardware compatibility - Like it or not, DX is better. People may accuse MS of flexing too much muscle, but it pays off if it forces hardware vendors to conform to a spec. My SGI doesn''t support many of the basic SGI_ opengl extensions. strange... But again, if you are only developing on your own machine this falls out of the equation as well...

3. Ease of use. For the completely new person, I''d point to OpenGL. In fact, I keep pointing out that the red book is a great resource for the basic concepts. For experienced programmers, I''d say it''s a close race between OpenGL and DX8.

4. New features - I''d say DX8, but not by much. The nice thing about DX8 is that it has direct access to new DX8 features (shaders), and OpenGL only has access through extensions, giving DX8 the slight upper hand. However, there are exceptions to this. For instance, the GF3 supports shadow buffers, but DX8 doesn''t have any notion of them. There is however, an nVidia OpenGL extension for shadow buffers, so this is a case where OpenGL wins on a new feature.

5. Resources - there are good resources for each. Many of the questions I see here could have been answered by reading either SDK docs or a handful of good, easy to find sites. You may have to spend 5 minutes at a search engine, but that''s to be expected...

Things that don''t matter:
1. "I hate MS" - this isn''t a particularly valid technical reason...
2. Download time - unless you measure your total development time in hours or minutes, this doesn''t matter.
3. Lines of code - You can write bloated DX8 code and you can write bloated OpenGL code. Writing "Hello World" in assembly takes more lines of code than writing it in C. Is the assembly code version better or worse? Perhaps it''s better, depending on your restrictions. Bottom line is that this isn''t a good metric.
4. Speed - both are pretty much the same, depending on how you use them.

blah, blah, blah... The bottom line is that neither is a bad choice. My personal opinion is that OpenGL is better for beginners, DX8 may be better for experienced people. If you learn OpenGL, switching to DX8 is incredibly easy and vice versa. Learn a little about each and choose what you like best. Switch later if you change your mind. Most of the arguments above either don''t make sense or are people arguing about differences in *opinion*.

Share this post


Link to post
Share on other sites
Actually, D3D is alot harder to learn than OpenGL. And, if SDL was better documented, DInput and DSound would be harder to learn. If HawkNL was better documented, DPlay would be out of the picture ( though, theres always WinSoc so that may not be true ).

Besides the fact that there are tons of books on Direct 3D, OpenGL is easier to learn, the functions make more sense, the initialization takes less than 20 seconds, and its alot less messy..

This whole thing is going to bring out a flame war, wheres the moderator?

Share this post


Link to post
Share on other sites
quote:
Original post by PSioNiC
DX supports all relevant features provided by the card needed for games. With the introduction of High-Order primitives, it even does NURBS now. Correct me if im wrong, but if anything, GL doesn''t support some hardware features seeing how it doesn''t even do Vertex and Pixel shaders, which are in my opinion, the biggest advancement in ANY API i''ve ever seen in my life.


OpenGL does NURBS (gluNurbs___) as well as supports Vertex and Pixel shaders (through extensions for now, since NVidia and ATI had disagreements over the method of using them. ATI may use NVidia''s method in the future. OpenGL 2.0 is expected to have standard support for them).

[Resist Windows XP''s Invasive Production Activation Technology!]

Share this post


Link to post
Share on other sites
>> GL doesn''t support some hardware features seeing how it doesn''t even do Vertex and Pixel shaders, which are in my opinion, the biggest advancement in ANY API i''ve ever seen in my life <<

aye? no only can u do pixel+vertex shaders in opengl but u had access to pixel + vertex shaders in opengl before d3d. what have u been smoking

Share this post


Link to post
Share on other sites

  • Advertisement
  • Advertisement
  • Popular Tags

  • Advertisement
  • Popular Now

  • Similar Content

    • By QQemka
      Hello. I am coding a small thingy in my spare time. All i want to achieve is to load a heightmap (as the lowest possible walking terrain), some static meshes (elements of the environment) and a dynamic character (meaning i can move, collide with heightmap/static meshes and hold a varying item in a hand ). Got a bunch of questions, or rather problems i can't find solution to myself. Nearly all are deal with graphics/gpu, not the coding part. My c++ is on high enough level.
      Let's go:
      Heightmap - i obviously want it to be textured, size is hardcoded to 256x256 squares. I can't have one huge texture stretched over entire terrain cause every pixel would be enormous. Thats why i decided to use 2 specified textures. First will be a tileset consisting of 16 square tiles (u v range from 0 to 0.25 for first tile and so on) and second a 256x256 buffer with 0-15 value representing index of the tile from tileset for every heigtmap square. Problem is, how do i blend the edges nicely and make some computationally cheap changes so its not obvious there are only 16 tiles? Is it possible to generate such terrain with some existing program?
      Collisions - i want to use bounding sphere and aabb. But should i store them for a model or entity instance? Meaning i have 20 same trees spawned using the same tree model, but every entity got its own transformation (position, scale etc). Storing collision component per instance grats faster access + is precalculated and transformed (takes additional memory, but who cares?), so i stick with this, right? What should i do if object is dynamically rotated? The aabb is no longer aligned and calculating per vertex min/max everytime object rotates/scales is pretty expensive, right?
      Drawing aabb - problem similar to above (storing aabb data per instance or model). This time in my opinion per model is enough since every instance also does not have own vertex buffer but uses the shared one (so 20 trees share reference to one tree model). So rendering aabb is about taking the model's aabb, transforming with instance matrix and voila. What about aabb vertex buffer (this is more of a cosmetic question, just curious, bumped onto it in time of writing this). Is it better to make it as 8 points and index buffer (12 lines), or only 2 vertices with min/max x/y/z and having the shaders dynamically generate 6 other vertices and draw the box? Or maybe there should be just ONE 1x1x1 cube box template moved/scaled per entity?
      What if one model got a diffuse texture and a normal map, and other has only diffuse? Should i pass some bool flag to shader with that info, or just assume that my game supports only diffuse maps without fancy stuff?
      There were several more but i forgot/solved them at time of writing
      Thanks in advance
    • By RenanRR
      Hi All,
      I'm reading the tutorials from learnOpengl site (nice site) and I'm having a question on the camera (https://learnopengl.com/Getting-started/Camera).
      I always saw the camera being manipulated with the lookat, but in tutorial I saw the camera being changed through the MVP arrays, which do not seem to be camera, but rather the scene that changes:
      Vertex Shader:
      #version 330 core layout (location = 0) in vec3 aPos; layout (location = 1) in vec2 aTexCoord; out vec2 TexCoord; uniform mat4 model; uniform mat4 view; uniform mat4 projection; void main() { gl_Position = projection * view * model * vec4(aPos, 1.0f); TexCoord = vec2(aTexCoord.x, aTexCoord.y); } then, the matrix manipulated:
      ..... glm::mat4 projection = glm::perspective(glm::radians(fov), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f); ourShader.setMat4("projection", projection); .... glm::mat4 view = glm::lookAt(cameraPos, cameraPos + cameraFront, cameraUp); ourShader.setMat4("view", view); .... model = glm::rotate(model, glm::radians(angle), glm::vec3(1.0f, 0.3f, 0.5f)); ourShader.setMat4("model", model);  
      So, some doubts:
      - Why use it like that?
      - Is it okay to manipulate the camera that way?
      -in this way, are not the vertex's positions that changes instead of the camera?
      - I need to pass MVP to all shaders of object in my scenes ?
       
      What it seems, is that the camera stands still and the scenery that changes...
      it's right?
       
       
      Thank you
       
    • By dpadam450
      Sampling a floating point texture where the alpha channel holds 4-bytes of packed data into the float. I don't know how to cast the raw memory to treat it as an integer so I can perform bit-shifting operations.

      int rgbValue = int(textureSample.w);//4 bytes of data packed as color
      // algorithm might not be correct and endianness might need switching.
      vec3 extractedData = vec3(  rgbValue & 0xFF000000,  (rgbValue << 8) & 0xFF000000, (rgbValue << 16) & 0xFF000000);
      extractedData /= 255.0f;
    • By Devashish Khandelwal
      While writing a simple renderer using OpenGL, I faced an issue with the glGetUniformLocation function. For some reason, the location is coming to be -1.
      Anyone has any idea .. what should I do?
    • By Andrey OGL_D3D
      Hi all!
      I try to use the Sun shafts effects via post process in my 3DEngine, but i have some artefacts on final image(Please see attached images).
      The effect contains the following passes:
      1) Depth scene pass;
      2) "Shafts pass" Using DepthPass Texture + RGBA BackBuffer texture.
      3) Shafts pass texture +  RGBA BackBuffer texture.
      Shafts shader for 2 pass:
      // uniform sampler2D FullSampler; // RGBA Back Buffer uniform sampler2D DepthSampler; varying vec2 tex; #ifndef saturate float saturate(float val) {     return clamp(val, 0.0, 1.0); } #endif void main(void) {     vec2 uv = tex;     float sceneDepth = texture2D(DepthSampler, uv.xy).r;     vec4  scene        = texture2D(FullSampler, tex);     float fShaftsMask     = (1.0 - sceneDepth);     gl_FragColor = vec4( scene.xyz * saturate(sceneDepth), fShaftsMask ); } final shader:
      // uniform sampler2D FullSampler; // RGBA Back Buffer uniform sampler2D BlurSampler; // shafts sampler varying vec4 Sun_pos; const vec4    ShaftParams = vec4(0.1,2.0,0.1,2.0); varying vec2 Tex_UV; #ifndef saturate  float saturate(float val) {     return clamp(val, 0.0, 1.0); } #endif vec4 blendSoftLight(vec4 a, vec4 b) {   vec4 c = 2.0 * a * b + a * a * (1.0 - 2.0 * b);   vec4 d = sqrt(a) * (2.0 * b - 1.0) + 2.0 * a * (1.0 - b);       // TODO: To look in Crysis what it the shit???   //return ( b < 0.5 )? c : d;   return any(lessThan(b, vec4(0.5,0.5,0.5,0.5)))? c : d; } void main(void) {     vec4 sun_pos = Sun_pos;     vec2    sunPosProj = sun_pos.xy;     //float    sign = sun_pos.w;     float    sign = 1.0;     vec2    sunVec = sunPosProj.xy - (Tex_UV.xy - vec2(0.5, 0.5));     float    sunDist = saturate(sign) * saturate( 1.0 - saturate(length(sunVec) * ShaftParams.y ));     sunVec *= ShaftParams.x * sign;     vec4 accum;     vec2 tc = Tex_UV.xy;     tc += sunVec;     accum = texture2D(BlurSampler, tc);     tc += sunVec;     accum += texture2D(BlurSampler, tc) * 0.875;     tc += sunVec;     accum += texture2D(BlurSampler, tc) * 0.75;     tc += sunVec;     accum += texture2D(BlurSampler, tc) * 0.625;     tc += sunVec;     accum += texture2D(BlurSampler, tc) * 0.5;     tc += sunVec;     accum += texture2D(BlurSampler, tc) * 0.375;     tc += sunVec;     accum += texture2D(BlurSampler, tc) * 0.25;     tc += sunVec;     accum += texture2D(BlurSampler, tc) * 0.125;     accum  *= 0.25 * vec4(sunDist, sunDist, sunDist, 1.0);           accum.w += 1.0 - saturate(saturate(sign * 0.1 + 0.9));     vec4    cScreen = texture2D(FullSampler, Tex_UV.xy);           vec4    cSunShafts = accum;     float fShaftsMask = saturate(1.00001 - cSunShafts.w) * ShaftParams.z * 2.0;              float fBlend = cSunShafts.w;     vec4 sunColor = vec4(0.9, 0.8, 0.6, 1.0);     accum =  cScreen + cSunShafts.xyzz * ShaftParams.w * sunColor * (1.0 - cScreen);     accum = blendSoftLight(accum, sunColor * fShaftsMask * 0.5 + 0.5);     gl_FragColor = accum; } Demo project:
      Demo Project
      Shaders for postprocess Shaders/SunShaft/
      What i do wrong ?
      Thanks!
       


  • Advertisement