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 / Shaders Not Showing

Author
Message
MateiSoft Romania
10
Years of Service
User Offline
Joined: 16th Oct 2013
Location:
Posted: 17th Dec 2014 22:45
I had made a shader in Dark Shader i exported with an example code but in the example code it doesnt show the shader like in Dark Shader please see the attached file

Alex Matei CEO
www.alexmatei.com

Attachments

Login to view attachments
WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 18th Dec 2014 01:55
My graphics card doen't support pixel shader 2a, so I'm unable to test the shader light arrays. But, it would look to me your not passing the shader any light or any default light set up in the shader.
Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 18th Dec 2014 11:14 Edited at: 18th Dec 2014 11:20
I got some shader support here, so had a look.

Your program is valid but insufficient for this kind of effect.

You need to set the ambient light in the shader from pitch black to something slightly brighter. This is required by your normal mapping algorithm to see any texture on your objects.

You also need to specify the number of lights, and their properties. The code I have posted will demonstrate something similar to what Dark Shader has done to make things work. Use my function in your project and expand on it.



This is a good shader for learning the basics, try to have a read of the shader code to get a grasp of what all of the properties are doing.

Later on you could attempt to improve it or try out some of Evolveds shaders on his website or the shader library here, the normal map shader you have used is not the best out there which tend to use some kind of cubemap reflection and height map.

Check out some of my early shader tests a few years back and do a search on normal mapping in the forums to see what others have come up with for inspiration.

MateiSoft Romania
10
Years of Service
User Offline
Joined: 16th Oct 2013
Location:
Posted: 19th Dec 2014 14:40
I see and this works only for dbu(the code) ?

Alex Matei CEO
www.alexmatei.com
MateiSoft Romania
10
Years of Service
User Offline
Joined: 16th Oct 2013
Location:
Posted: 19th Dec 2014 14:41
dbs i meant sorry

Alex Matei CEO
www.alexmatei.com
Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 19th Dec 2014 21:22
The effect vector element commands are from the included Dark Shader library. Did it work for you?

MateiSoft Romania
10
Years of Service
User Offline
Joined: 16th Oct 2013
Location:
Posted: 19th Dec 2014 21:28
Your example worked perfectly for that specific object, i have an editor so i must import multiple objects so the shader must be universal i must use the .fx file right?

Alex Matei CEO
www.alexmatei.com
Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 20th Dec 2014 16:06
That's right, use the same shader be it .fx or .dbs on all of your objects with similar characteristics; you can use as much textures as your hardware permits the program to run, but keep the shader count low because they can take long to load and can get unstable.

MateiSoft Romania
10
Years of Service
User Offline
Joined: 16th Oct 2013
Location:
Posted: 20th Dec 2014 19:13
Well i exported the fx file from Dark Shader loaded into my editor but it looks black like the dbs file before your code, do i need a rechange of that code?

Thank You!

Alex Matei CEO
www.alexmatei.com
Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 22nd Dec 2014 10:45
It is black because by default, the shader sets all the lights to black with 0 range, and the shader's ambient light is also black.

What I did was set the brightness of your lights, and you will need to do the same. In addition to that, you also need to tell the shader how many lights you want it to render.

The way that the shader has been coded, you set the shader technique which inturn sets the number of lights.

Simply add my functions to your project, and call them when you load your shader; use my for loop in the example to specify the number of lights.

I recommend you use my code as a template; load all of your objects before the main loop; set them to the same shader, apply your textures accordingly and call an update function containing your program code.

MateiSoft Romania
10
Years of Service
User Offline
Joined: 16th Oct 2013
Location:
Posted: 22nd Dec 2014 11:24
I see, ill definetly try that but loading the objects before the loop it violates the application's rules because my app lets the user choose the objects so in the main loop is done. I have minor problem with Dark Lights and a question, does Dark Lights work with this kind of shaders?

Thank You very much for your time!!!

Alex Matei CEO
www.alexmatei.com
Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 22nd Dec 2014 12:42 Edited at: 22nd Dec 2014 12:45
Quote: "does Dark Lights work with this kind of shaders?"


Yes, and no lol.

The no is the fact that Dark Lights will not know anything about the shaders; its functions feature no shader functionality.

The yes is your shader can be programmed to use Dark Lights lightmap textures. You simply need to give your shader the lightmap and perhaps some information about the dark light entities.

What you can do to start off with is add an additional texture stage in the shader which should be the same stage Dark Shader uses to light up your objects.

For simple scenes or for testing purposes, you can blend this lightmap texture, using its own UV coordinates; with the base texture and normal map in your shader.

A more advanced procedure is the use to bind your shader's lights to the nearest 'Dark Light', so to say; your shader can then use the lightmap as a guide for the light sources and shadows which need to affect the bump mapping algorithm in your shader's light update for loop. This will improve the way your bumps are affected by the lightmap.

