constant shader in DirectX material

About Truespace Archives

These pages are a copy of the official truespace forums prior to their removal somewhere around 2011.

They are retained here for archive purposes only.

constant shader in DirectX material // Archive: Tech Forum

1  |  

Post by Emmanuel // Jul 12, 2006, 3:48am

Emmanuel
Total Posts: 439
pic
I am trying to get a constant texture shader for DirectX/player display. I mean a material that simply shows a texture according to its UV map, with no regard to lightening.

I didn't found it in the libraries.

Once again, I tried to get into a DX material creation. But after one hour of spagetti cooking, my red nose and watered eyes definately said that all I developped was an allergy to the LE.


Any idea, someone ?

Post by Asem // Jul 12, 2006, 7:13pm

Asem
Total Posts: 255
I hope this is what you are looking for or at least close. I put it together myself and its DX material not lightworks. One is the material itself and the other is a scene example also it seems to work when the object is some short distance away from light. If the object appears under the light, it will have a shadow though.

Post by trueBlue // Jul 12, 2006, 8:57pm

trueBlue
Total Posts: 1761
pic
If you would like to disable the shadow it is possible. Select your object first. Open the Preference in the stack and click inside your scene. Within the Player - Rendering panel select the Show Object Attribs button, then within the Object Render Attributes panel under Default select Advanced and disable the Cast shadows option. If you go inside your object now you will have the Object Render Attributes panel in there as well.

Post by Emmanuel // Jul 12, 2006, 10:02pm

Emmanuel
Total Posts: 439
pic
Thanks for the replies :)

But I couldn't get the effect I am looking for.


@ Emma :

LW materials are for LW rendering ; in the player the shader is not a constant one.


@ Asem and TrueBlue :

Thanks for the files Asem. I tried this before. But the player always seems to take lightening into account (light intensity, colour and direction) : if the object is close to a colored light, then its texture will be colorized. If there is no light in the area, then it will be dark. With many lights around, the object will look overexposed. Turning off the cast/receive shadows options in object render attribute do not change anything for that.


The Player is supposed to be close to a game engine.

But in games engines, we often use constant materials for lights textures effects, particles, smoke effects, trees, etc...

Do you think that trueSpace's DirectX9 engine misses that feature ?

Post by Asem // Jul 12, 2006, 10:35pm

Asem
Total Posts: 255
I don't think its missing the feature rather we have the ability to create those features. Looking at the way Hlsl(itself) and ts7 Hlsl (Same but coded a bit differently in ts7) it's possible. Unfortunatly that is what me and others are trying to figure out. Hopefully someone finds a way to implement advanced stuff.


I tried again and this time it looks right. The light shouldn't effect to shader and it should still be lit the same way in shadow.

Post by Délé // Jul 12, 2006, 11:08pm

Délé
Total Posts: 1374
pic
It looks like your last one works pretty good Asem. It seems that it whites out when you're really close to the light source though.

I was messing around and came up with yet another way. I think this just goes to show the versatility of tS7. :)

I used the gooch2 shader and just filtered the texture/color into it's properties. Seems to remain constant in all instances so far as I can tell.

I have two materials in the zip. One is for just a plain color and the other is for a texture.

hth

Post by Asem // Jul 12, 2006, 11:28pm

Asem
Total Posts: 255
Nice Dele even can use highlights if wanted:D

Post by TomG // Jul 13, 2006, 4:56am

TomG
Total Posts: 3397
I think the trick is to replace the inputs in the shader that come from the shader input brick - this takes calculations from the light sources etc for its values, so it changes.


I found that I needed to replace three values - Diffuse Color, Light Color and Normal Vector. Replace those with constants rather than the shader input brick values, and everything becomes constant :)


See attached image. The color is controlled by Diffuse Color, Light Color seems to control the brightness of this "constant light" and the normal value is just there to avoid nothing showing up.


This shader was based on the regular "BlankDXMaterial"

Post by TomG // Jul 13, 2006, 5:18am

TomG
Total Posts: 3397
Working from the last shader, but adding the shader input back in and using the Eye Direction for both the lighting and eye direction, and adding the normal back in, we get a glow effect - that is, surfaces facing the view are bright, those facing away are dark.


In order to avoid the center of the glow being brilliant white, a little math was required on the normal, so a multiply brick was introduced.


The object is attached, but note that I havent named things nicely or exported values etc, it's just rough :)


Similar mods to the alpha channel should produce a transparent glow sphere for lightbulbs for instance.


Nothing "overlooked" in the way the real-time shaders work, just a matter of figuring out how to achieve the effect you want (and yep, there may be more than one way!)


HTH!

Tom

Post by TomG // Jul 13, 2006, 5:27am

TomG
Total Posts: 3397
Oh, these do change if they move around lights, how strange - they remain constant and unaffected by the light itself, but yep they do alter depending on whether there is a light near them.


How odd :)


They may still prove useful though.


HTH!

Tom

Post by TomG // Jul 13, 2006, 5:40am

TomG
Total Posts: 3397
Seems there is a "light count" going on and that the shader (or some part of it) is called multiple times, once per light. As it moves into the influence of another light, the actual intensity, direction, color etc of that light has no effect, but it causes the shader to run an extra time and add its results onto the previous.


So when it moves into and out of a spotlight's cone, it will grow brighter, as it becomes equivalent to running the constant shader again and adding the result to the other run (or runs) of the constant shader.


So the materials may be being called on a "per light" basis.


Investigating and will report with more info when available!


Thanks!

Tom

Post by michalv // Jul 25, 2006, 8:50am

michalv
Total Posts: 2
pic
It is not possible to create completelly constant shader in D3DView - each object only show pixels that react to the light. This means that even if you ignore light information (light color, direction...) in model shader and just output constant value it will display that constant value depending on the number of lights that affect the object.

Mathematically final_color = constant_color * number_of_lights;


As a workaround you would have to dim the constant color by number of lights affecting the objects (which also means that this number has to be tweaked every time object moves or light condition change)

Post by Emmanuel // Jul 26, 2006, 11:21pm

Emmanuel
Total Posts: 439
pic
Thank you Michal.

This helps a lot :)
Awportals.com is a privately held community resource website dedicated to Active Worlds.
Copyright (c) Mark Randall 2006 - 2024. All Rights Reserved.
Awportals.com   ·   ProLibraries Live   ·   Twitter   ·   LinkedIn