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 / The Ultimate Shader Thread 2.0

Author
Message
Ian T
21
Years of Service
User Offline
Joined: 12th Sep 2002
Location: Around
Posted: 22nd Feb 2005 12:11 Edited at: 22nd Feb 2005 12:36
A while ago Neophyte started a fantastic thread to provide a complete knowledge reference for working with pixel and vertex shaders in DarkBASIC Professional. The thread has expired now, but all that great information shouldn't be lost, so I'm making a new one with all of his tutorials and some additional gems from that same thread.

Due to the sheer bulk of all the information he and others posted I will be presenting all of the information in a few posts.

Feel free to post here with questions or knowledge about shaders.

Here is Neophyte's original introduction.


Shaders are programs that run exclusively on modern graphics hardware. However, there are many different profiles for shaders which dictate what graphics hardware they can run and what they are capable of.

Profiles consist of different instruction sets that have varying capablities. They are usually refered to by number. For example, one of the earlier vertex shader versions is called vertex shader 1.1 or VS_1_1 or vs 1.1 for short. Shader profile is one of the most common reasons that a shader won't run on your hardware.

A complete list of profiles is as follows.

Vertex shader 1.1
Vertex shader 2.0

Pixel shader 1.1
Pixel shader 1.2
Pixel shader 1.3
Pixel shader 1.4
Pixel shader 2.0

Generally, if a card can support a profile it can support all profiles below it. For example, the Geforce 4 ti 4200 supports Pixel shader 1.3. So it also supports Pixel shader 1.2 and Pixel shader 1.1.

For information on what profile your graphics hardware supports go to the website of the graphics card and it will usually tell you.

Here's a general reference as to what supports what. Cards newer than the listed cards here almost always contain all of the profiles listed for the older cards.

Nvidia Geforce 3 ti - VS 1.1, PS 1.1
Notes:
One of the earliest shader capable cards out there. It supports the basic bare minimum shader profiles and Nvidia cards older than this do not support shaders whatsoever.

ATI Radeon 8500 - VS 1.1, PS 1.1, 1.2, 1.3, 1.4
Notes:
Came out 6 months after the Geforce 3 ti. This is ATI's entry into the shader capable graphics card market. It supports the basic vertex shader profile as well as several new pixel shader profiles most noteably PS 1.4.

Nvidia Geforce 4 ti - VS 1.1, PS 1.1, 1.2, 1.3
Notes:
Adds several new pixel shader versions to the geforce series. Does not support pixel shader 1.4 as this was ATI's creation.

ATI Radeon 9500 - VS 1.1, 2.0 PS 1.1, 1.2, 1.3, 1.4, 2.0
Notes:
Added VS 2.0 and PS 2.0 to the Radeon series. This card and all other Radeons after it should be able to run any shader out there currently.

Nvidia GeforceFX 5200 - VS 1.1, 2.0, PS 1.x, 2.0
Notes:
This card and all other Geforces after it should run almost any shader that you can find out there.

Nvidia GeforceFX 5700 - VS 1.1, 2.x PS 1.x, 2.x
Notes:
The GeforceFX 5700 and up(with the exception of the 5800) add new extensions to the 2.0 model for both vertex and pixel shaders which makes them pixel and vertex shader 2.x capable.

Nvidia Geforce 6800 - VS 1.1, 2.x, 3.0 PS 1.x, 2.x, 3.0
Notes:
Adds the new Shader Model 3.0(VS and PS 3.0) to the Geforce series.

A special note about Geforce 4 MX:
This is the one card that breaks the rule of newer cards supporting the profiles of older cards. This card doesn't support any of the pixel shader profiles and it only supports VS 1.0 which was a vertex shader profile that was never intended to be used in graphics hardware. Its a terrible card that is nothing more than a souped up geforce 2 and I'd recommend avoiding it and buying something far better like a GeforceFX 5200 which is around the same price as Geforce 4 MX but absolutely blows it away in terms of performance and features. I'd even recommend getting the older Geforce 3 ti over the MX.

What profile a shader uses is largely determined by what instructions or how many instructions it uses. Shaders in the .fx file format have their profiles explicitly stated in the .fx file so determining what profile a shader uses is a piece of cake. Shaders that are not in the .fx file format(which we will deal with shortly) are another story.

Shaders written in assembly have what profile they use at the top of their code in abbrevated form. So if you see a VS 1.1 at the top of an assembly shader than it means that it uses the Vextex Shader 1.1 profile.

Shaders written in HLSL, High Level Shader Langauge, do not have their profile explicitly stated in them if they are not in the .fx file format. These are a lot harder to determine whether they work for one profile or not so your best hope of finding out is to look at whatever information came with it if you got it off the net or if that fails just try compiling it with a shader compiler under various profiles. If you are really knowledgable about shaders you could determine what profile it uses by spotting any instructions that are specific to that particular profile but this won't always work as a shader could be of a certain profile because of instruction count limits and not because of instructions used.

DBPro doesn't deal with straight HLSL shader files, though it can deal with assembly files. So concerns about shader profile won't really factor in until you decided to convert an HLSL shader to the .fx file format.


Resources for shader developers

RenderMonkey from ATi
http://www.ati.com/developer/rendermonkey/

FX Composer from nVidia
http://developer.nvidia.com/object/fx_composer_home.html

Other resources, posted by Neophyte

If you want to move ahead here are a few more resources for you to look over. I don't have the time to go over them in detail unfortunately so I'm afraid you'll be on your on for the time being.

From issue 9 of the DBPro news letter:
http://www.fairyengine.com/articles/hlsl2sided.htm

This one deals with pixel shaders, how to set them up in DirectX 8(not very useful for us) and the pixel shading asm language(useful for us). Note: I haven't had the time to go over how to integrate ASM shaders into the FX file system but it is really easy. For a good example of how check out the bump.fx shader that came with DBPro and that I posted above.
http://www.cfxweb.net/modules.php?name=News&file=article&sid=1305

This one is from Microsoft. Deals with HLSL and hemispherical lighting:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndrive/html/directx02192001.asp

Here is a power point slide by Wolfgang Engel dealing with HLSL:
http://www.shaderx.com/direct3d.net/GDC2003/index.html

Here is another tutorial dealing with HLSL this time using RenderMonkey, a tool for developing shaders by ATI. Note: The .fx export for the current version of RenderMonkey is broken. Don't bother trying to export shaders from RenderMonkey because it would be quicker to create the .fx file by hand and paste your source into it than to have to modify the .fx file produced.
http://www.shaderx.com/direct3d.net/tutorials/RenderMonkey%20Movies/1Steps/RenderMonkey.htm

And to top it off, here is the page where I found the above two tutorials. It contains another four tutorials, Fundamentals of Vertex shaders, Programming Vertex Shaders, Fundamentals of Pixel Shaders, and Programming Pixel Shaders that might be of interest to you.
http://www.shaderx.com/direct3d.net/index.html


Its tough finding good material thats meant for absolute newbies. A lot of this stuff makes the assumption that you are familar with the graphics pipeline and how it works. I learned about this through another book called "Real Time Rendering Second edition". The best that I can offer is a link to its massive resource page.

http://www.realtimerendering.com/

A good start would be under Rendering Pipeline. There is a link that details the Direct3D rendering pipeline as well as the pipeline for OpenGL. I know its an extremely dense read and a bit much to a hit a beginner with, but it is all I can come up with for the time being. I haven't really had the time lately to spend on these forums.


