Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / [STICKY] Learning to write Shaders

Author
Message
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 26th Jul 2007 01:17
Quote: "btw, do you know if it's possible to do Motion Blur in DBP? Like in Offset engine? "


I'd use a shader - but there may be a way using purely DBP commands.

If you want to use a shader you could Try doing it yourself. Start with a simple shader which just renders an object in the usual way and then have several passes which offset the object slightly in the right direction. You might be able to just have a vertex shader and rely on the standard pipeline to do the pixel rendering (with some alpha render states set). I'm guessing - but it would be nice to see someone else experimenting with this stuff.

Some of us will try to help - but you'll learn more by trying yourself.
Try
19
Years of Service
User Offline
Joined: 16th Aug 2004
Location:
Posted: 26th Jul 2007 10:20 Edited at: 26th Jul 2007 13:47
Green Gandalf,

Quote: "I'd use a shader - but there may be a way using purely DBP commands."

Doing this in DBP is fairly easy and I know how to do it, but it will be more like a 'Motion Trail' that way not a real Pixel Based 'Motion Blur'.

Quote: "If you want to use a shader you could Try doing it yourself"

Yeah, you're right. I'll see what I can do!

Quote: "Some of us will try to help - but you'll learn more by trying yourself."

It's good to know there are always some people to help

[EDIT 1]
OK, here's a little code I found! (From DirectX SDK)
It is a pixel based motion blur effect: (PixelMotionBlur.fx form SDK)



Now, shall I work on something like this (Pre-made) and try to tweak it for DBP or I better work on my own from scratch? (by learning shader programming first!)

