Home Unreal Engine

UDK Material Reflection behaviour similar to Marmoset?

polycounter lvl 11
Offline / Send Message
timotronprime polycounter lvl 11
So I'm trying to make it so that the Specular Texture would control the color of reflection as well as the intensity of reflections like in Marmoset.

I have my material tree set up like this so far:
ZqfECIypng

But it's not really where I want it at - does anyone have some tips on changes?

Thanks!

Replies

  • lpcstr
    Options
    Offline / Send Message
    For starters, you want to plug your environment map into the emissive channel, not the specular channel.
  • timotronprime
    Options
    Offline / Send Message
    timotronprime polycounter lvl 11
    lpcstr wrote: »
    For starters, you want to plug your environment map into the emissive channel, not the specular channel.
    Alright, what is the reason behind this?

    Intuitively, it doesn't quite make sense to me - appreciate an explanation to help me understand.
  • lpcstr
    Options
    Offline / Send Message
    The specular node is a parameter that is tied to the analytic lighting that gets calculated for every light in the scene. Environment maps are a hack to fake global illumination, they have nothing to do with the analytic lights. You need some way to squeeze the contribution of the environment map into the final pixel color, and you don't want it to be modified or modulated by anything else. That's the emissive channel in a nutshell. Lighting is calculated and accumulated from all light sources, and then emissive is simply added on to that.
  • sprunghunt
    Options
    Offline / Send Message
    sprunghunt polycounter
    lpcstr wrote: »
    The specular node is a parameter that is tied to the analytic lighting that gets calculated for every light in the scene. Environment maps are a hack to fake global illumination, they have nothing to do with the analytic lights. You need some way to squeeze the contribution of the environment map into the final pixel color, and you don't want it to be modified or modulated by anything else. That's the emissive channel in a nutshell. Lighting is calculated and accumulated from all light sources, and then emissive is simply added on to that.


    This is true ^

    Also if you're trying to integrate reflections into the specular path then maybe it might be better to do it by using the custom input and recreating the phong specular and combining it with the reflection.
  • timotronprime
    Options
    Offline / Send Message
    timotronprime polycounter lvl 11
    Thank you, I have multiplied the spec map with the cube map and plugged that into the emissive, which is half of what I wanted: the specularity of the object also controls the brightness of the reflection.

    Now, for the other half, I would hope for the SpecularPower (grey-scale Gloss map in the alpha channel of the Spec map as an alpha for a Lerp between 1-100) to also control the sharpness of the reflection and I have no clue on where to start on this as most of the math operations seem to only be able to affect its brightness.
  • lpcstr
    Options
    Offline / Send Message
    Thank you, I have multiplied the spec map with the cube map and plugged that into the emissive, which is half of what I wanted: the specularity of the object also controls the brightness of the reflection.

    Now, for the other half, I would hope for the SpecularPower (grey-scale Gloss map in the alpha channel of the Spec map as an alpha for a Lerp between 1-100) to also control the sharpness of the reflection and I have no clue on where to start on this as most of the math operations seem to only be able to affect its brightness.

    I'm not really sure what you are asking. If you are asking how do you make your environment map work with your gloss map, the answer is that there is no good answer. Epic failed big time in that regard. If they wanted to make amends they would add support for cubemaps as inputs to custom nodes and they would add a DDS file importer (with support for cubemaps of course) that preserves mip chains. Then you could store various levels of gloss in the different mip levels and use your gloss value as an input to tex2Dlod.
  • lpcstr
    Options
    Offline / Send Message
    I suppose you could always fake it a bit. Have two environment maps, one for the highest glossiness and one for the lowest, and lerp between them.

    I would also recommend you not use UDK's default lighting. It's crap.
  • timotronprime
    Options
    Offline / Send Message
    timotronprime polycounter lvl 11
    lpcstr wrote: »
    Then you could store various levels of gloss in the different mip levels and use your gloss value as an input to tex2Dlod.
    That is essentially what I was looking for.
    lpcstr wrote: »
    I suppose you could always fake it a bit. Have two environment maps, one for the highest glossiness and one for the lowest, and lerp between them.
    That is a solution I hadn't thought of yet and it sounds like it'd work reasonably well. I'll get to testing it soon.
    lpcstr wrote: »
    I would also recommend you not use UDK's default lighting. It's crap.
    Default lighting do you mean the default settings for the lights? Or the "Morning/Afternoon/Night" Preset levels?
  • lpcstr
    Options
    Offline / Send Message
    Default lighting do you mean the default settings for the lights? Or the "Morning/Afternoon/Night" Preset levels?

    I mean the built in Phong shading. Here is a custom lighting shader and an example of how to use it.

    http://dl.dropbox.com/u/48657892/CustomLighting.upk

    A quick rundown on the parameters.

    Roughness: This is the equivalent of "glossiness", but unlike Phong, bigger number = more rough. The range of this is parameter is technically (0, +inf), but most common materials are going to be in the rage of (0, 1].

    Diffuse: This is the diffuse albedo, pretty self explanatory. Be careful to use realistic values. Very few materials have an diffuse albedo > 0.6ish.

    Specular: This is the specular albedo, equivalent to the amount of light that gets reflected at normal incidence. This value can be calculated based off of the material's index of refraction. Example:

    Glass IOR = ~1.54

    Specular albedo = ((1.54 - 1) / (1.54 + 1))^2 = ~0.0452

    You may find some more insights by reading this blog: http://seblagarde.wordpress.com/2011/08/17/feeding-a-physical-based-lighting-mode/
  • timotronprime
    Options
    Offline / Send Message
    timotronprime polycounter lvl 11
    I took a look at the CustomLighting provided and have a few questions:

    Is the package you linked to also a PBR shader like in the blog?
    Seems similar effect.

    Instead of the flat colors, looks like the CustomLighting shader will translate sRGB textures as well?
  • lpcstr
    Options
    Offline / Send Message
    Is the package you linked to also a PBR shader like in the blog?

    Indeed, it's a variation of Cook-Torrance and Oren-Nayar. UDK actually works with linear RGB values. By default, texture samples get converted from sRGB -> Linear RGB. So, for example, if you wanted to make something copper you could use the values from the blog (0.955008, 0.637427, 0.538163) in a constant node. However, if you wanted to put this in a specular texture, you would first adjust the values from linear -> gamma, the from the range [0, 1] -> [0, 255] like so:

    (0.955008, 0.637427, 0.538163) ^ (1/2.2) * 255 = (250, 208, 192)
  • pmlvl
    Options
    Offline / Send Message
    Very usfull informations, TY Guys
  • [HP]
    Options
    Offline / Send Message
    [HP] polycounter lvl 13
    This is extremely interesting.

    I tried it, and all I get is black, (other than the surfaces that are being hit by direct sun) any idea how to work around it or what I'm doing wrong?
    Do you have to use a env cubemap to get the ambient light from?
  • MooseCommander
    [HP] wrote: »
    This is extremely interesting.

    I tried it, and all I get is black, (other than the surfaces that are being hit by direct sun) any idea how to work around it or what I'm doing wrong?
    Do you have to use a env cubemap to get the ambient light from?

    Try also plugging your diffuse into the CustomLightingDiffuse slot.

    I'm also having some issues with the material in DX11 mode - lots of artifacting on the corners.
  • Jakob Gavelli
    Options
    Offline / Send Message
    Jakob Gavelli interpolator
    This is pretty cool. Can't quite get the customlighting to work though. I seem to have the same problem as [HP]. Only the areas directly hit by the DominantDirectionalLight make use of the shading, it ignores all other light sources and the cubemap plugged into the emissive just makes all the dark areas look like mirrors. Twisted horrible mirrors!

    If I do as MooseCommander suggests and plug the diffuse into the CustomLightingDiffuse aswell as the Diffuse slot in the customlightning, only the areas hit by the DominantDirectionLight make use of the custom shading.

    Maybe I'm forgetting something but if it only works on the surfaces hit by the DominantDirectionalLight I don't know how to use it. =(
  • Ace-Angel
    Options
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    I think I can see what the confusion is in here, you peeps should take a step back, relax, and just think logically for a second with the names and what they do, so it's becomes easier to take in on how materials work in UDK (any shader for that matter).

    CustomLighting is where you put in your lighting (like Lambert, Oren Nayar, etc) term, it essentially the equivalent of LightPerPass function of your average shader. This part will ALWAYS show whatever you put into it, from the light position, as long that is what you want (and should be).

    CustomLightingDiffuse is your Ambient/Diffuse slot, where you put in only your Diffuse and/or with Ambient Map. This one won't interact specifically with the light source, UNLESS you write a specific term for it.

    The difference is one will react to light, other won't, the other is like the ambient/core color of the mesh. If you want it even more simplified, one is ontop of the other and replaces/merges with the other when it sees light.

    Put two different colors in each slot and you will see what I mean, best way to understand what they do.

    Emissive is...what the name says literally, your emissive/glow slot. If you put a cube map in here, it's going to 'glow' the cube on your mesh as a fully lit source map, hence why you plug your cube and/or with ambient in here if you wish to take 1:1 value of your map without relying on the light source.

    The second confusion here is that cube and ambient maps are supposed to be the replacement of your Specular and lighting quality term, and you guys are using generic maps in environments that won't work with them properly.

    Both of them can be used and mixed, but you need to make sure both of the terms being used aid each other, and don't fight each other.

    Think of it this way, if you character is in a cave, you cube and ambient map NEED to reflect the environment you're in, putting on the map of a skyline on the beach inside a cave doesn't make sense, and parts of mesh that are supposed to shadowed for physical correctness (like the bottom, and part facing inside the case) will glow and be blue, instead of dark brown or such.

    Ambient especially is important to be correct here.

    If you can't be bothered to create the proper maps, then you will be limited to used a Specular term, simple as that, the reason Specular terms aren't put into the emissive is because they will glow all over the mesh, even in the dark parts, and UDK doesn't take Light Vector into the Emissive slot.

    Lastly, make sure you take a moment to read the UDK wiki, CustomLightDiffuse is explained that it's also shadowed, so meaning it will show itself when being shadowed FROM the light source. You can push back the amount of shadow under the options in the material, called Shadow Bias iirc? Use small numbers however.
  • Santewi
    Options
    Offline / Send Message
    Actually, what you plug in the CustomLightingDiffuse does get a bit of shading if you plug in your normalmap in the Normal... It'll also affect the cubemap reflections automatically.

    But yeah, cubemaps (in emissive) are used for faking indirect lighting. And if your cubemap doesn't match the environment, it's not the shader's fault.
Sign In or Register to comment.