Search Unity

Using transform position and not light in PPL

Discussion in 'Shaders' started by nawash, Nov 27, 2010.

  1. nawash

    nawash

    Joined:
    Jan 29, 2010
    Posts:
    166
    Hi all,
    I am using the following shader.


    Code (csharp):
    1. Shader "Mystuffs/Legacy Shaders/Lightmapped/Bumped Diffuse" {
    2. Properties {
    3.     _Color ("Main Color", Color) = (1,1,1,1)
    4.     _MainTex ("Base (RGB)", 2D) = "white" {}
    5.     _BumpMap ("Normalmap", 2D) = "bump" {}
    6.     _LightMap ("Lightmap (RGB)", 2D) = "black" {}
    7. }
    8.  
    9. SubShader {
    10.     LOD 300
    11.     Tags { "RenderType" = "Opaque" }
    12. CGPROGRAM
    13. #pragma surface surf Lambert
    14. struct Input {
    15.   float2 uv_MainTex;
    16.   float2 uv_BumpMap;
    17.   float2 uv2_LightMap;
    18. };
    19.  
    20. sampler2D _MainTex;
    21. sampler2D _BumpMap;
    22. sampler2D _LightMap;
    23.  
    24. float4 _Color;
    25. void surf (Input IN, inout SurfaceOutput o)
    26. {
    27.   o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb * _Color;
    28.   half4 lm = tex2D (_LightMap, IN.uv2_LightMap)  * 2;
    29.   o.Emission = lm.rgb*o.Albedo.rgb;
    30.   o.Alpha = lm.a * _Color.a;
    31.   o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
    32. }
    33. ENDCG
    34. }
    35. FallBack "Legacy Shaders/Lightmapped/Diffuse"
    36. }
    Off course it use realtime light for now but I would to get rid of the mesh normal (which are useless in my case since I am using a lightmap).
    I would alos like to use a normal map but if I get rid of the normals using the fbx import options, the normal map rendering does not work anymore.

    Do you have an idea how I can specify that I want to use only a transform direction and not an actual light ?

    Is there another method you recommand to do this ?

    Is there a specific lighting model for what I want to do ?

    Hope you can help....

    thx
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    without normals you don't get normal maps anymore.


    also I don't understand with the part on the lights. if you use pixel lights you will get the light pixel informations. if you don't want to use lights, don't place them in the scene or set them to be bake only lights and provide the shaders vector3 structs through registers you set on the material :)
     
  3. nawash

    nawash

    Joined:
    Jan 29, 2010
    Posts:
    166
    Thank you for your extra fast answer.
    There must be something I am missing here :

    if I use PPL, why do I need the vertex normal ? They are not used at all in process, don't they ?

    I think the actual problem is that the Lambert lighting model uses "half3 lightDir" on which I have no impact.
    I would like to replace this automatically computer lightdir by a custom "half3 simulated_by_a_transform_dir"
     
  4. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    for PPL you don't need it.
    But if you want to use a shader that uses normals / tangents than your mesh must have normals / tangents or they just won't be there to use (obviously ;))


    as for the light dir: you can push in an own value through setting it through code on the material, thats no problem. that way you can push in whatever you want for an own light dir.

    what a transform dir is though is somehting thats beyond my mind, as the light dir you get is nothing else than the direction from light and this pixel
     
  5. nawash

    nawash

    Joined:
    Jan 29, 2010
    Posts:
    166
    Ok, I am totally confused here....
    How do you make PPL without using
    o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
    ?

    Do you have a sample to point me to (even in the built in shader) for pushing my own vector in the lighting function ?
     
  6. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Sending it over is nothing about shaders but about an own monobehaviour you write to feed the shader.
    Check out the script reference of the Material class


    also of interest: the comment of aras on here: http://blogs.unity3d.com/2010/07/17/unity-3-technology-surface-shaders/ in relation to the input thats calculated per vertex and provided per pixel
    as well as http://unity3d.com/support/documentation/Components/SL-SurfaceShaderLightingExamples.html and http://blogs.unity3d.com/2010/07/17/unity-3-technology-surface-shaders/
     
    Last edited: Nov 27, 2010