The old thread for reference purposes:

http://forum.thegamecreators.com/?m=forum_view&t=28992&b=1&p=5


Neophyte's First Tutorial:

THE FX FILE FORMAT - PART ONE - BUMPREFLECTHLSL SHADER IN DBPRO


The .fx file format is a simple, easy, to use format that encapsulates a number of parameters required to run a shader. These parameters include, but are not limited to, the shaders themselves, various techniques, the number of passes to be made, textures used, models used, constants, render states, sampler states, shader states, light properties, materials, etc. Basically, almost anything that can make up a graphical scene is or can be included in a .fx file.

In this tutorial, I will cover how to set constants, loading in the media that DBPro requires to run shaders as well as a brief overview of the FX file. The specific shader that we will be using is the BumpReflectHLSL shader that comes with Nvidia's FX Composer. The Media for this tutorial can also be found with Nvidia's FX Composer.


Here is the BumpReflectHLSL shader in .fx format:



It can be broken up roughly into Seven sections.

The first section is called "un-tweakables."



The un-tweakables are a series of constants that can't be manipulated by hand. You can't just increase one of the values in them by one and expect to see coherent results. These un-tweakables usually consist of a series matricies that are necessary to display 3D models on the screen. An example of one of these maticies would be this:



This section of code can be split up into four parts: type, variable name, semantic, and annotion.

The float4x4 part is the type. This denotes the fact that the variable is a 4 by 4 array of floating point numbers. Most matricies are size float4x4 though they can be smaller.

The worldMatrix part is the variable name. The variable name always comes directly after the type. This is important as we might need this variable name later on if we need to set the constant manually. Setting a constant manually is usually necessary when DBPro can't set it for you due to an unrecognized semantic.

Which leads us to Semantics, the next part of in this section of code. The part that comes after the ":" symbol is the Semantic; in this case it is World. DBPro recognizes a certain set of case-insenstive semantics and will supply the necessary data for them. The current list of supported semantics as of Upgrade 5.2 is as follows:

World
View
Projection
WorldView
WorldViewProjection
WorldIT
ViewIT

The final part of this section of code is the annotion. It consists of everything between the < and > symbols. Annotions are optional and are entirely application specific. There is no current standard for what can be in an annotion. They are mainly used by content creation applications like FX Composer to provide additional information like what kind of User Interface gadget the constant can use if any. You'll see in this section of code that the UI widget is set to "none." That's because matricies like these can't be easily manipulated due to the complex math behind making a valid matrix.

The next section of the .FX file is called "tweakables".



There is only one in this file, bumpHeight, but there is usually more. As you can see, bumpHeight is of type "float" and is to be set to 0.5. DBPro, as of upgrade 5.2, won't set it to 0.5 though. You'll have to set bumpHeight manually.

The next section of the .FX file format contains the textures to be loaded and their respective sampler states.



This section will need a little modifying as DBPro, as of Upgrade 5.2, doesn't support FX Composers naming conventions. You'll have to change the line:



to:



Basically, you change "Resource" to "name" and DBPro will understand that you want to load a texture. Do the same for the cube map so it's line looks like this:



These two textures are included with FX Composer. You'll find them under MEDIA->HLSL_textures and MEDIA->textures->cubemaps respectively. Make sure that you include these files in the same directory as your shader so they load with it.

The section after the previous one holds the structures that are passed into and out of the Pixel and Vertex shader if any.



These really aren't very important for our purposes right now so I'll skip over them.

The next two sections are the vertex shader and the pixel shader respectively.





Now there can be more than one vertex and/or pixel shader in the .FX file or than can be none at all(which will be covered in a subsequant tutorial). These sections will only exist for HLSL shaders. Assembly shaders are contained in another section.

The final section of the .FX file is the technique section.




There can be any number of different techniques in a .FX file but there most always be at least one. There are two techniques in this paticular shader, BumpReflect0 and ReflectNoPixelShader. BumpReflect0 contains two shaders that use profiles pixel shader 2.0 and vertex shader 2.0. This is the high quality version of the effect. The second technique, ReflectNoPixelShader, is a lower quality version of the effect and will run on most cards. Its image quality is based on how well tessellated the model is though. DBPro will operate on the first technique if your card can run it. If it can't it will move to the next available technique and see if it can run that. So no need to switch techniques to get what version you need to run it on a card, unless you are deliberately running the technique below the cards capabilites to boost your games performance. Or running a different effect using the shaders in the effect file. The choice is your's.

But enough talk. Lets get to some code.

In order to figuare out quickly what constant's you are going to need to set start a new project and type in this code:




This will print all of the constants to the screen. The important part to notice is the value of "Hook: ". It will be 1 if DBPro knows how to set the value and 0 if it doesn't. A gentle reminder: Make sure that you have the media for this shader in the same directory as the shader before you run this code.

Now you should see a 0 value after the hook for worldViewMatrixI, viewInverseMatrix, and bumpHeight. Will deal with bumpHeight first because it is the easiest. In order to set the bumpHeight constant all you have to do is type in the following code before the do loop:





Now we know that bumpHeight is of value float due to "VarType: " having a value of 3. The value of VarType corresponds to what type the constant expects. Here are the values and their corresponding Types:

Value: 0 Type: Undetermined. This occurs for textures and sampler states. Since we don't need to be set anything with a Value of 0 these should be ignored.

Value: 1 Type: Boolean.

Value: 2 Type: Integer.

Value: 3 Type: Float.

Value: 4 Type: Vector.

Value: 5 Type: Matrix.

Now we move on to the two matricies that need to be set, worldViewMatrixI and viewInverseMatrix. Lets start with worldViewMatrixI.

Figuaring out what these matrices need is usually pretty easy as most coders name their variables after the order in which the matrices are multipled or operated on. For example, with worldViewMatrixI we can deduce that we will need a world matrix and a view matrix to multiple together and an inverse operation to perform on the result. So write in the following code above the do loop to set up the matrices we will need for this constant:



Here we are making two 4x4 matricies numbered 1 and 2. The null return value is not important. It will always be 1 and isn't really needed other than to fill out the requirement of a variable for the make matrix4 to return its result into.

Next up is filling in these matricies. Now the DBPro 3DMath command set has a large selection of possible matrices to choose from. We want two paticular matrices, World and View, so we use the World Matrix4 and the View Matrix4 commands:




Its as easy that. We now have our matricies filled out so lets multiply them.




DBpro's 3Dmath command set is really simple so don't let other people fool you into thinking it's too tough to approach. Take the above command for example. All we did was multiply matrix 1(our world matrix) by matrix 2(our view matrix) and store the result back into matrix 1. So now we have matrix 1, which contains world*view, and matrix 2 which contains just view. Pretty simple, no?

All we have to do now is perform one last operation on matrix 1 and we are ready to set our first matrix constant. Type this in after the above code:



The null# is just a place holder for the necessary return value needed by inverse matrix(which is also a float and not an integer for some bizarre reason).

With this simple operation performed on our world*view matrix we now have the necessary result needed to set our constant. So without further ado here is the code to set the constant:




That's one down. Now for number 2.

Recall that we already stored our view matrix into matrix number 2. Now to get the value for viewInverseMatrix we have to, as you might have guessed, invert our view matrix. We'll use the same command as we did last time:



Since that is all that we have to do to get the needed result we type in the following code to set the constant:



