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
mr Handy
16
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 1st Aug 2012 10:16
I call the mighty Green Gandalf here !!! Please

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 2nd Aug 2012 01:51
Had a quick look at that thread and Diggsey is already answering your questions.

Quote: "I don't have any experience of RGBA32 textures"


Like Diggsey did on your other thread I assume you mean the D3DFMT_A32B32G32R32F format. If that's not what you mean then please explain. I won't be able to look into this for a few more days yet.
mr Handy
16
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 2nd Aug 2012 09:29 Edited at: 9th Aug 2012 13:43
Thank you for your quick look!

I have two threads about shaders:
1. http://forum.thegamecreators.com/?m=forum_view&t=196344&b=1&msg=2382431#m2382431
Is about semantics, last post is fresh and detailed.
2. http://forum.thegamecreators.com/?m=forum_view&t=199105&b=1
This thread is (in the end) about how to "pack" RGB into R channel.
Although, wikipedia says, that 16 float is unacurate with rounding down decimal part. And 32 float is better, but online calc shows that if I pack RGB into R as 9-digit RRRGGGBBB, BBB will be inacurate, and can't take value of 100. I.e. 100100100 will be 100100996, and I think that's bad for packing normals.
What do you think?

Xystus
20
Years of Service
User Offline
Joined: 2nd Sep 2003
Location:
Posted: 21st Aug 2012 01:01
Is there a normalmap, bump, or parallax shader with support for darklights lightmaps? I tried to modify the ReliefMapping.fx from evolved with no luck.

How to add the stage 1 with darklights lightmaps to a shader?

Original:



and my modification



Thanks and sorry for my english
Xystus
20
Years of Service
User Offline
Joined: 2nd Sep 2003
Location:
Posted: 22nd Aug 2012 14:31
Well i did it and now works very well.
This is the shader:

david w
18
Years of Service
User Offline
Joined: 18th Dec 2005
Location: U.S.A. Michigan
Posted: 5th Oct 2012 22:58
I have a quick question on combining textures in HLSL. What is the best method to do this? For example I want to blend two textures together but it never seems to give a correct result. Usually I get what amounts to a washed out look. What can I do to prevent this?

Normally I would do something like these examples but I never quite get what I want.

lerp(img1,img2, 0.5);
img1 *= img2;

Then it gets worse when I try to combine multiple images. Any Ideas on proper image combinations?
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 6th Oct 2012 02:46
It rather depends on what you're trying to do.

Your first method will give the average of the two images which will usually result in a slight loss of contrast. You can correct for that in the pixel shader code but the details are a bit fiddly. I've done that with reasonable results in some of my shaders. "Lerping" tends to give best results when the lerping constant is read pixel by pixel from a black and white masking image. i.e. the lerping constant is close to one or zero. In that case there's no loss of contrast.

The second method will usually be darker than the two source images. You can correct for that to some extent by brightening the final result - simply doubling the result might work if the source images are roughly mid grey for example. An exception will be where one is a light map and the other is the base texture - in that case your second method will usually give the correct result.

So we're back to my first question: what effect are you trying to achieve?
david w
18
Years of Service
User Offline
Joined: 18th Dec 2005
Location: U.S.A. Michigan
Posted: 6th Oct 2012 04:18 Edited at: 6th Oct 2012 04:40
I'm gonna take a few screenshots and I will post them and hopefully I can explain what I am talking about.

//this image is to dark - notice the lack of stars in the sky


//this image is way to light - notice how washed out everything looks


What I have is a lightmap + colormap + fogmap + raymap

I am trying to combine these in a single shader but I am having problems getting them the "mesh / blend correctly together.

If I try to blend the colormap outside of the lightmap shader it gives me a very washed out look but if I blend it inside of it I have to multiply this this:

float3 DiffuseColor = color *(light ) *Color;
float4 final = float4(DiffuseColor + (specularLight),1);
return final; //this will produce a very washed out image

However if I return
return final*final; //this produces the "to dark" image

Does this help to clear up what I am trying to accomplish?
Thank you.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 6th Oct 2012 15:51
Quote: "Does this help to clear up what I am trying to accomplish?"


Somewhat.

Your scene seems to have several different things in it. For example, how are you rendering the sky and the ground? Are they using the same shader or different shaders?

Some questions about your snippet:

1. What are the variables "color" and "Color" and why are they multiplied together?

2. What is "light"? Is it the total diffuse lighting as in a lightmap?

3. Which variables are the ones you refer to, i.e. "lightmap + colormap + fogmap + raymap"?

4. Are you using TWO lightmaps, i.e. specular and diffuse?

