PDA

View Full Version : How to change material texture upon being hit by light



SethNemo
10-18-2011, 01:19 PM
Hello guys,

So, easy question but I haven`t found an answer after going through the google and Forum-Search routine so I guess the answer is more complicated. (Forum search gave me 1 result and the last post was by the thread starter who gave up on this problem ^^).

I want to create a material that changes its visual conditions when it gets hit by light. (like: no light means glowing cracks and light means seamless concrete). I know I need a lerp for this and also have the two inputs ready. I tried to play with the LightVector node on the alpha wich gave some funny but useless results. Haven`t tried it with a custom lighting solution, but I`m also hoping I don`t need to because I want to use this material on a rather big map.

Has someone tried this before or has some valuable hints were to look? I`d appreciate any help I could get :)

If this isn`t possible i`d be also interested in knowing if I can change a material based on the position of a volume so I can work around the problem by using that.

Edit: I think I might be on to something if I calculate the light vector together with the camera vector but my understanding of the mathematics involved is not high enough yet. But maybe there is also a way easier solution and I`m just error-blind. Anyways, I`ll try to test a few things on thursday (sadly my laptop doesn`t run UDK so I have to use a PC at one of my jobs...) and it would be really cool if you guys could help me out a bit while doing a "possible solutions list" :) I`ll share the finished material layout to give you a little something in return. ;)

thanks,

rjmyth
10-20-2011, 07:37 AM
my first thought would be. depending on whqat you wanted to do when the light hits...

in my case, i would be ok creating a decal if the player is facing a relevant wall or maybe within a volume and looking at the piece of wall.

the other way might be to fire a trace in the direction the player is facing and if it hits the correct material, change is how you want.

ambershee
10-20-2011, 09:09 AM
You probably want to look at using 'custom lighting' within the material. There are resources on the UDN.

SethNemo
10-20-2011, 06:13 PM
Thanks you two.

@ambershee: Yeah, that did what I wanted. It was also simpler than I thought. :)

Now, IŽve got the thing working on a rather rough level. It has a lot of growing pains, not to mention that it isnŽt that useful right now. I need to get a better control over the different elements wich will require a lot of finetuning and clamping and playing with values. I need to have the wall receive a little bit of lighting before the lerping actually happens. But IŽll try to work something out.

I want to let the emissive cracks "leak" into the lit area but to do that I must be able to control a falloff. Maybe I can work around this with a light function (wich I need anyway if I want to have a good looking maglight cone.) and having the falloff inside the functions texture. Right now the effect isnŽt very visible. I couldŽve also just plugged a Diffuse and a dim emissive in and wouldŽve almost the same effect. I might get it more prominent by lerping between different normals, tessellation levels or parallax offsets. This will have to wait till tuesday when IŽm back infront of a running UDK. Maybe I should plug a parallax occluding shader in but that wouldnŽt be very elegant or efficient. xD

Also the mesh does block the light, but it doesnŽt block the effect itself. Light basicly shines through (wich could be used for some very nice things in the future but right now it is a bit troubling.)

Other thing for wich ther might be an easy workaround: Now what if I donŽt want the light bouncing off the material (getting a bright spot instead of just the texture) but still want the material to be influenced by the light? Like my light is "turned off" while it actually isnŽt? @rhmyth: The thing with tracing might work here. Some say this might be rather expensive on the hardware but idk.. Anybody has some ideas if there is an elegant way to do this? IŽll try to find some clues on the net. This should be possible somehow...maybe I could just make the light very bright but change the color to black or adjust the alpha or whatever but that also has to wait till tuesday.

So, thanks for the help so far, IŽm quite happy with todays results. :) Here is the material in its current state.

http://i5.photobucket.com/albums/y162/corky13/Lightmat.jpg

SethNemo
10-25-2011, 06:24 PM
I promised to keep you updated. I found a way to do this without custom lighting, but IŽll either go back to that or to using this exclusively on decals. It works nice on a solely technical level but with some not so nice boundaries. IŽll do some more work on thursday. Right now IŽm happy to have found at least something were it is actually usable...blacklight evidence like fingerprints at crime-scenes. IŽm sure there is a more elegant way to do this though. SO I have to find a more "crazy" usage like "black glass" stones and you can see bubbles when you point a light "inside" it or something. Here is a 5sec test shot:

http://www.youtube.com/watch?v=Nkp_zSDRei8

Now what I really like to do, and I fear that I have to go another route for this, is that I make this work without raytracing or light vectors, but with an invisible volume/lightshaft-mesh and make the material dissolve "on impact". IŽd really appreciate any input and IŽm happy to share what I get out of this. :)

EDIT: Seems my best bet is to jump over my shadow and learn some unreal script in order to work with hit masks. Might be exactly what I need.