With that done you should be able to run the the shader and see the BumpReflectHLSL shader in all of its glory.

A Quick Note: if you left the code for checking your constants in your do loop you'll notice that the hook values for the constants you just set are still 0. This doesn't mean that you didn't set them. DBPro, as of Upgrade 5.2, doesn't check to see if you set a constant. Only whether the semantics associated with that constant are supported or not.

This concludes the first part of THE FX FILE FORMAT tutorial series. For the complete code to run the BumpReflectHLSL shader look in the source button below this post.

If you find any factual errors or would like to recommend any additions to this post that would increase clarity(not content) than please post in this thread and I'll see what changes I can make.


End of Tutorial

It is a perilous occupation for TGC to post anything by way of a promise, as the words get etched in indestructable marble for all time.
-Lee Bamber
Ian T
21
Years of Service
User Offline
Joined: 12th Sep 2002
Location: Around
Posted: 22nd Feb 2005 12:16
More content from Neophyte:

Anyway, as requested, a media-less shader with full DBPro source code.

The shader in question is the per-vertex Goochy lighting model. It shades everything with Warm and Cool tones on a vertex by vertex basis. Its one of the few per-vertex shaders out there that will light a low poly object rather well. The code for the shader is here:




The accompanying DBPro program will allow you to modify the effect constants in real time and see the result. The DBPro source is here:



Instructions:

Press the Upkey/Downkey to Increment/Decrement the LiteColor.
Press the LeftKey/Rightkey to Increment/Decrement the DarkColor.
Press the W/S keys to Increment/Decrement the WarmColor.
Press the A/D keys to Increment/Decrement the CoolColor.

You'll have to copy and paste the effect into notepad and save as goochy.fx. Also, make sure that the effect file is in the same directory as the project.

It is a perilous occupation for TGC to post anything by way of a promise, as the words get etched in indestructable marble for all time.
-Lee Bamber
Ian T
21
Years of Service
User Offline
Joined: 12th Sep 2002
Location: Around
Posted: 22nd Feb 2005 12:29
Neophyte's Second Tutorial

THE FX FILE FORMAT - PART TWO - CARTOON SHADING IN DBPRO


THE FX FILE FORMAT - PART TWO - CARTOON SHADING IN DBPRO

The goal of this tutorial is two-fold. The first goal is to provide the reader with a firmer grasp on the cartoon shading abilities of DBPro so each developer can create a more personalized look to their cartoon shaded models. The second goal is to explore the concept of assigning media to a shader dynamically.

To that end, I present to you the cartoon shader that DBPro uses internally:





This shader and its media can be found under Help->examples->basic3D.

Now to highlight the important bits.

Since we want to use whatever media we would like with this shader lets take a look at the media required by this shader.



This code can be found at the top of the .fx file below the constants.

The "string XFILE = "default.x" means that it will use the model "default.x". The model isn't really all that important for our purposes so we'll ignore it for now.

The next two lines are the most important. The textures toonshade and toonedge determine how the model will be shaded. You can find these in the same folder that you can find the cartoon.fx file. Lets examine them in detail.

The toonshade texture is shade.bmp and opening it up in paint you can see it is a single pixel in height and 16 pixels in width.

Note: You are going to have to zoom in a bit on it to get a good view.

Now you are probably wondering why the image is only 1 pixel high and the answer is of course that it doesn't need to be any higher. What happens is that the shader takes the dot product of the light vector and the normal of the vertex and the result is a single value. That value is used to look up a pixel in the shade.bmp.

So the shade.bmp is basically a one dimensional look up table. The closer to the light a paticular vertex is the further to the right in the texture the value is looked up.

You can change shade.bmp to hold whatever color ramp that you want. Just keep in mind that all pixels below the first line will be ignored.

The next texture is the toonedge. As you could probably have guessed this texture determines the color of the edges of the model. Its listed as edge.dds but that is incorrect. The edge.dds image is a 1 by 128 image that is just a single color: white. The example that came with DBPro that showcases the Set Cartoon Shading on command uses the edge.bmp texture instead.

The edge.bmp texture is 32 by 32 image. It consists of a gradient that starts on the right with the color white and goes to the left to the color black. Now it doesn't need to be 32 by 32. It can be just 1 by 32 as edge.bmp is a look up table just like Shade.bmp. The values for it are determined by taking the dot product of the eye vector with the normal of the vertex. The result is a single value used to look up which pixel should be multipled with the current pixel.

You are probably not going to want to modify the edge image other than to maybe make it a 1 by 32 image. However, there is nothing stoping you from trying out different values if you want the edge of your image to be shaded differently.

Now that we have covered the needed textures, lets examine how to load and apply them seperately from the shader.

Note: Before we begin, make sure that the shader and its media are in the same folder as your project. The following code will be based upon this assumption.

The first line of our source will be this:



The zero at the end of the command tells DBPro to use the existing textures on the model and not the ones specified in the fx file. This is different from our usual approach of leaving a one at the end of the command seeming how we want to assign the media seperately from the shader.

After that we will load in our images and create our test model:



At this point I'd like to point out the advantage of loading in media seperately from the .fx file. If we loaded media through the .fx file, i.e. left a one at the end of the load effect command, we would be stuck with that media for whatever we applied it to. Loading the media in seperately from the .fx file would allow us to use whatever media we wanted to. We could even use different media for different objects all with the same shader.

To use our current shader as an example, we could load in multiple shade images, that may or may not be named "shade.bmp", to give a different color to a variety of objects. We wouldn't be able to do that if we loaded in the hardcoded media. The only way we could achieve an effect like that is to have seperate shader files each with a different shade image and that could be pretty wasteful of both space and time.

For simple demos, the hardcoded way is probably easier, but for games that have varying texture requirements the dynamic way is the way to go.

Now we have the most important part to do and that is assigning the loaded textures to the shader. Its surprisingly simple to do and it involves the texture object command. Insert these two lines into your DBPro code that you have so far:



The first number, 1, is the object to be textured. The second number is the stage index to which the texture is being assigned. After that is the image number.

Now in order to determine the proper texture stage index we need to look back at the shader code.

Under the vertex shader assembly is a series of render states. This section of code looks like this:



The two that we are interested in are the Texture[0] = <toonshade>; and the Texture[1] = <toonedge>;.

The number in brackets is the texture stage index. So for the toonshade texture we would assign a 0 and for the toonedge texture we would assign a 1. Its as simple as that.

Unfortunately, not all shaders use the Texture[n] state command. Only the shaders that use assembly usually do. So for HLSL shaders most of the time you'll need to do a bit more work. For the shader being used, you'll have to look in its input parameters for a variable or a variable of a structure that contains the TEXCOORDn semantic. From there it will take a little investigative work to figure out which texture is assigned to which. Usually you'll need to look for the tex2D function or its derivitives in the pixel shader. You'll see a variable that contains the tex coords to be used and a sampler state name. With the name of the variable and the specific texcoord semantic assigned to it all that is left to do is find the sampler state specified by the sampler state name.

Sampler states are usually declared above the function somewhere. They are usually easy to find because they start with a keyword like sampler2D or samplerCUBE followed by the name of the sampler. In them you'll find a Texture = <whatever>; and the "whatever" is the name of your texture.

Now that we have assigned the textures to their appropriate stages, we can assign the shader to the object.



After that we have a little while-loop that exits when the space bar is pressed. The code from here on out is pretty standard fare so I'll just list it as it needs no real explanation.