Leaving aside the raymap for the moment, I would expect the shader calculations to mimic what happens physically. For example, the lighting, i.e. specular and diffuse, affect the surfaces of objects. That light then passes through fog before it reaches the viewer. So I would first calculate the net effect of the lighting on the surfaces as seen by the viewer without fog, then apply the fog. So you might have something like this:



So non-reflective and fully reflective surfaces would have surfaceReflectivity = 0 and 1 respectively (or you could have a specular map giving values in between). Similarly, fogDepth should be zero if there's no fog or 1 for full fog with a fog map giving values in between.

You could argue that the light reaching the surface also has to pass through fog so should be fogged as well. That's possibly an unnecessary refinement though.
david w
18
Years of Service
User Offline
Joined: 18th Dec 2005
Location: U.S.A. Michigan
Posted: 6th Oct 2012 21:20
I'm gonna try to anwser your item's and also try to implement your suggestions and yes the light is suppose to affect the fog. The point lights however are not affecting the fog as it is passes through. I think I need to pass the fog as a texture to the lighting shaders and blend based upon depth, however I am not certian about this.

1. Color is the "worldColor" basically the world drawn without any lighting, only texture data. With specular information stored in the alpha channel. And color is the color of the direction light. I suppose that I should have used a better naming system because it can be confusing. I was combining them this way as to affect the final computed color. Now that you point it out, this does not make sense, but at the time I it did.

2. light is calculated in this way which I think is fairly standard.
float3 lightVector = normalize(lightDirection);
float3 light = saturate(dot(lightVector,normal));

3. Each variable is a render target with the information that has been calculated and now needs to be blended together for the final output of the scene as the viewer will see it.

4. There is only one overall light map that contains the combined directional, point, and specular lighting information.

I am going to try to rework the approach to mimic what I think you have described. I've always had great success working with your ideas in the past and hopefully this will be the same.
Thank you.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 6th Oct 2012 21:36
Quote: "Color is the "worldColor" basically the world drawn without any lighting, only texture data. With specular information stored in the alpha channel. And color is the color of the direction light."


I thought that might be what you meant but wasn't sure - and yes it is VERY confusing. I'm sure you'll be as confused as I was if you look at that code after a time gap of a year or two .

Quote: "There is only one overall light map that contains the combined directional, point, and specular lighting information"


That doesn't seem quite consistent with this bit of your code:



where they seem to be calculated separately.

Anyway, let me know how you get on and I'll see what I can do.
Green7
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: Switzerland
Posted: 10th Oct 2012 01:53 Edited at: 16th Oct 2012 14:17
Hello

I got a problem with a naormal map shader from the shaderpack. i guess its old stuff, but it works fine. or nearly fine. as it seems the light is calculatet for the first object an then it is the same for every following object. this means, if I displace a object it is still lit as it was in its old space.
I think it is a global / local thing... I searched this thread, but reading in a foreign language is hard, so it could be I missed the clue. I'm an artist, not a coder, so I fail in changing the shaders code. please, can someone have a look at the attached demo and maybe find a solution? Thx in advance!

ps: I use this shader for it has multiple lights and a specular map. I plan to combine it with a light map. I did this once before, but my data is lost, so I have to restart. if there is a better solution for 4 dynamic lights, please fear not to tell me.

EDIT: nevermind. after a week i sorted it kinda out, found a better shader.

Attachments

Login to view attachments
mr Handy
16
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 25th Jan 2013 15:52
Green Gandalf, hi! I have posted the source in my thread!

*** Merry Chuckmas! ***
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 26th Jan 2013 00:16
OK. Just been away from the forum for a few days.
mr Handy
16
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 30th Jan 2013 21:45
If you will have time to see source, please post your thoughts there.

*** Merry Chuckmas! ***
mr Handy
16
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 15th Feb 2013 19:20
@Green Gandlaf

Hey hey hey, are you still here?

*** Merry Chuckmas! ***
wattywatts
14
Years of Service
User Offline
Joined: 25th May 2009
Location: Michigan
Posted: 29th Apr 2013 20:02
It's been a while so I don't know if anyone's still around this thread or not but @Xystus, your relief+lightmap mod is awesome, but how do you use it with various objects & textures? I mean if I have the ground and a tree they would optimally use different textures so they can be scaled, but wouldn't this necessitate loading the models separately, = light maps wouldn't work? I really want to use light maps with bump, but totally confused.

http://mattsmith.carbonmade.com/

Login to post a reply

Server time is: 2024-03-19 09:13:41
Your offset time is: 2024-03-19 09:13:41