Home Unity

Unity Shader(Normal Rim light)

polycounter lvl 17
Offline / Send Message
seforin polycounter lvl 17
Hey everyone.

so I am working in unity and im trying to re-create a shader in there...and honestly ive been a bit stumped on this one.

the idea is to make a rim light that is also effected by the direction of the normal map (3 point shader does this and plenty of game engines do this to)

unity offered this one bit of code that has what I want.

http://www.unifycommunity.com/wiki/index.php?title=BumpSpecRim


But I am using the unity plugin "strumpy" to achieve these results.

my current shader is setup to have a object pan based off a time And a alpha on it thats being controlled my a master lerp over the normals + alpha itself.

Anywho so asside from that this shader is pretty standard down the board. But every time I try to use my shader with the new rimlight values I get a error, but if I have nothing else in my node network asside from just the normals and the normals setup it works exactly as I want.

I have the 2 examples attached in the following zip. Along with the Textures I am referencing ....seriously any help would be a LIFE saver right now


NOTE: You need Strumpy's node based editor plugin to see this!


http://dl.dropbox.com/u/11483203/SlimeTEsts.zip

Replies

  • Farfarer
    I have no ide what you're on about with object pan based on alpha and time.

    But what are the errors in the console for your shader? I haven't used Strumpy before but I've written a fair few in straight up CG.
  • SanderDL
    Offline / Send Message
    SanderDL polycounter lvl 7
    I'm also a bit lost at what you are on about. Anyway I hope I fixed it for you:

    http://dl.dropbox.com/u/6325410/SlimeShader.unitypackage

    I just loaded in the Rimlight example that came with the Strumpy shader plugin. Then I added in a Texture driven diffuse and a normal map. I also made sure the normal map was also connected to back end of the Fresnel so that it takes the normal map into account.

    I hope this is what you need.

    PS: The specular map needs to be inside of the alpha channel of the diffuse texture for it to work.
  • seforin
    Offline / Send Message
    seforin polycounter lvl 17
    Hey Snader Thanks

    That is what I wanted but I think I kinda figure out Why it wasnt working.

    I did the same thing before plugging in the normals result to the fresnel normal but my display became pink and gave me a error.

    so I used your example adn started to rebuild my shader little by little how I wanted.


    So originally my shader did the following

    Took Diffuse , spec and normal

    Allowed me a slider controler for spec intensity and gloss

    My uvs panned on the X at a speed I set as a value (.5 in this case)

    And I had a fresnel rim light that I wanted to effect the normals of the model.

    Finally I had a Alpha set on this entire model which was being controlled by a lerp infront of Emissions and Normal because plugging in a straight value into the alpha channel slot and setting it to off (zero) the model still displayed normals and emission. So I had to trick it and place a lerp with a float 4 constant set to zero and a controller between the 2 for the alpha value.

    So As I was rebuilding this shader 1 by 1 with your working fresnel I found the 2 areas that caused issues.


    area 1 is the panning uv's. Copying my same nodes over into the diffuse and spec gave a error, but if I have them working on the normal map panning absolutely fine. But trying to copy those nodes into the diffuse and spec and it gives a error.

    so I ignored that and went to the next part, which was setting up the alpha the same as before...but putting the lerp again to control normals/emission..and as soon as I plug them into it, I get the same error as before.



    so im a bit stumped again. I'll upload the latest shader if you wanna look at it.


    Oh also before you get confused I am flipping the normal map green chanel in the shader because all of our moels are being baked in 3ds max and need green flipped. (but this shouldnt be causing any sort of issues)


    Talon: to give a precise answer its giving the same error being.

    Implicit From "float 4" to half3 at line 142

    (but honestly im not sure what that means :S)


    EDIT:annnnnnnnnnnnnnnnnnnnnnnnnnnnnd all the issues where from me not having shader model 3 enabled..go me.
  • LoTekK
    Offline / Send Message
    LoTekK polycounter lvl 17
    float4 to half3 means you're trying to cast incompatible value types. In this case, it's likely something along the lines of:
    float3 rgbVar;
    float4 rgbaVar;
    rgbaVar = someStuffHere;
    rgbVar = rgbaVar;
    

    In which case you could change the last line to
    rgbVar = rgbaVar.rgb;
    

    float and half are just different precisions, float having more bits to represent a number than half.

    Scalar Types (DirectX HLSL)

    Haven't had a chance to look at the node network yet, but if it's still giving you trouble I can take a look when I'm home tonight.
  • Farfarer
    seforin wrote: »
    Talon: to give a precise answer its giving the same error being.

    Implicit From "float 4" to half3 at line 142

    (but honestly im not sure what that means :S)
    It's trying to make 4 components of information equal 3 components of information - can't be done.

    So somewhere you'll likely have an RGBA trying to plug into an RGB slot or something like that.

    float, half and fixed are all numeric values in the shader. These range from the most precise but expensive (float) to the least precise and cheapest (fixed).

    The number on the end tells it how many components it has, up to a maximum of 4. So you could have, e.g. float, half2, fixed3, float4. So float could contain a gloss value, half2 could contain UV coordinates (as it has 2 components which can be used for U and V), fixed3 could contain a colour (3 components ==> R, G and B), fixed4 can be RGBA or a tangent or something.

    You can convert between the different precision values, but only if they have the same number of components (i.e. you can turn float3 into fixed3 without any problems but you couldn't put a float4 into a fixed3).
  • seforin
    Offline / Send Message
    seforin polycounter lvl 17
    ah ok this is some great stuff guys...but in all honesty I forgot to mention the real reason my shader was giving that error was asside from a herp derp node connection...I had shader model 2 enabled instead of 3.

    I was hitting the limit captain! and I didnt even know it!

    and talon you where correct I had a Split Command set that was exporting out XyzW or in this case RGBA and I didnt have the w(a) Placed to anything!

    that was another quick fix I was doing.


    Now I need to set a clamp of some sort on the Fresnel based rim lighting on normals because when I put a color and its lets say red...it displays as neon red...adn if I go dark (near black) it shows either the proper color...or nothing..
    I think some quick tweaks are in line for this one.


    And then after that I'll move on to refractions...I'll post progress as I go.
Sign In or Register to comment.