But the cartoon shader that comes with DBPro is rather limiting. You can only shade the object one color and there is no option to apply a texture to it. So you end up with a rather uninteresting monochrome object. We can do better.

As an added bonus, I will add some additional code to DBPro's cartoon shader improving it. It will now take an additional texture in as a base texture so you can detail your model even more.

Add this code beneath the first technique:


And add this code up at the top beneath the two texture declarations for toonshade and toonedge:


Now we only have to add a few lines of code to our existing DBPro source to get it to work. The first line will of course be a load image command after all of the other load image commands. It will load in our texture that will be used as base. For this example we will be using the marble.bmp texture that came with DBPro. It can be found in the same directory as all of the other media that we have used so far.


Next we will assign the texture to the object. We will assign a texture stage index of 2 to our base texture. Place this code just below all of the other texture object commands:


The last line we will need to add will switch the current technique, which doesn't accept a base texture, to the new technique that will. Place this under the set object effect command:


The final version of the source can be found below. Note: This source will not run the old version of the shader but the new one only. Also, the new version of the cartoon shader is still named cartoon.fx in the source though you can change that if you want.


For future work, you can always modify the existing code to switch back and forth between shader techniques or other shaders. Since applying the texture object command to an object will wipe whatever shading is being done to it, you can simply set up the texture stages for the new shader or technique with the texture object command and apply whatever shader you want or none at all. There is no special command needed to stop an object from being shaded other than using a texture object command on it.

That concludes the second tutorial of the FX FILE FORMAT series. I hope that this has been an informative experience that answers many of the questions surrounding cartoon shading in DBPro.

End of Tutorial

It is a perilous occupation for TGC to post anything by way of a promise, as the words get etched in indestructable marble for all time.
-Lee Bamber
Ian T
21
Years of Service
User Offline
Joined: 12th Sep 2002
Location: Around
Posted: 22nd Feb 2005 12:30 Edited at: 22nd Feb 2005 12:33
Ideajuice posted an ocean shader with some information on how he modified it to work with DBpro:

Here is the ocean shader modified to work in DarkBasic. Call it Pocean.fx to go with the example.



Here is some DB sample code to instantiate it:



The example uses a model called "slab.x". It is too large to post inline here, but it is simply a plane that has been subdivided into a grid. The more subdivisions, the better the effect looks, but of course the more memory it uses and the slower it will run.

The only changes to the shader were to change all occurences of "ResourceName" to "Name" and to change this line:

Quote: "float4x4 viewInverseMatrix : ViewInverse < string UIWidget = "none";>;"


to this:

Quote: "float4x4 viewInverseMatrix : ViewIT < string UIWidget = "none";>;"


so as to avoid having to unneccessarily compute and set the View Inverse transform from within DarkBasic.


Have fun.


And later posted a modified version:



that is our old friend the ocean shader which I have added the depth shader into so that the farther parts of the ocean darken.

To make this work, I added the output of the Z shader, which was a color, to the structure that lists what the outputs of the Vertex shader are. Then in the pixel shader, after it has done all of it's normal calculations, I multiply the color it computes by the color computed by the Z-Depth shader.

It is a perilous occupation for TGC to post anything by way of a promise, as the words get etched in indestructable marble for all time.
-Lee Bamber
Ian T
21
Years of Service
User Offline
Joined: 12th Sep 2002
Location: Around
Posted: 22nd Feb 2005 12:40
NinjaMatt posted a number of excellent shaders that work with DBpro and information on how he made them. Here is the first:


A bloom lighting effect? Well, I've been fiddling around to make one that works in DB, and here's what I've got so far:





Currently, the shader works by using a seperate camera to render the scene to an image, preferably of size 128/128 or 256/256, and then using that image to texture a ghosted plain in front of the main camera. The shader will then blur the image and scale the colours to get a good glow. Also, you'll need to make sure that the second camera, used to capture the glow image, doesn't include the plain, otherwise it'll mess up. The way I did that was to position the plain three units in front of the main camera, then set the second camera's minimum view range to four units. Also, you have to remember to tell the shader to use the textures already applied to the object when you load it, otherwise it'll mess up.

I've included a modified version of the RoadTerrain program in the code box below, since that's what I use to test all my shaders out! To use it, you'll need to have this shader saved as "GlowTest2.fx" in the "RoadTerrain" folder, where the .dba file is stored. Then start a new project and paste the code below into it. If it doesn't work - kick me until I fix it!

You might also want to go into the shader itself and mess around with the "Scale for Glow" part, since that's what affects the final colour output the most.

It is a perilous occupation for TGC to post anything by way of a promise, as the words get etched in indestructable marble for all time.
-Lee Bamber
Ian T
21
Years of Service
User Offline
Joined: 12th Sep 2002
Location: Around
Posted: 22nd Feb 2005 12:46
Another of NinjaMatt's shaders:



Now, second-up, is one of the first shaders I ever made, but one that forms the backbone of the GUI for my current game - it's a hologram shader! And, for the peeps with older hardware, it's just a vertex shader, so it'll work on even the most dated video card. As usual, here's the source code for the shader:




The preview picture:


And finally, the example program that the picture was taken from:
http://mysite.wanadoo-members.co.uk/wisemonkeys/darkbasic/Hologram11.zip

It is a perilous occupation for TGC to post anything by way of a promise, as the words get etched in indestructable marble for all time.
-Lee Bamber
Ian T
21
Years of Service
User Offline
Joined: 12th Sep 2002
Location: Around
Posted: 22nd Feb 2005 12:48
A third shader from NinjaMatt:


And, once again, I've got another shader for everybody. This is another shader I'm going to be using in my game, but I'll probably enhance it before I do, so you might see another version sooner or later. I'm also quite chuffed that I managed to convert it over to PS 1.1, since it uses texture dependent reads and they're pretty messed up in the older versions!

Anyway, what we have a simple metallic shader that utilises normal maps to get a nice 3D effect. It's not such a far cry from the hologram shader, actually, as it reads the shininess from a 1D lookup table that is made so a shallow eye angle causes the metal to shine brighter. Usually, an effect like this would probably be done with a cubic environment map instead of a 1D map, but this method is faster and saves a lot of memory. Not to mention that it was easier to program, too! It still looks nifty, and that's what matters, right?





http://mysite.wanadoo-members.co.uk/wisemonkeys/darkbasic/Metal11.zip

Hope you like it, there'll be another one soon!

It is a perilous occupation for TGC to post anything by way of a promise, as the words get etched in indestructable marble for all time.
-Lee Bamber
Ian T
21
Years of Service
User Offline
Joined: 12th Sep 2002
Location: Around
Posted: 22nd Feb 2005 12:52
A fourth shader from NinjaMatt in its final iteration:


Well, call me persistent, or just unoriginal, but I've got yet another version of normal map shader for you! The only functional changes are that it can now read up to eight lights, as controlled by the technique you select, and that the shader has been split into two seperate files - one for normal mapping, the other for normal mapping with specular lighting. The reason for this change is that, as more lights are added, so are more passes, which ends up making the .fx files absolutely huge! Click here to grab them:

http://mysite.wanadoo-members.co.uk/wisemonkeys/darkbasic/NormalMap21.zip

There are three techniques in each file: Lights2, Lights4 and Lights8, which differs from the older version which only has the two techniques Normal and NormalSpecular. Apart from this, the effect should plug comfortably into the sample program I made.