If you have not yet played around with shaders and HLSL, you will want to do that first before taking on this complex task. It is not as complicated as it sounds, you simply need to give your shader information about the dark lights and the lightmap itself.

Quote: "ill definetly try that but loading the objects before the loop it violates the application's rules because my app lets the user choose the objects so in the main loop is done"


You can load your objects when ever you wish; and apply shaders on them without any performance hit. What causes the performance hit is loading (and compiling) the shader; therefore it is the loading of the shaders which should be done outside of your main loop. You can compile your shaders to assembly with Dark Shader; or the FXC.exe file from the DirectX 9.0 SDK; this will in the best case scenario, speed up the shader loading functions.

MateiSoft Romania
10
Years of Service
User Offline
Joined: 16th Oct 2013
Location:
Posted: 22nd Dec 2014 13:09
Oh man, i understand all what you said, but sorry for asking, do you have an example code for doing this? really... its just that i am not so familiar with the shader implementation and modifiying it in darkbasic... thank you again!

Alex Matei CEO
www.alexmatei.com
Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 22nd Dec 2014 16:23 Edited at: 22nd Dec 2014 16:27
Sort of, but not ideal for you. The source code I have for my project uses my game functions, and many thousands of lines of code, it would take all day to get it to run without my game files.

It is best if you find a small example on the forums; otherwise you will have to do your own thing.

If you want to make your own lighting engine then start out with one of the Dark Shader examples, find out what texture stage is used then implement it in the shader.

Here is your shader:


Here is a walkthrough your texture stage implementation. Any texture applied on your objects will be referenced through here by your GPU.

It indicates no stage index, but its order within your shader program determines what texture stage it uses; the first sampler uses stage zero, and the either uses stage seven.

You can change the name of the texture, sampler and default resource file.



In terms of your normal map shader, this is what each pixel starts out as: float3 color = AmbientColor;

They are the ambient colour, the reason why your box was black is because by default AmbientColor is {0,0,0}

Here is the texture colour: float4 texColor = tex2D( diffuse_smp, IN.uv );

And here is the final colour of each pixel: return float4(color,1.0) * texColor;

Add your lightmap colour to the texture colour to see what happens;

EG: texColor += lightMapColor;

or perhaps: textColor *= lightMapColor;

But there must be a lightmap texture supplied for this to work, and the 4th vector element represents opacity.

Generally, colours in HLSL range from 0.0 - 1.0; At this stage the result will not be properly constrained but will suffice for now.

For early testing purposes, you could set the object's lightmap texture to some test image.

I still recommend using a better normal map shader, this one will not give you the best results.

MateiSoft Romania
10
Years of Service
User Offline
Joined: 16th Oct 2013
Location:
Posted: 22nd Dec 2014 21:57
I understand, well, here is the shader the .fx shader, i dont see an adjustable AMBIENT LIGHT though to see the texture from the cube. If i am texturing the object with this shader, the texture file name i assume that will be automatically changed in the fx file right? I am putting stupid questions to make some connections in my of how the shader file works.

Download attached!

Alex Matei CEO
www.alexmatei.com

Attachments

Login to view attachments
Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 26th Dec 2014 18:26
These questions are not stupid; nobody is going to grill you for asking the kind of questions you are asking. lol.

Quote: "If i am texturing the object with this shader, the texture file name i assume that will be automatically changed in the fx file right?"


Your shader will apply the textures assigned to it if you request it to do so using the Load Shader command; otherwise when you apply textures to objects, these image assignments do not change anything about the shader or its source code. All objects assigned to the shader can use different textures (and should).

The ambient light property is this: float3 AmbientColor : AMBIENTCOLOR;

The example I gave you shows you how to set the ambience. You can also initialize the shader constant in the shader (.fx/.dbs) file with a default value like so:

float3 AmbientColor = {0.2, 0.2, 0.2};

If you read up on a little HLSL and the C programming language; just a few introductions to the languages, it will help you to navigate and interpret the shader program more easily; indeed C has little to do with HLSL, but features similar syntax and has more documentation.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 31st Dec 2014 12:17
Quote: "If i am texturing the object with this shader, the texture file name i assume that will be automatically changed in the fx file right?"


I would strongly advise against relying on the texture flag working as intended/expected since it seems that errors can occur if you try to change the textures in DBPro.

Just use load effect "myEffect.fx", 1, 0 and load or create all your images in DBPro and assign them to the correct texture stage in DBPro. The only thing to watch out for is that DBPro texture stages correspond to the order of the texture declarations in the shader. So, for example, texture object 1, 0, 2 will assign image 2 to texture stage 0 of object 1 and, if a shader has been applied to the object, the first texture declared in the shader will therefore be assumed to be image 2. Similarly an image applied to stage 1 in DBPro will correspond to the second one declared in the shader, and so on.



Powered by Free Banners

Login to post a reply

Server time is: 2024-04-27 02:27:41
Your offset time is: 2024-04-27 02:27:41