[Edit 2]
I tried using this effect by setting the technique in DBP (I'd rather the 'post process' one) and using the quad.fx for full-screen stuff... but no luck!

Now, should I use FXComposer or something like that (perhaps a compiler?)
Any ideas/suggestions? (Debugging advices, tricks, etc.)
(Because I don't see anything on the screen! Now where to go from here?)

[Edit 3]
OK, the shader is using shader model 2.
My goal is to use the PostProcessMotionBlur technique so I guess I can delete other stuff from there for the sake of simplicity! I'll post the result later.

Cheers,
-Try
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 27th Jul 2007 01:49
That's quite a difficult shader to start with if you're new to HLSL and I have a feeling you can't easily adapt it for DBP because it uses multiple render targets. But you can mimic this by using set camera to image, etc, and doing the rendering in two or three stages.

When I'm debugging shaders I usually use Dark Shader and FX Composer. These are particularly useful for identifying coding syntax errors and give you some idea of what the effect will look like. Dark Shader is specifically designed for use with DBP and has some nice examples as well as offering extended shader support for DBP. FX Composer is free and has some handy features such as procedural texture support (which isn't supported by DBP).

But some shaders can only be easily debugged by trying them with DBP - this particularly applies to full-screen shaders.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 27th Jul 2007 01:54 Edited at: 27th Jul 2007 02:42
Here's another lava style shader. It starts with a very crude and basic "lava" image then processes it with a shader combined with a fractal "noise" texture. The final result looks reasonably realistic despite the crude initial texture.

You can obviously try different images instead of the "lava base.PNG" image to get different effects. By changing the colours you could get a simple water effect, for example.

Edit

Out of curiousity I took a screenshot of a forum page and used that instead of "lava base.PNG". Looked a bit like water with an oily film on it. Plenty of room for experimentation.

Attachments

Login to view attachments
Try
19
Years of Service
User Offline
Joined: 16th Aug 2004
Location:
Posted: 28th Jul 2007 08:09
Green Gandalf,
You're right GG, that one was pretty difficult for me to implement. I learned a few things when I was trying to port/use it in DBP, I'll take your advice, I'll start learning shader programming very slowly and carefully.

Thank you very much GG. But if you got any time or you simply got bored, then have a go for it. I'll be more that happy to see some MRT-Motion Blur stuff in DBP

Cheers,
Try
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 28th Jul 2007 12:35
Quote: "But if you got any time or you simply got bored"


Very unlikely on this forum.

I'll see what I can come up with - but probably not this weekend.

[By the way, I don't think my earlier suggestion would look right. That shader you posted is probably the way to go - but will need some work. I've seen one like that somewhere, but as I say, it'll probably be later in the week before I get to it. ]
Jeff Miller
19
Years of Service
User Offline
Joined: 22nd Mar 2005
Location: New Jersey, USA
Posted: 28th Jul 2007 17:07
I need advice on shader capabilities (that DBP will handle) before I take a plunge into studying shader language. I have only one project and it contains only one problematic object.

1. Many of the shaders discussed in this thread tend to add pixels to the rendering, such as glow, blur, etc. I am initially looking for a means to achieve the opposite. In a skysphere whose texture shows 9000 stars in their correct relative position - one texel per star - I initially need to ensure that one and only one pixel is rendered for each particular texel. There will always be distortion in projecting a spherical surface onto a monitor, and I can live with the positional distortion that increases with the distance of a texel from the center of the screen, but I want to eliminate the system's tendency to increase the number of pixels rendered for a texel as its position increases from the center of the screen. (The camera position is naturally at the center of the sphere.)

2. If I can achieve that, the next question is probably more conventional because it involves adding pixels. I construct the texture in a memblock, from astronomical data I've downloaded and massaged, so that the texel position correctly maps to the star's position, and the alpha value corresponds to the visual magnitude of the star. Can that value be used to trigger a rendering of that texel in an particular enlarged pixel pattern centered at the position that the single pixel would take? If so, could several values be used to trigger several corresponding pixel patterns?

Thanks in advance for any advice you may have. I've tried a few conventional methods to achieve what I want but they have not proved successful.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 28th Jul 2007 19:10 Edited at: 28th Jul 2007 20:00
Quote: "I initially need to ensure that one and only one pixel is rendered for each particular texel"


Interesting question - and I am not sure that it can be done easily. My reason for saying that is that it is unlikely that the texture texels will exactly correspond to the screen pixels. Suppose you were using a cube map as your texture, consisting of, say, 6 512x512 images. If your screen resolution is 1024x768 there is obviously going to be a mismatch - and that's without the complications of spherical distortion.

I suspect that what you really need to do is to turn off some of the linear filtering that is usually standard in a shader (filtering is a form of blurring which may or may not be desirable in different applications). For example, when you sample from the skysphere texture the shader code might look like this:



You may get an effect close to what you want by using "POINT" instead of "LINEAR" in the filtering settings - and you could try turning one or two off using "NONE". By specifying "POINT" you are telling the shader to use the nearest texel rather than an average of neighbouring texels. This may be exactly what you want so you see the stars in crystal clarity. Worth a try anyway. It should be quite easy to put together a demo and see how it looks.

Quote: "Can that value be used to trigger a rendering of that texel in an particular enlarged pixel pattern centered at the position that the single pixel would take? If so, could several values be used to trigger several corresponding pixel patterns?"


Another interesting, and more difficult, question. My immediate reaction is "no". As you suggest, it usually works the other way round. You could for example store additional info in the alpha component or, if you knew the stars would all be white, in the green and blue components as well. This would allow you to modify the rendering of a particular pixel - and you could look up neighbouring texels according to those values as well. But that is essentially the blurring procedure you were talking about. As you say, you want the reverse. There may be a neat way of doing what you want, but it escapes me for the moment. The only ways that spring to mind involve lots of texture look-ups - e.g. for a given pixel you could scan neighbouring pixels to see if the current pixel would be affected by the "pixel patterns" triggered by the neighbours. Messy, but possible. (And the FPS would probably drop through the floor.)

Just one caveat to this. My experience is with VS2 and PS2 and below, VS3 and PS3 support many more features and might make this task much easier. For example, I understand that VS3 allows some sort of texture look-up. If this allows you to specify the pixel's position according to the value found in a texture texel then you might be home and dry. But I'm guessing.

Edit

And here's a simple demo to illustrate what I mean about the filtering. Move the camera with the mouse, and choose LINEAR or POINT filtering by pressing "1" or "2" respectively.

Attachments

Login to view attachments
Jeff Miller
19
Years of Service
User Offline
Joined: 22nd Mar 2005
Location: New Jersey, USA
Posted: 28th Jul 2007 20:35
Thank you very much for your interesting insights. This provides me with quite a bit to think over.

Regarding the use of RBG values to convey additional info, I didn't mention it in my question but I use them for, well, RGB. Since stars have colors, although only the brighter ones put out sufficient light to trigger the rods/cones and whathaveyou on your retina to trigger a color perception, I was converting temperature info into RGB through some empirical formulae some astronomers have developed.

Regarding storing additional info in the alpha component, I know methods in the abstract of carrying more than one piece of info in a single byte, but I have to think over some of the limitations.

Regarding the use of neighboring texels to convey info on the texel they neighbor for use in generating a centered pixel pattern, I might run out of space between texels. The 9000 visible stars are positionally distributed such that quite a few directly adjoin each other at, say, a 2048x2048 pixel texture, and because of the way the UV map is set up for a sphere it gets damn crowded near the poles. Since the perception of two stars so close together is generally that of a single brighter star, I would edit the texture to eliminate adjoining texels in favor of a single texel and then crank up the visual magnitude info accordingly, which I was planning as the alpha value. I'm going to try 4096x4096 to see where it gets me. Although the sphere has to rotate (to elevate the pole to the user's latitude, and to rotate it on its local axis to correspond to the time/date of the view), it does not have to smoothly rotate over a series of syncs, like an animation, so I have more processing time to play with.

However, in re-reading the many pages of this thread, an alternative to the three topics above comes to mind because you have explained in the thread that shaders can apparently take several textures for the same object. Could I use the first texture for the RGB and alpha, and then use a second texture to impart neighboring-texel type info to be used to create a pixel pattern? I could easily sacrifice most of the stars in the second texture to create a spacial buffer between the brighter ones for the multi-pixel pattern add-on since only perhaps 10% of them might merit a pixel pattern. If I can do that, could the shader render all the fainter stars in the first texture based upon their presence there even if they didn't happen to appear in the second texture?

Regarding your idea about employing info in the texel to specify pixel position by a lookup value, I'm not yet able to grasp it. I'm conceiving pixel position as dependent upon the orientation of the textured object and the FOV, and nothing else.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 28th Jul 2007 21:47
Quote: "Could I use the first texture for the RGB and alpha, and then use a second texture to impart neighboring-texel type info to be used to create a pixel pattern?"


Yes. And you could use several textures. In the shader you can combine the textures in many different ways limited only by your imagination and the, quite strict, instruction count limits of the pixel shader. (I try to do everything within about 15 instructions because my machine is slow.)

Generally, the more of the scene's rendering you can "pre-bake" into textures the better. I don't know what sort of pixel patterns you have in mind, but if you have a fixed pattern that you want to fade in and out according to, say, atmospheric conditions, you can just blend it with the main texture with a parameter controlling the blending. You could probably use the set blend mapping on commands rather than a shader - but I find shaders easier because you have more control over the precise way the blending is done.

Quote: "If I can do that, could the shader render all the fainter stars in the first texture based upon their presence there even if they didn't happen to appear in the second texture?"


Yes. You just decide how you want to combine them per pixel. For example, suppose you have two textures sampled by "mainSample" and "patternSample" and an additional float blending parameter "blend". Then pixel shader to look up and combine these might contain:



That would give you simple linear interpolation between the mainColour and patternColour.

Alternatively, you might want to add the second colour modified by "blend":



Many other variations are possible, including doing different things with each colour component.

Quote: "and because of the way the UV map is set up for a sphere it gets damn crowded near the poles."


You can avoid that by having a carefully constructed cube map (unlike my demo cube map). You would then look-up the cube map using the object's normal as in my demo rather than the conventional sphere UV's which look dreadful near the poles.

I don't know what your source star data consists of, but if it's in the form of longitude, latitude, size, etc, then you could run a simple dbp program to place 9000 "star" objects in the correct positions around a hypothetical sphere. Then place a camera at the centre of the sphere and take 6 "photos" of the sky (set camera to image, etc). Then save the images and combine them into a single cube map. That way you might be able to eliminate, or considerably reduce, the distortion that standard sphere UV coords produce.

Quote: "Although the sphere has to rotate (to elevate the pole to the user's latitude, and to rotate it on its local axis to correspond to the time/date of the view), it does not have to smoothly rotate over a series of syncs, like an animation, so I have more processing time to play with."


That could be useful.

Quote: "Regarding your idea about employing info in the texel to specify pixel position by a lookup value, I'm not yet able to grasp it."


Neither can I yet - I just mentioned that as a possibility (I haven't studied VS3/PS3 yet so I don't know what can be done).
Jeff Miller
19
Years of Service
User Offline
Joined: 22nd Mar 2005
Location: New Jersey, USA
Posted: 28th Jul 2007 23:14
Thanks for your input. This is making my mind spin. I admire the way you explore multiple avenues of solution opportunities.

Regarding star position data, it is in the form of 2 spherical coordinates (radius is considered infinite, thus a constant) of "declination" (angle analogous to latidude but measured from the celestial equator, which is a projection into space of the terrestial equator) and "right ascension" (analogous to longitude, but measured in 'hours' each equal to 15 degrees arc, and measured from the intersection of the celestial equator and the ecliptic at point of the vernal equinox). These are easily positioned on a cube or a known UV map of a sphere with simple geometry.

I will give your cube recommendation a try. I'm a bit nervous because while it will necessarily reduce crowding near the two poles it will also necessarily increase crowding near the four intersecting cube edges perpendicular to the equator.

Incidentally, I'm not sure what the "conventional" UV map for a sphere is. I've only wrestled with the mapping of two types so far, and they are different at the poles. The DBP "MAKE OBJECT SPHERE" constuction command seems to produce a map where the polar section is composed of right triangles. I am getting my spheres out of Lithunwrap, which spits out a UV map with the polar regions cast as isosceles triangles (easier to plot stars on and slight reduction in distortion). As an aside, the DBP sphere also contains duplicate triangles and degenerate triangles, if you snoop at them in a memblock. The Lithunwrap sphere does not.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 29th Jul 2007 00:07
Quote: "it will also necessarily increase crowding near the four intersecting cube edges perpendicular to the equator"


I'm not sure that's true. It should be easy to check by using a uniform random distribution of points over a sphere - no wonder I don't get any gardening done.

[Hmm. You might be right. In the past I've made two normal cube maps using that idea. I'm sure the first was seamless without distortion. I then had a reason to make another using the same method and it was distorted. Perhaps I improved the code ...? ]

Quote: "These are easily positioned on a cube or a known UV map of a sphere with simple geometry."


In which case, why do you get the crowding near the poles?

Quote: "I'm not sure what the "conventional" UV map for a sphere is"


Neither am I. I actually meant the DBP UV map for spheres.

Quote: "As an aside, the DBP sphere also contains duplicate triangles and degenerate triangles, if you snoop at them in a memblock."


Yes, I've noticed that too. I've been told there's a good reason for it - but I don't believe it.

I'm now torn between playing a game and investigating the "crowding" issue. Perhaps it'll be raining tomorrow so I'll have another reason not to do the gardening ...
Jeff Miller
19
Years of Service
User Offline
Joined: 22nd Mar 2005
Location: New Jersey, USA
Posted: 29th Jul 2007 00:23
Play the game instead of investigating the crowding issue. Trust me on this, it is indigenous to projecting a spherical surface onto a plane, and the problem has persisted through heavyweights starting probably with Ptolemy up through Mercator and beyond. Squash it here and it bulges there. More polyhedrons less distortion. Only thing worse than a cube is a tetrahedron.

Why I get crowding near the poles is that I can't plot a texel in less space on a texture image than a pixel. In either a DBP or a Lithunwrap map the pixel alternatives as you approach the poles approach to zero. That gets crowded.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 29th Jul 2007 01:13 Edited at: 29th Jul 2007 13:37
Sorry - but I think you're wrong. Use the attached cube map in place of the earlier one and see if you can tell me where the "poles" are once you've moved the camera.

The whole point of my method is that you take "photos" of the scene within DBP so everything is in the right place.

I suppose you'd like to know how I created the cube map as well?

[I agree the pixels get distorted a bit - but the stars should be in the right place so no crowding occurs. Well, see what you think.]

Edit

Jeff

It should be very easy to use simple geometry to construct the 6 cube map images without the object creation step I was referring to earlier (although that is a little bit easier to implement correctly in DBP). What I think you need is the 3D version of the following 2D idea.

1. Draw a circle of radius 1 unit (this represents the skysphere).
2. Draw a square with same centre as the circle (size doesn't matter - but make it commensurate with the circle.
3. Mark the centre O of the circle (the viewer).
4. Choose an arbitrary point P (a star) on the circle 's circumference.
5. Draw a line from O through P and mark where it intersects the square Q.
6. Think of the side of the square as representing your flat image and put a dot on the image at position Q.

You should see that there is no "crowding" at the corners, the opposite if anything, and you should get nice images for constructing the cube map.

There is absolutely no need to use the UV coords of the skysphere - the shader just uses the direction of a point on the sphere (as measured from its centre) to look up the cube map and everything will be in the right place (if you've got your cube map images the right way round . [I used the object's normal rather than position - but it's the same idea.]

Attachments

Login to view attachments
Jeff Miller
19
Years of Service
User Offline
Joined: 22nd Mar 2005
Location: New Jersey, USA
Posted: 29th Jul 2007 15:15
Your are right, the distortions compress at the center of the side cube faces, not the edges. I was incorrectly thinking of a consequence of my screen being very rectangular.

I'm not sure how you positioned the stars you are showing. If you randomly positioned them on the faces of the cube then one would expect no distortion, but when you position the actual stars and project the celestial grid on the inside of a cube the positional distortion is much more noticeable than you get from a more spherical polyhedron. I made such a cube a few months ago before moving up to more spherical polyhedrons, and the positional distortion hits home when you impose the celestial coordinate grid lines on the cube. Assume the equator to be the intersection of the cube faces with the X-Z plane. The the tropic of cancer then consists of 4 hyperbolas connecting to each other high on the side edges and each dipping down toward the equator as you approach the side centers. Using a larger segmented polyhedron, any declination grid still appears a bit segmented but approaches a smooth curve. E.g. I'm using a 72 segment (orange slice) sphere, so imagine how much smoother a curve of 72 slightly hyperbolic segments would appear as compared to 4 heavily hyperbolic segments. Similarly, when you impose hour lines on the cube they are purely vertical on the side faces then abruptly radiate to the centers of the top and bottom faces only beginning at the top and bottom edges.

The 3D extension of the 2D projection method you describe is called a gnomonic projection, and it is the only viable projection method for a project of this type. The "gnomon" is the viewer's eye. It's what I use to plot the stars on the texture map for the star sphere. It is how sundials work.

I actually didn't mean to suggest that my stars get crowded near the poles, but that the availability of neighboring texels gets crowded because they - well - are off the UV map area. That fear was based on an assumption that I am not really qualified to make. I assumed that the a shader could only consider the portion of the rectangular texture that falls within the UV map. Is that really so? If the shader can consider values in neighboring texels that don't happen to be on the UV map, the two-texture method looks even more promising.

However, I am going to first tackle the concept of stars as objects that you mentioned before, distributed over a hypothetical sphere. I hadn't been thinking along those lines at all. Now that you have suggested it, I want to see how much more flexibility I can get from objects rather than texels. For one thing, at any particular view I might be able to nudge them into a less distorted position. The math will be awful, but that's my long suit.

Thank you again for all of your advice and suggestions.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 29th Jul 2007 16:00
Quote: "I'm not sure how you positioned the stars you are showing. If you randomly positioned them on the faces of the cube then one would expect no distortion, but when you position the actual stars and project the celestial grid on the inside of a cube the positional distortion is much more noticeable than you get from a more spherical polyhedron"


I'm not sure why you think this.

I positioned the stars randomly over a sphere then took 6 "photos" using set camera to image. These were then converted into a cube map using "DxTex.exe" (one of the few MS SDK tools that I have found really useful). This, in effect, does the projection onto the cube - all the maths is done for you. When you use the shader to render the skysphere, the projection is just reversed and there is no positional distortion. That's my understanding of what's going on anyway.

One way to check this would be to place 9000 points, say, regularly over the sphere using some sort of regular spherical polyhedron and then look at the result of the the above procedure. A less satisfactory alternative (and easier to try off the top of my head) would be to place points uniformly around several "great circles". This will naturally result in "crowding" near the poles - but should reveal any distortions caused by the cube map. In fact I'll try that now. If you can suggest a simple method of generating coords for the vertices of a regular spherical polyhedron I'll try that as well.

Quote: "I assumed that the a shader could only consider the portion of the rectangular texture that falls within the UV map. Is that really so? If the shader can consider values in neighboring texels that don't happen to be on the UV map, the two-texture method looks even more promising."


No. This particular shader doesn't use the UV coords at all.
Chris K
20
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 29th Jul 2007 16:01
Just had an idea for a little challenge I am going to try and make, a shader that textures an object with text.

Like, you literally give it the raw text "Hello World" and the text size, font and start position in UV space, and it writes it onto the object.

The advantage of this would be it could be smooth whatever level you zoom it to. It would also barely take up any space, only a few Kbs. A model of a DVD case could have all the correct text on the back.

Useless but fun!

No idea how I'm going to achieve it, and will probably need some to-and-fro between the CPU and GPU, but I'll give it a go eh

-= Out here in the fields, I fight for my meals =-
Chris K
20
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 29th Jul 2007 16:03 Edited at: 29th Jul 2007 17:10
The reason the cube map can look as good as a sphere map is because it assumes you are at the centre of the cube.

------------------

Updated first post in thread.

No more annoying questions on what the good books are mKay

-= Out here in the fields, I fight for my meals =-
Jeff Miller
19
Years of Service
User Offline
Joined: 22nd Mar 2005
Location: New Jersey, USA
Posted: 29th Jul 2007 17:10
GG - I misunderstood what you had done. I thought you dumped the stars on the cube sides then photographed them.

Your method of positioning stars on an actual geometric spherical surface does remove all distortions otherwise introduced by gnomonic projections positioning them on the surfaces of a polyhedron of any size. So the maps you made from the views of the sphere are indeed as good as you can get from the standpoint of positional distortion. I've plotted all 9000 stars as objects now in their correct position on the surface of a hypothetical geometric sphere. I think you have found me a winner on the distortion end, which was the first phase of what I was looking initially for, because after fiddling with the object size vs. radius of the sphere ratio they now appear to be coming it at one pixel per star, regardless of how far they are from the center of the screen. That is exactly what I needed. I will indeed use your cube map approach. Thanks a million!

For the second phase of my initial concerns - augmenting the pixel pattern of particularly bright stars, I'll start playing with the object sizes. The RGB of the particular stars will also probably work out OK by a color object command.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 29th Jul 2007 17:10 Edited at: 29th Jul 2007 17:12
Quote: "In fact I'll try that now."


Here's the resulting cube map image.

I can't see any distortion associated with the poles or corners of the cube map when you use this in the shader demo I posted earlier. There is some distortion around the edges of the screen - but that is independent of the orientation of the camera and/or sky sphere and is something to do with perspective I think.

There is some noticeable corruption of the image near the poles but that's a result of the image resolution I was using (512x512). If you're using 4096x4096 images you shouldn't have a problem (hmm? ... 6 4096x4096x24bit images is over 300Meg - perhaps you need lower resolution images?).

Edit

I see we posted at the same time. Looks like good news all round.

I look forward to the next instalment.

Attachments

Login to view attachments
Jeff Miller
19
Years of Service
User Offline
Joined: 22nd Mar 2005
Location: New Jersey, USA
Posted: 29th Jul 2007 17:27
I was only feeling pressure for a larger texture when contemplating making room for adjoining texel info. I don't think I'll need that now. I think I'll get by with much less.

The polar region on the dds you just posted does look suspicious. It is almost like what I would expect if some sections were missing. Is the camera FOV cranked up to 90?. According to Dimitri's Get FOV function it starts out in the 60's by default.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 29th Jul 2007 17:33
Quote: "It is almost like what I would expect if some sections were missing. Is the camera FOV cranked up to 90?."


I can't see anything wrong/missing. The latitude angles range from -87 to 87 degrees, so the poles themselves are missing and there are exactly 6 degrees between each star on each great circle. And yes the field of view is set at 90 - otherwise rather a lot of the sky would be missing (or replicated).

What do you think is missing?
Jeff Miller
19
Years of Service
User Offline
Joined: 22nd Mar 2005
Location: New Jersey, USA
Posted: 29th Jul 2007 17:44
Just a feeling. I'm going to try adding extra objects to mine to plot out gridlines (colored differently from the stars) and see how they look. I'll post something tomorrow - gotta split for the day. Thanks again for all your help.
The ARRAYinator
18
Years of Service
User Offline
Joined: 13th Aug 2005
Location:
Posted: 22nd Aug 2007 05:08 Edited at: 22nd Aug 2007 05:11
Hi this is my first time posting here. I am currently in need of writing a shader that can read the color values from the pixels on the screen and let the shader change them based on a specific algorithm. Im not very advanced yet in writing shaders yet although I do know quite a bit about how they work and how to make some simple ones. I was just wondering whats the most efficient way of doing this and if if statements can be used in a shader. Thanks!

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 23rd Aug 2007 01:50
Quote: "I am currently in need of writing a shader that can read the color values from the pixels on the screen "


A simple way is to set a camera to the screen image and texture a simple plain with that image. You can then process that texture any way you want (within reason) within the pixel shader. You will probably need to know how to set the plain up as a screen quad as well.

Quote: "and if if statements can be used in a shader"


Yes. Here's a typical example in a pixel shader from an example I posted recently:



If you need several statements to be executed you need to enclose them in {}, i.e.



Note that in HLSL you need to use the "==" operator rather than "=" if you want to test equality (I guess the reason is that "=" is used as the assignment operator which is a different operation from "=" used in testing equality - whereas DBP, and some other languages, use the same operator for both operations ).
The ARRAYinator
18
Years of Service
User Offline
Joined: 13th Aug 2005
Location:
Posted: 23rd Aug 2007 02:30
Thanks GG for the quick response. I havent dealt with a screen quad before but im assuming its similar to the plain in the bloom shader. I will get working on this and post back with my results. I actually have the effect hardcoded with the db pro 2d commands but unfortunately I get like between 1 and 5 fps in game so hopefully this will be much faster. Thanks!

Jna99
18
Years of Service
User Offline
Joined: 3rd Nov 2005
Location: Portugal
Posted: 27th Aug 2007 02:12
Hi guys I'm looking for a Hologram shader, so that textured object would look like in star wars, blue and shaky (like bad tv transmission). I've already opened a thread asking for ways to achieve this, but it would help if there was a shader. I've found the hologram shader in the ultimate shader thread but it has nothing to do to the effect I want.

Jna99
18
Years of Service
User Offline
Joined: 3rd Nov 2005
Location: Portugal
Posted: 27th Aug 2007 19:48
anyone?

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 27th Aug 2007 20:22
Jna99

Quote: "anyone?"


Patience please - we're not here at your beck and call you know.

Anyway, is the attached demo anything like what you want?

The demo starts with a simple striped sphere in a wooden box. If you press "t" you see a blue/shaky/fading wobble shader applied to the object.

You can move the camera around with the mouse and up/down keys.

Attachments

Login to view attachments
Jna99
18
Years of Service
User Offline
Joined: 3rd Nov 2005
Location: Portugal
Posted: 27th Aug 2007 21:17 Edited at: 27th Aug 2007 21:51
I'm sorry GG is only that in this thread I normally see quick answers to posts...and It has been almost a day since mine! I humbly ask your forgiveness.

EDIT: GG I very much like the effect but I can't find a decent config to that gives me the impression of an actual hologram

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 27th Aug 2007 23:25
Quote: "I humbly ask your forgiveness."


Granted.

Quote: "GG I very much like the effect but I can't find a decent config to that gives me the impression of an actual hologram"


Thanks - but neither can I - it was just a beginning, something to work on. I used that demo to test three separate things really: (1) a simple shaky/wobble effect; (2) a fading in and out to blue; and (3) a fading in and out to nothing. That effect used simple sinusoidal functions for all three which is probably not ideal - but that is a "mere detail" from the programming point of view. The real issue is what do you want the final result to look like?

Just to remind my tired old brain - were you thinking of things like the hologram message/plea for help from Princess Leia in Star Wars? If so, you have to remember that half of the effectiveness of the effect is the accompanying soundtrack.

To complete such an effect visually you would need to enclose it some sort of "display" or "box" and have an inner overhead light (if I recall correctly).

If they can do it - then so can DBP (with shaders possibly).
Jna99
18
Years of Service
User Offline
Joined: 3rd Nov 2005
Location: Portugal
Posted: 29th Aug 2007 14:37
Green Gandalf any updates about your holo shader? I've got a couple of suggestions, I believe that you should stop an object from being completelly blue, and it should always be visible so the alpha should have a minimun of 20.

Mike Inel
21
Years of Service
User Offline
Joined: 14th Feb 2003
Location: Sa upuan ko po...
Posted: 29th Aug 2007 17:38 Edited at: 29th Aug 2007 18:01
Hi,
Just want to thank everyone that i've finally managed to learn a bit in hlsl!
This is my first shader ever, so i'll share!
It's based from many other codes, especially from DarkShader's and Green Gandalf's...

It's a basic screen changing shader: Brightness, contrast, saturation, color overlay, and motionblur. Requires PS 2.0, and it's compatible with DarkShader. (It's specially made for my project... ^_^)

EDIT: Oh my, this shader makes a big difference in fps! From 600 to 200! Sigh...

Attachments

Login to view attachments
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 29th Aug 2007 19:47
Quote: "I've got a couple of suggestions"


Good. I've been waiting for those.

Will have a go later.

Quote: "This is my first shader ever, so i'll share!"


I'll have a look at that later as well.
TinTin
17
Years of Service
User Offline
Joined: 16th May 2006
Location: BORG Drone Ship - Being Assimilated near Roda Beta (28)
Posted: 30th Aug 2007 12:12
I've had a thought, and maybe were all looking at this from the wrong perspective.

Holograms are 3D images on a 2D surface although, I've seen some that are cylinders that when you walk around you get a full 360 projection (these were static).

I believe what (in the Princess Leia holo) were looking for can be achieved by using a second camera to look at an animated object, this cameras view point is tied to the player viewpoint (so as they move the other camera moves around the object). The output from this cammera sould then be modified...
First, seperate the colour chanels and reduce the contrast (leaving blue with most contrast), offset the chanel images slightly.
Next, use, like GG's a sine function to modify the alpha of the image to give between 60% and 90% patchiness.
Finaly, tear/warp the image in a few places to give the impression the image has lost sync.

paste this image onto a flat plane that always faces the player. and voila a nice hologram effect. Further information can be found in the dataslot of my trusty R2D2 drone...

Go Create...

Cyberspace was becoming overcrowded and slummy so I decided to move. These nice chaps gave me a lift.
Jna99
18
Years of Service
User Offline
Joined: 3rd Nov 2005
Location: Portugal
Posted: 30th Aug 2007 17:39
TinTin I've done it in photoshop (hue to 193, saturation to a little over the bar, gaussian blur to 1.0, give an outer glow and finally create a layer, fill it with a black & white stripes put it as softlight done!) , but I would like to make it in real time

Chris K
20
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 31st Aug 2007 15:13
There's a hologram shader in the Shader Pack, you just need to add some distortion to it...

-= Out here in the fields, I fight for my meals =-
Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 31st Aug 2007 15:16 Edited at: 31st Aug 2007 15:31
Actually you want a nice hologram effect, checkout the ATI R600 Physics Tech Demo (youtube has a copy of the video)... projects a real-time video feed to cubes that you can do crazy stuff with, like capture them in a tornado or throw balls at them; then have it smash apart.

I'll have a quick look and post back in a min > tada

Jna99
18
Years of Service
User Offline
Joined: 3rd Nov 2005
Location: Portugal
Posted: 31st Aug 2007 17:20
Chris K that hologram shader doesn't work on textured objects...

Chris K
20
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 31st Aug 2007 20:16
You can edit it so that it reads from a texture and fades the colour with the result from it's current pixel shader.

-= Out here in the fields, I fight for my meals =-
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 31st Aug 2007 22:00
Some of you may be interested in a new fog shader demo that I've just posted in the Ultimate Shader Pack thread in the WIP board:

http://forum.thegamecreators.com/?m=forum_view&t=79849&b=8&p=7

It's a completely re-worked version of an earlier demo and, among other things, illustrates one use of a projective texture lookup in the shader (tex2Dproj).

As usual it still needs a bit of work, so any comments would be welcome.
Jna99
18
Years of Service
User Offline
Joined: 3rd Nov 2005
Location: Portugal
Posted: 2nd Sep 2007 21:38
GG about the hologram I've found an After Effects Tutorial that explains how to achieve an hologram effect, here's the link , I saw the guide lines and it looks you're very close, just need to perfect what you've already done!

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 2nd Sep 2007 23:04
Jna99

Thanks for the link. I'll have a look later. It's about time I had another look at this project.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 6th Oct 2007 23:17
For those of you interested in bump mapping and its variants, one of the best references I've seen so far is:

http://www.delphi3d.net/articles/printarticle.php?article=bumpmapping.htm

It's by far the best discussion I've seen so far. Have fun.
Visigoth
19
Years of Service
User Offline
Joined: 8th Jan 2005
Location: Bakersfield, California
Posted: 10th Oct 2007 08:35
@gg
Question.
Is it possible to return a value from a shader? I was just thinking, I wrote a shader to vertex color my terrain, and it works alot better than the way I was doing it before, but the trouble is, it really hits the frame rate. Since shaders allow floating point color values, I can get alot more "steps" to my vertex colors. Once I color it, there really is no reason to continue running the shader. I tried applying the effect, then creating a mesh from it, but, no go, it just makes a mesh with the same values before the effect. I even tried a sync first, but still doesn't work. If I could get the shader to color the vertices at load time, then write it back to the object somehow, it should help the framerate. Also, I learned a little bit about directional lights. Turns out that the light 0 in DBPro is actually a directional light. Only, you can't reposition it. At least I can't figure out how. So, it is real easy to have a shader do the directional light instead, and it can be repositioned in real time, with really no hit on frame rates. It works great for simulating sunlight (sunrises, sunsets.).
anyway, just thinking out loud again.
Chris K
20
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 10th Oct 2007 17:29
Hmm.... I don't really understand the question... a Vertex Shader has to return a vertex position and a Pixel Shader has to return a colour...

Maybe a screenshot would help here? Are you just trying to colour the vertices of a terrain a constant colour? If so you should just do that in code before the loop, not with a shader.

-= Out here in the fields, I fight for my meals =-
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 10th Oct 2007 23:13
Quote: "a Vertex Shader has to return a vertex position and a Pixel Shader has to return a colour..."


The question is fine. A vertex shader can easily pass a color to the pixel shader - just as it can pass any other float4. If each vertex passes a different calculated colour to the pixel shader then the pixel shader can just pick up the interpolated colour from all three relevant vertices. You can get quite effective colouring of an object without using images that way.

However, some code would help us see what exactly has been done and what is proposed.

The only way that I know of for retrieving data from a shader (up to Shader Model 2 anyway) is via the pixels in a rendered image - as is often used for storing things like depth info for a full-screen shader. Perhaps that is what Visigoth has in mind? You'll be limited to the usual RGB 256 byte values of course - unless you do something complicated rendering two images of the same scene, i.e. one for the low 8 bits and another for the high 8 bits. I doubt it would be worth it though. I think EVOLVED's "deferred shading" demo did something like that.
Irradic
17
Years of Service
User Offline
Joined: 1st Jul 2006
Location:
Posted: 11th Oct 2007 02:45 Edited at: 11th Oct 2007 03:31
@Green Gandalf

Hi GG ! I remember that you were working on your own DOF Shader variant before Evolved came up with his Depth of Field Shader.
I know I requested the DOF shader during the NVIDIA competition but wasn't really able to implement it. The shader is a bit overkill and as said by you guys a pain in the a%$ to implement.
I've been trying since to create a simple background blur shader.
Something in which you just specify a distance value from which it would start to blur things. No advanced things like auto focus and stuff which is included in Evolveds shader.
Maybe you could help me out or have something I could work on ?
I would really appreciate it. Thanks

Edit:
Just tested Mike Inels Shader which can be found pretty much in the middle of this page (I attached it anyway). It does have motion blur but would it be possible to add distance blur to it ? The shader has some other quiet useful stuff in it.

Attachments

Login to view attachments
aXeon
16
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 11th Oct 2007 03:03
Green Gandalf,

Is there a reason why all my applications crash
when I use one of the shader-modify values commands?
Like: Set effect constant float / vector /etc..

The only shader that does work is Evolved's bloom shader at
this moment. Everything else just crashes.

That shader on page 1, 'JustOneColor' even crashes.
It's all the default windows crash.

- : aXeon Essentials : -
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 11th Oct 2007 14:03 Edited at: 11th Oct 2007 14:24
@Irradic

Hi! Welcome back.

Quote: "I've been trying since to create a simple background blur shader."


How far did you get? You could approach the problem in various ways. If you can be sure the background really is further away then simple distance based blur applied to all objects might be simplest to implement - but is bound to be heavy computationally because it will probably require multiple passes. If you have Dark Shader then the new DBPro commands and extra shader support that come with it enable you to write more efficient full-screen and blur shaders.

Quote: "Just tested Mike Inels Shader which can be found pretty much in the middle of this page (I attached it anyway). It does have motion blur but would it be possible to add distance blur to it ? The shader has some other quiet useful stuff in it."


Yes, that's a nice shader which implements several useful features - and implements a form of blur quite efficiently. You could probably adapt that quite easily. My guess is that you just need to calculate the BlurX, BlurY and BlurZ values in the vertex shader before using them. If I recall correctly, Mike's demo dba code passes these values to the shader as zero when the object/camera is not moving - you just need to replace that with distance based code in the shader (I think ). Definitely worth a try anyway.

@aXeon

That's a weird problem - especially since EVOLVED's shader works. Does that shader use Set effect constant float / vector /etc.. ? His shader demos usually do.

Do the shaders all work correctly if you remove or comment out the set effect constant commands? (Depending on the demo, you may need to adjust certain things in the shader to make them look OK if you aren't using set effect constant, etc.)

Only thing I can think of is a GFX card driver issue - might be worth updating it.

One other thing - is there a pattern in the shader version that's being used in the shaders, i.e. VS_2_0, PS_2_0, etc in the "compile" lines near the end of the shaders?

Quote: "That shader on page 1, 'JustOneColor' even crashes."


I'll have a quick look at that to see if there are any clues.

Edit No, that demo is about as simple as you can get. Anyone spot the silly bug in my dba code? Doesn't affect the shader though. Shame I didn't get around to writing more tutorials like that ... When I retire, perhaps?

Edit2 Which DBP upgrade are you using? You should use the latest U6.6b if you are using shaders. Some early versions won't work correctly with shaders.

Login to post a reply

Server time is: 2024-05-04 09:45:55
Your offset time is: 2024-05-04 09:45:55