Speaking of passes, that's a little problem area that you'll have to be aware of: using all eight lights can seriously slow down you game, as standard lighting will require four passes, while specular lighting will take up a whopping twelve passes! I'd recommend that you optimise your scene to run on four lights instead of eight (remember that shader lighting is defined seperately from the standard lights), which would halve the amount of passes needed. Failing that, you could always modify the shader yourself to accomodate exactly the amount of lights you need - just delete some passes from the Lights8 technique to make your own five or six light technique.

Sorry for all the confusion with the new versions and everything, but it's pretty hard to make a shader to accomodate everybody's differing needs! I'll get it nailed eventually, I hope!

It is a perilous occupation for TGC to post anything by way of a promise, as the words get etched in indestructable marble for all time.
-Lee Bamber
Jess T
Retired Moderator
20
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 22nd Feb 2005 13:44
Mouse, you're a legend!

I was actually about 2 pages into that thread the other week before I gave up wading through the fights of Raven's Ego Vs Rest Of The World.

Thanks for doing this, mate.

And thanks to Neophyte for the original information.

Jess.


Team EOD :: Programmer/All-Round Nice Guy
Aust. Convention!
Ian T
21
Years of Service
User Offline
Joined: 12th Sep 2002
Location: Around
Posted: 22nd Feb 2005 14:33
Thanks Jess ! Glad to help. I'm not sure if Neo, Ideajuice or NinjaMatt are still around, but I would definatly like to thank them for all this as well. Neo's tutorials are awesome and NinjaMatt's normal shader is absolutely fantastic.

It is a perilous occupation for TGC to post anything by way of a promise, as the words get etched in indestructable marble for all time.
-Lee Bamber
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 22nd Feb 2005 21:21 Edited at: 22nd Feb 2005 21:24
Now that's a good work, Mouse.

I would like to start the new contributions with one of my first shaders: Simple Blur

Code for DBPro:



and the hlsl .fx file:



Well, use :

"1" & "2" for changing blur factor (~number of pixels displaced)

"a" & "s" for changing ambient color (only levels of white at the example)

"z" & "x" for changing diffuse color (only levels of white at the example)

"3" & "4" for changing blur addition factor

It performs a simple blur by adding the color of the surrounding pixels to the current one.

I was intending to perform a post-processing effect, but two objects are needed for that (the object itself and a screen aligned quad), and I do not know how to make that different techniques affect different objects within the same .fx file/effect loaded in DBPro, so I made this work-around. If we knew that, we could make some impressive effects.

Now all the martians get out of the closet! (just a joke)

Regards.
Dodo
19
Years of Service
User Offline
Joined: 8th Aug 2004
Location: eating lunch
Posted: 23rd Feb 2005 02:47
yayyy!!! here is another happy coder who was in the same position as Jees. Thanks Mouse!

Part of solving the problem is actually noticing that the problem is there in the first place

MoboJack
19
Years of Service
User Offline
Joined: 20th Jun 2004
Location:
Posted: 23rd Feb 2005 10:44
Thanks! This is going to help a lot

Mobojack is on the phone -
Preston C
20
Years of Service
User Offline
Joined: 16th May 2003
Location: Penn State University Park
Posted: 24th Feb 2005 09:42
Hey mouse, you missed the ones I posted (guess you got tired of looking after the sixth page, huh?). Though, they are pretty simple ones:

http://www.ppcdesigns.com/public/ShaderPack1.zip

Intel Celeron 1.3 Ghrz | 512 MB Ram | NVIDIA GeForce FX 5200 128MB
MSVC++ .Net 2003 | Wings3D | CharacterFX | Gimp v2.0
Prayne de crabug ahm rinedere be-yogt iglo kes gron
Teh Go0rfmeister
20
Years of Service
User Offline
Joined: 17th Aug 2003
Location:
Posted: 26th Feb 2005 21:17
someone should really set up a website dedicated to this...

Ninja Matt
19
Years of Service
User Offline
Joined: 5th Jun 2004
Location: Lincolnshire, UK
Posted: 27th Feb 2005 08:16 Edited at: 27th Feb 2005 11:31
Hi, everyone! Long time no see!

I'm glad to see that some people are still sticking at the whole shader thing, even after Raven's flame war! I haven't used DarkBasic for a long time now, since I've pretty much migrated to C++, but I'm still hammering out some decent .fx files, so I'd be happy to stick around here and help.

In the meantime, I've got a few good shaders already prepared for DB - this one is an implementation of parallax mapping, which is a computationally inexpensive form of displacement mapping. There's a few problems with it, like some iffy distortions and a reliance on PS 1.4 (sorry, old-GF users), but it's otherwise quite cool.

http://homepages.nildram.co.uk/~moonrise/matt/Parallax20.zip

Just download and extract this into a folder, and load it into DB and create a project file for it if you feel like it. I'm a bit rusty on DB at the moment, but it should run nicely and give you something like this:



You can see a box with textures. The clever thing is that the box, although it looks to have uneven 3D surfaces, is actually just made from six basic plains! So, for those that want to modify it or convert it to HLSL or something, how does it work?

Quite simply, actually! The most important thing is the illusion of depth that you can see on the surfaces. A key point of note is that, when using PS 1.4 and above, you can specify texture coordinates on a per-pixel, rather than per-vertex basis. Although similar effects can be done in earlier versions, they lack the power and flexibility to do something like this. Anyway, using this technique, it's possible to 'warp' the texture based on any number of different parameters - for example, a heat haze effect would do this with a couple of noise textures. All we need to do is warp parts of the texture towards or away from the camera, which can be done by moving the camera into tangent/texture space. The resulting red (U coord) and green (V coord) channels become the offsets we need. Looking straight at the surface, both these channels would be near black, meaning there would be almost no offset, while looking at a shallow angle brings the channels nearer to 1/-1, and so gives a greater offset. This offset is then multiplied by a heightmap inside the pixel shader, which ultimately inhibits the offset of 'low' areas of the map, while ensuring 'high' areas are shifted away from the camera. The height modulated offset is then toned down a bit to keep the shift effect from getting out of hand (try changing the 0.08 constants in the pixel shader!) and added to the original texture coordinates.

The lighting is then done as standard N-dot-L normal mapping, with a specular effect and ambient lighting thrown in for good measure. It's a standard implmentation and isn't the focus of this shader, but if anyone wants to know how they work, let me know and I'll do my best to explain!

I've got a couple more to post, but I'm out of time for now, so look for them in a day or two! And, while I'm on the topic, does anybody have a shader request they'd like fulfilled?

Hope you enjoyed reading!
Jess T
Retired Moderator
20
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 27th Feb 2005 18:12
GOod-God, man! That's awesome!

Thanks for these, Ninja!

That really is an effective way to make a plain look like it has bumps and humps!

Great job

Jess.


Team EOD :: Programmer/All-Round Nice Guy
Aust. Convention!
Try
19
Years of Service
User Offline
Joined: 16th Aug 2004
Location:
Posted: 27th Feb 2005 20:24 Edited at: 27th Feb 2005 20:25
wow, thank you Ninja Matt.

It's great to see you here again

It's really kind of you to share it with us.

GOOD LUCK!
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 27th Feb 2005 22:58
@Ninja Matt, we are all glad to see you around.

Now, I cannot implement effects that use more than one object.

As a shader request I would say that a Shadow Volume one would be great for using it, as well as an example.
All Shadow Volume shaders that I've tried to convert use at least two objects, the one that projects the shadow and the other, that receives the shadow.

Also, a good example of this could be a post-processing effect, like bloom, glow, blur.. etc. (Anything with more than one object.)

Thanks for your time.
Ninja Matt
19
Years of Service
User Offline
Joined: 5th Jun 2004
Location: Lincolnshire, UK
Posted: 28th Feb 2005 02:30 Edited at: 28th Feb 2005 02:31
@Morcilla:
This is one of the limitations of DB and, sadly, it's quite a hard one to get around.

The post-processing effects can be done by specifying a camera to draw to an image. The hard part is then getting that image onto the screen. For something that doesn't need too much precision, like a glow or bloom, using a screen-aligned plain with a small camera-based image mapped to it still gives decent results. Although, if you were going to do anything like edge-detection or something that needs to operate on a sharp texture map (like a perfectly aligned 1024x768 map, for example), you're going to need to do something a bit more complex. It should be possible to make a shader that aligns a quad perfectly to the screen, which would be the first step in getting this to work, so that's what I'll have a go at over the next few days.

As for shadow volumes, they're going to be pretty tricky in DB. I'll see what I can do, but I suspect I'd need to get the above done first, before I can get anything else!

Anyway, here's another shader for you all (sorry, PS 1.4 again):


http://homepages.nildram.co.uk/~moonrise/matt/PhongHolo10.zip

Look familiar? It's the next rendition of the hologram shader, but this one using the Phong lighting model rather than the Gauraud (sp?) model. The Phong model performs far better when applied to low-poly models, especially curved ones, since it operates on a per-pixel rather than per-vertex basis.

Gauraud, as I'm sure you all know, will compare the normal vector of each vertex on a model against the vector of a light source and, with a bit of N-dot-L magic, gives you a resulting luminance value. This value is then linearly interpolated across the polygon and passed into the pixel shader for output. Although very fast, this procedure can easily miscalculate the lighting on curved surfaces if there isn't a vertex in the right place.

Phong, on the other hand, gets around this by passing the vertex normal vector and the light vector into the pixel shader and doing the calculation there. With the aid of the above linear interpolation, the model provides a good approximation of a curved surface at the pixel level, which is especially useful when we are dealing with specular lights. Of course, the downside to Phong lighting is that it's a bit slow compared to Gauraud and uses quite a lot of valuable pixel shader instructions!

If you want more information on lighting models, just have a poke around the Internet, and I'm sure you'll turn something up!

Hope this helps you all!
Hamish McHaggis
21
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 28th Feb 2005 06:03
Bleedin' 'eck! That parallax shader is fantastic . And the hologram shader looks pretty pretty as well . I'll be trying to find some use for them.

I definitely have a shader request. I'm not sure how hard this would be, or even how it would work, but here's how I'd imagine it... Basically having a second texture map where black is no added effect, and coloured areas glow. Glow as in look like they're emitting light, like a flourecent (sp!) light. The more bright the colour is (nearer to white) on the texture map, the brighter the glow.

This could obviously be done by particles, but in certain situations it'd be good to have a shader to do it .

Isn't it? Wasn't it? Marvellous!
Ninja Matt
19
Years of Service
User Offline
Joined: 5th Jun 2004
Location: Lincolnshire, UK
Posted: 28th Feb 2005 10:51 Edited at: 28th Feb 2005 20:39
@Hamish:
Well, there's a lot of different ways you could do this, depending on how exactly you want the effect to work. The easiest, of course, is to just treat the second texture map as an overlay that just adds it's colour to the base texture while ignoring light. This would be good for making small lights stand out on a texture while the object is in darkness.

Of course, a more advanced technique would be to combine the above with a bloom/glow shader - this would make the light seem a bit more realistic, as it would 'stand out' from the texture it's placed on and affect the scene around it. The best way to do this in DB is to create two seperate shaders, one to make a basic glow on a textured model, then a seperate bloom shader that just operates on all bright spots in a scene. This would be the fastest and simplest way to do it, but has the downside that it might bloom areas that you don't want it to...

But, before I have a shot at the above, here's another shader! This one's a grass/field shader that boasts a similar 3D effect to the parallax shader (that means PS 1.4, too):


http://homepages.nildram.co.uk/~moonrise/matt/Grass10.zip

Although it uses a similar "shift the texture away from the camera" system, this shader uses four layered textures, rather than one warped texture. Each one is shifted slightly further, and therefore 'higher', than the last. With a bit of maths (PS 1.4 doesn't directly support the max command), the shader then chooses to display the brightest layer at each pixel, as this usually represents a bright blade of grass against a dark earth-tone. Of course, the effect isn't complete without a bit of a breeze thrown in! To get the waving effect, a simple noisemap is scrolled over the surface of the object and perturbs the texture coordinates in a similar way to the camera position. Noisemaps are used regularly in fake-procedural effects like fire, clouds and waves, as they give convincing results without appearing to repeat like a usual fixed animation.

One extra feature that makes the grass seem more organic is the addition of a fresnel term intented to give the illusion of sub-surface skittering. This skittering occurs when light isn't immediately absorbed by a surface, and so is allowed to pass a short distance through it. It's often seen in organic membranes like skin and, in our case, blades of grass, and tends to lend objects a more vibrant look. To see exactly what it's doing, try darkening the standard and ambient lights!

Anyway, hope you enjoyed reading! I'll try to have the above glow shader done in a couple of days!
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 28th Feb 2005 19:56 Edited at: 28th Feb 2005 20:25
@Ninja Matt:

Happy to see that you found that interesting.

I was afraid that the "two ojects" shaders were not possible with DBPro. At least now I won't waste my time trying to make it work that way.

I'm afraid also that any other technique that uses a second camera will be too slow for a real-time effect, specially when the afected object is near and covers big areas of the screen.
And it would have an increased dificulty in setting the position, as you said, as well as in optimizing the size of the effect area (to avoid sluggishness).

Great shaders examples! And nice tips too! (Although we can only see the .jpg picture of the Grass shader, I hope you don't mind if I post here the correct link: http://homepages.nildram.co.uk/~moonrise/matt/Grass10.zip)

Thanks a lot.

Quote: "Error! DBForum won't let me post the rest of my reply...
Arse fez... "


Unbelievable! You should even have your own parking place at the entrance! Somebody give this man a power user profile! or a medal! or something! (Another joke )
Ninja Matt
19
Years of Service
User Offline
Joined: 5th Jun 2004
Location: Lincolnshire, UK
Posted: 28th Feb 2005 20:22 Edited at: 28th Feb 2005 20:38
@Morcilla:
Thanks for posting the correct link! I'm afraid that was one of my messed up copy & paste jobs! I've fixed it now above, just to be on the safe side.

I've also figured out why it wasn't letting me post. Apparently, the forum doesn't like me using a word very similiar to "skittering", so went to a blank white page rather than did anything useful. I fear this may be the language filter gone bonkers.
Hamish McHaggis
21
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 1st Mar 2005 04:17 Edited at: 1st Mar 2005 04:24
Hmmm, I can't get your specular (or regular for that matter) normal mapping shader to work very well. the base texture only seems to show through when you have a bold colour, and this isn't very easy with brown textures . My object just looks completely white, with some bump mapping. Any ideas?

EDIT

Figured it out. Turning alpha down lets through more of the base texture, but surely alpha should only make it more shiny rather than more white?

Isn't it? Wasn't it? Marvellous!
Ninja Matt
19
Years of Service
User Offline
Joined: 5th Jun 2004
Location: Lincolnshire, UK
Posted: 1st Mar 2005 07:06
Hmm, that's probably because I haven't tested that version of the shader very well. After all, there was quite a lot to it, and it was mostly just copied from the original!

Speaking of the original, I'm sure that it works properly, so you might want to have a look at it instead:


http://mysite.wanadoo-members.co.uk/wisemonkeys/darkbasic/NormalMap20.zip

It only supports two lights, but it comes with a nice sample and it should be well-commented enough for you to make your own variations of it, especially if you already know a bit about shaders! If you've still got the same problem, let me know and I'll try to figure out what's up.
Ian T
21
Years of Service
User Offline
Joined: 12th Sep 2002
Location: Around
Posted: 2nd Mar 2005 00:36
That's amazing stuff ! The parralax shader is just fantastic, I didn't even know you could do that in DB yet. Damn good of you to stick around here even if you're not making DBP-compatible shaders for yourself anymore too.

Preston-> Yes, I did miss those, thanks for reposting them.

It is a perilous occupation for TGC to post anything by way of a promise, as the words get etched in indestructable marble for all time.
-Lee Bamber
EVOLVED0
19
Years of Service
User Offline
Joined: 1st Mar 2005
Location: UK
Posted: 2nd Mar 2005 05:41 Edited at: 20th Aug 2006 14:31
EVOLVED0
19
Years of Service
User Offline
Joined: 1st Mar 2005
Location: UK
Posted: 2nd Mar 2005 07:21
seems the links do not work sorry ...

Attachments

Login to view attachments
Baggers
19
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 2nd Mar 2005 09:55
Jesus christ ninja matt sometimes there is a definate need to be allowed to swear on these forums because that parallax mapping one was ****ing fanstastic...couldnt believe how good it looked!
Ill definatly be having a look into shaders more now !
Erick G
Retired Moderator
19
Years of Service
User Offline
Joined: 2nd Oct 2004
Location: Texas, USA
Posted: 2nd Mar 2005 12:53
This is awsome work guys, I am definatly going to visit this thread on a regular basis.

Ninja Matt, I ran your samples and all I can say is WOW. Please impart your knowledge to us
Peter H
20
Years of Service
User Offline
Joined: 20th Feb 2004
Location: Witness Protection Program
Posted: 2nd Mar 2005 21:58
Quote: "A special note about Geforce 4 MX"

ahhh...i just HAD to buy that Geforce 4 MX420 those 2 years ago didn't i...

/me sits here kicking myself over and over again

nice work guys...can't wait until i upgrade my graphics card

"We make the worst games in the universe."

EVOLVED0
19
Years of Service
User Offline
Joined: 1st Mar 2005
Location: UK
Posted: 2nd Mar 2005 23:50
uploaded a old bumpmap shader with 8 lights to my quick website i made.. also updated my High dynamic range rendering code and put some images up of what thay should look like.

go to my web page to get them. its a bit kack but i cant find any good "free" webhosting sites. also pls say if my site is not working......

http://myshaders99.50megs.com/index.html

thx.
MikeS
Retired Moderator
21
Years of Service
User Offline
Joined: 2nd Dec 2002
Location: United States
Posted: 2nd Mar 2005 23:50
Excellent work on the shaders Ninja Matt. Also, thanks to Mouse for reviving this topic, as well as Neophyte who spent a great deal of time making the great tutorial.Thanks as well to Preston for his pack of shaders.

Keep up the good work everyone, I'll keep my eye on this thread.



A book? I hate book. Book is stupid.
(Formerly known as Yellow)
Jess T
Retired Moderator
20
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 3rd Mar 2005 06:51
wow, evolved, they're really nice too

Jess.


Team EOD :: Programmer/All-Round Nice Guy
Aust. Convention!
Ninja Matt
19
Years of Service
User Offline
Joined: 5th Jun 2004
Location: Lincolnshire, UK
Posted: 3rd Mar 2005 07:42 Edited at: 3rd Mar 2005 07:43
@Evolved:
You shaders look good, but I can't download them! The site says something about the file being linked to from a seperate site and so access has been forbidden. Any workarounds?

I'd love to be able to have a look at your HDR shader, since I'm having a nightmare with the bloom shader I'm working on. I'm taking the same approach as you, by having multiple cameras, but I'm trying not to have them all render the entire scene. The plan is that the first camera takes the scene and blurs it on a plain, then the next camera takes an image of the blurred plain, and blurs again, etc, until it's smooth enough to be placed in front on the main camera.

I'm currently wrestling with the draw distances, and that's what's holding me up. I've got a nice shader that places a quad exactly in the screen coordinates, regardless of movement/rotation/FoV, but that means it always appears on all cameras. Fortunately, it still keeps it's original Z-depth, so you can 'move' it out of the cameras draw distance and it vanishes. With a bit of fiddling, I'm sure I can come up with something!

In the meantime, I've been working on a hair shader to use in a different project. It's not very realistic (basicly just anisotropic lighting), since it won't be seen close up very often, but I'm sure someone here could do something with it! I'll have that ready in a couple of days, along with the aforementioned 'texture-glow' shader, once I've got a semi-decent blur effect working!

Oh, yeah - and would anyone happen to want an orthographic view shader making? They're suprisingly simple, you know.
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 3rd Mar 2005 08:28 Edited at: 3rd Mar 2005 08:42
@evolved, thats a fantastic job! Specially the HDR one.

@Ninja Matt, the links work for me right now. (http://forum.thegamecreators.com/xt/xt_apollo_download.php?i=516532 and also http://myshaders99.50megs.com/index.html) Maybe you should take a look to evolved's approach, it has good results at a -I think- very reasonable speed (I'm talking about the HDR shader, it is very similar to bloom).

Unfortunately, it affects the whole scene, and not individually object by object, which could be undesireable in more than one situation.

Would a "what's an orthographic view shader?" count as a "yes, please"? Does it transforms the view to isometric-orthogonal? uh
Ian T
21
Years of Service
User Offline
Joined: 12th Sep 2002
Location: Around
Posted: 3rd Mar 2005 08:42
Quote: "Oh, yeah - and would anyone happen to want an orthographic view shader making?"


I would be

It is a perilous occupation for TGC to post anything by way of a promise, as the words get etched in indestructable marble for all time.
-Lee Bamber
adr
20
Years of Service
User Offline
Joined: 21st May 2003
Location: Job Centre
Posted: 3rd Mar 2005 17:12 Edited at: 3rd Mar 2005 17:12
evolved/ninja matt/any shader makers

I can create sub-accounts with my provider, so you'd actually have your own directory, login and password to FTP your stuff. If you want somewhere to mirror or even just store your shader pages, just shout.

I only have 500MB a month bandwidth, because it's effectively just a domain holder, temp file store and email provider. But since in theory, we'd only be shifting shaders, it shouldn't be that large a hit on my bill

Cheers and keep up the good work.

book is death - wife is stupid
Erick G
Retired Moderator
19
Years of Service
User Offline
Joined: 2nd Oct 2004
Location: Texas, USA
Posted: 3rd Mar 2005 18:49 Edited at: 3rd Mar 2005 18:50
I am also willing to host people, just give me a email

erick.grove at gmail.com

I will host you for free. That is the shader guys etc...

This is awsome work going on here, and I would love to help
EVOLVED0
19
Years of Service
User Offline
Joined: 1st Mar 2005
Location: UK
Posted: 3rd Mar 2005 22:16
@Ninja Matt

the only way to individual select objects to render to the camera is to clone the objects you want to render and position them way way off the main camera ( position object objn,0,200000,0 ). and then position the main img cam to the position of thos objects (position camera 1, main cam x, main cam y+200000, main cam z). if u get what i mean , i suck at explaining things . i had to do this for my bumpyrefraction shader so the object does not get renderd in the main img cam, so it can get the seen/back ground correctly..

or, or nag at the DBP team to make the dam show/hide object command better so you can "hide object objnum,camnum", this will then hide all the objects you dont want to renderd in that camera ..

is that what your after ??? if not i duno what your talking about lol only started messing with HLSL at the end of jan.

aslo @ volume shadowing
this would be so sweet to see in darkbsaic but as far as i know how this shading is done by altering the backbuffer.

type "Improving Shadows and Reflections via the Stencil Buffer by Mark Kilgard" in google , i read like the first line and thought bugger it

i think you can do Shadows volume thro shaders but you have to fill the pixels in your self through via unlock backbuffer command.

think thats how it done any way, or u can alway do shadow maps (there slow!!!)

or go to this site has a few nice explanation on it + a demo(not DBP)
http://www.ronfrazier.net/apparition/index.asp?appmain=research/advanced_per_pixel_lighting.html

how do you hilight links eh ?
Tartopom
19
Years of Service
User Offline
Joined: 27th Jun 2004
Location:
Posted: 3rd Mar 2005 23:55
@NinjaMatt

I'd like to see your orthographic shader. Sounds really interesting...
EVOLVED0
19
Years of Service
User Offline
Joined: 1st Mar 2005
Location: UK
Posted: 4th Mar 2005 00:49
@my last post
ignore it i just woke up and got a bit confused @ Morcilla
"Unfortunately, it affects the whole scene, and not individually object by object, which could be undesireable in more than one situation." so i thort thats what you wanted.

also
@Ninja Matt
duno whats up with the links then , tested it on my bros comp and thay worked fine

p43.0ghz,gffx5900ultra,1gigram
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 5th Mar 2005 02:41 Edited at: 5th Mar 2005 03:50
@Evolved, very good job for only one month of playing around.

There was another "whole scene" glow effect (non-shader) here:http://forum.thegamecreators.com/?m=forum_view&t=45364&b=6 (to highlight the link just mark it with the mouse and press the "http://" button).

Anyway your results have a much more professional look.
I suppose that a workaround for one single object would be:

- Hide everything except the object that has to glow with HDR.
- Call the HDR to render the scene (your update_HDR function).
- Show hidden objects (not affected by HDR).
- Sync.

You made me figure that out (I guess this also would work with the non-shader glow).

[EDIT]: Well, I tried the workaround and it doesn't work Don't know why at the moment...
EVOLVED0
19
Years of Service
User Offline
Joined: 1st Mar 2005
Location: UK
Posted: 5th Mar 2005 05:31
@Morcilla

its cus its done through the set camera to image command and the shader it self. you can download the newer code to see how it done off my site if its working, as there is no include code functions.

also uplaoded refraction shader , but unfortunately you have to render the seen twice to take out the object that gets refracted, making it useless. this is a cool effect tho as you can give the effect of bumpy distorsion on the surrounding scene, it get used in this gen games (farcy/hl2/d3) for heat waves, explosons effect , and see thru bummpy glass effects (hl2 glass doors whooha).
Duffer
21
Years of Service
User Offline
Joined: 9th Feb 2003
Location: chair
Posted: 6th Mar 2005 05:36
where can I find the mystical shaders which cause water ripple etc... dont seem to be readily accessible...?
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 6th Mar 2005 21:34
@Evolved, what can I say, now those effects are C-O-O-L!
I'm taking a look at the code...
Neophyte
21
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: United States
Posted: 8th Mar 2005 08:44
@Mouse

I'm not sure if Neo, Ideajuice or NinjaMatt are still around...

I'm still here.

I've just been extremely busy lately. I'll probably start working on the last part of my FX tutorial series soon when I get the time. Don't know when that will be though.
Ninja Matt
19
Years of Service
User Offline
Joined: 5th Jun 2004
Location: Lincolnshire, UK
Posted: 9th Mar 2005 01:56
Waah! I can't get a decent bloom effect to save my life! I've got all the downsampling, blurring, and screen-aligned quadding in place, but I just can't get it to look right! The bloom is either so faint that you can't see it, or so bright it looks like the colours are all washed out... I'll keep at it and see what I can get done but, if I don't get anything done soon, I'll post the alpha-glow shader that I'm using. It basically just lets you control an object's sensitivity to light based on it's alpha channel.

For now, though, take a look at this (PS 1.4 minimum):


http://homepages.nildram.co.uk/~moonrise/matt/Thermal10.zip

Using all the techniques I've figured out trying to make the bloom shader, I've come up with a decent-looking and relatively inexpensive thermal imaging shader. It uses an array of four cameras but, fortunately, only one of them renders the scene - the rest just render a basic two-triangle quad. The first camera grabs a greyscale scene that has been prepared for thermal imaging by the textures (light areas hot, dark areas cold) and a fresnel term that makes surfaces pointing towards the camera warmer than those at an angle.

The output defaults to a 256x256 texture, which is then applied to a plain suspended a few thousand units away so it can't be seen by the first camera. The plain has a special shader applied to it that aligns it to the screen-coordinates (saves working it out in DB every frame) and blurs the image in the horizontal axis. The second camera sees only this half-blurred plain and outputs it to another plain, again isolated on it's own. The second plain blurs the image vertically (horizontal + vertical = full blur) for the third camera to see.

Output is again sent to a plain, this time with a shader that uses the greyscale image for a texture lookup. For thermal, white becomes red, grey turns into green or yellow and black goes to blue, although the lookup texture could be replaced to achieve lots of different effects. This fourth plain is used as the final output to the screen.

As well as the above, I've also included a basic "ImageNull10.fx" shader which is the skeleton code required to align a quad to the screen. If you want to make your own shaders to complement the other two, this is where you should start! The only thing you need to remember is that, when positioned at the same coordinates as the camera, a plain will appear approximately 1.4 units in front of the camera. Using this little trick, it's easy to choose what your camera will render - check the example to see how it works!

Hope you like it! I'll pump out a basic ortho shader soon!
EVOLVED0
19
Years of Service
User Offline
Joined: 1st Mar 2005
Location: UK
Posted: 9th Mar 2005 05:38
@Ninja Matt
Wow very nice , after seeing your shader i have a urge to make a glow effcet for ps1.4 hell ill have a go at it in ps1.0 . very very nice

@Neophyte
you seem to know what your doing (and i loved your original tutorials in the old thread), so im kinda stuck on trying to get HLSL cubemaps to work in dbp useing the texture object command. i need cubemaps for 60% of my shaders im currently working on

example:

cubemap fx-



dbcode-



(aso added this as an attachment)

as you can see when trying to load the effect as " load effect "cube.fx",1,0 " (so dbp uses its own textureing ) the textures mess up is there away round this ? thx

(sorry if the code samples mess up - new to the forum)

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-04-20 01:43:03
Your offset time is: 2024-04-20 01:43:03