Search Unity

Sunshine! - Official Thread

Discussion in 'Assets and Asset Store' started by PolyVector, Aug 1, 2013.

  1. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Hi Atomicjoe,

    I've run into this same issue myself working on The Forest. The problem is that Sunshine can't hook into the ShaderLab code generation stuff that allows it to create a custom shadow pass, so it has to be done somewhat manually. The way we're doing it is by using a special RenderType to differentiate between specific types of vertex deformation.

    Say you have a fancy cloth shader, and you want it to cast shadows... Here are the steps that must be done to get things working:

    • Make sure your shader is using a custom RenderType... lets say you set it to "RenderType" = "FancyCloth"
    • Edit the Sunshine Occluders shader, and add a SubShader for your new RenderType. You can use the existing SubShaders as a guide. Basically, you'll need to create a vertex shader that matches your custom vertex deformation (we're using .cginc files to share logic). The fragment should already be created for you, just use of of the exsting ones in that file that matches what you want to do.

    If you run into trouble, or this is too advanced a technique for you, feel free to PM me a small project, and I'll attempt to create the SubShader for you.

    I hope this helps.
     
  2. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    Hey thank you VERY MUCH!
    I didn't thought of this! (Unity pipeline still has some mysteries to me! xD )
    It shouldn't be that hard to implement after all :)
     
  3. PrefabEvolution

    PrefabEvolution

    Joined:
    Mar 27, 2014
    Posts:
    225
  4. Skunkie

    Skunkie

    Joined:
    Jul 2, 2012
    Posts:
    75
    Unity 4.5 has been released and we know a lot of you will probably jump on upgrading with such vast improvements to stability. We have not tested Sunshine yet and we won't get a chance to until this weekend.

    If you do happen to upgrade, please feel free to report any issues you might find, but keep in mind we won't be able to address anything until this weekend.

    As always we thank you all for your patience.
     
  5. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    Everything works fine with Unity 4.5 and Sunshine for me.
    I have switched to forward render so I can't speak for deferred render for the moment.

    By the way, I have modified the ocluders shader and incorporated my custom vertex shader succesfully :)
    It was way easier than I thought it would be.

    I Think you should put this into the Sunshine manual, since using custom vertex shaders is really common.
    I had to declare some global shader variables to fully implement my original vertex shader into the ocluders shader (Shader.SetGlobalFloat from c# script ) , since I can't specify custom properties manually like in my other shaders. ( just in case someone needed the info in the future )

    This is a good example of why we need the source code of asset store products :)
    By the way, Sunshine is a pretty complex beast!
    You really know what you are doing PolyVector! ;)


    edit: another good reason for selling asset store products with the source code is: I had to manually remove the default shadow distance limit since I'm working with huge scenes. 1000 was REALLY low for a limit! (had to push it to 100000!) you should consider raising that limit or let the user modify it manually.
    I have raised the texture limit to 8192 too: since modern graphic cards can handle it, why limit the textures to 4096? (if it's for compatibility's sake, 4096 would give problems too, since a lot of decives only allow 2048 max!)

    And one silly question:
    why shadow filtering is limited to 4x4? Shadow Softener allows up to 8x8 and it's your product too! can't you include 5x5 -> 8x8 filters in Sunshine?
     
    Last edited: May 27, 2014
  6. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    That's excellent news! (both 4.5 compatibility and the custom vertex stuff).

    You're right that it should be documented, I'm pretty sure that got neglected because I kept planning on making the process smoother somehow. I'll try to get this sorted out in an update.

    Thank you for the kind words, It's wonderful to know Sunshine's being put to good use.
     
  7. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    And one silly question:
    why shadow filtering is limited to 4x4? Shadow Softener allows up to 8x8 and it's your product too! can't you include 5x5 -> 8x8 filters in Sunshine?
     
  8. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Haha, good question.

    Built-in shadows use a separate shadow collection pass, which means the entire shader can be devoted to expensive filtering. Shadow Softener exploits this by allowing those huge 8x8 kernels.

    Sunshine, on the other hand, processes the shadows inline with the rest of the shader so it has to be extremely lightweight and leave room for the original shader to do it's thing.

    Both techniques have pros and cons, and are surprisingly different internally despite both of them using PCF filtering.
     
  9. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    Haha! I knew I had to ask the question before trying to modify it myself and fail miserably! xD
    Thanks for saving me hours of frustration ;)
     
  10. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Haha, I aim to please. ;)
     
  11. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,822
    I'm considering purchasing Sunshine to make my mobile game look better, but first I have a few questions...

    1.) I've given up on Unity's lightmapping, its just buggy for me and half the time doesn't work or do anything or it corrupts my scenes, so I have to go with realtime shadows on my race tracks. I have quite a few props such as barrels, billboards, cones etc, that I want shadows on. Will your toolkit provide better performance on mobile over Unity's built-in shadow system?

    2.) I'm using the echologin core framework shaders on all my objects in my scenes, will your toolkit work nicely with these shaders?

    3.) On mobile will your toolkit actually make my game look better? Or are the features that make it better not performant enough on mobile to make a difference?

    Thanks
     
  12. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    1) The performance is simply different, so it depends on your bottleneck. Sunshine can be easier on Fillrate than built-in shadows, so fillrate-bound games can potentially run faster. It also has some features that allow you to only update every X frames, or after X movement, which can be a big help.

    2) I haven't tried these shaders, but looking them over, I'm going to say that they will probably be a decent amount of work to add support to. This is because they are Vertex/Fragment shaders, which Sunshine integration has to be somewhat manual. Our documentation goes over the process if you're interested.
    • Deferred rendering is the easiest path with no modification required
    • Forward surface shaders require a small amount of edits
    • Vertex/Frag shaders require more knowlege of the shader itself, and more work to integrate, so a whole pack might be a little time consuming to edit.

    3) Sunshine's main benefits when it comes to Mobile are compatibility (it can run on an Ouya), and not having to update the shadowmap every single frame. You can only update after the player moves X amount, and even treat it as something of a runtime baked solution.

    I can't say whether Sunshine is right for your particular situation, but if you try it and it simply doesn't work out, I'll give you a refund.
     
  13. Issam

    Issam

    Joined:
    Dec 18, 2012
    Posts:
    37
    Hi PolyVector,

    I am currently trying to speed up my shadow rendering and one of the idea I have is to split the scene into multiple shadow zones. For each zones I want to create a shadow/light map on the first frame for static objects, each frame I am thinking of testing what zone I am in and using that zone "pre-rendered" shadow map as the initial state for the shadow map. For dynamic objects I will just render normally on top of that initial state. Not sure if that make sense? I am currently looking at your code trying to figure out how I will write it, but if you have any suggestion where to look / what to change it will be really helpful.

    Our game is only targeting PC and Consoles, and we don't use textures (http://www.troubleimpact.com/) so I think I should be able to afford the memory cost of having multiple pre-calculated shadow map... in theory :)
     
  14. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    That's a clever idea, I like the way you think. I have to say though that this will likely be much more difficult to accomplish than it might seem...

    The basic process would probably involve inserting some code/shaders immediately after Sunshine renders it's shadowmap... This would take your pre-baked shadowmap and blend it with the dynamic one, and then allow Sunshine to do its thing... The problem is this shadowmap would have to be scaled and biased based on the camera's position, and relative z-depth... it could quickly get complicated, especially if there are cascades!

    If you want to go down that rabbit hole (and have the experience to pull it off), by all means go for it, I'm curious if it's possible. but you may void your warranty. ;)
     
    Last edited: Jun 4, 2014
  15. bluemoon

    bluemoon

    Joined:
    Dec 14, 2012
    Posts:
    85
    I'm using the Deferred renderer and Lux, how difficalt do you think it would be to combine Lux's defferred shaders with Sunshine's.

    I'm somewhat competent with surface shaders but have no experience with the Deffered lighting shaders.

    Thanks
     
  16. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Does LUX replace Internal-PrePassLighting.shader? If it does replace it, then Sunshine's modifications to that shader would need to be merged with LUX's to work properly. I have no idea how difficult that might be... might be a simple change, might be very difficult. If it doesn't replace that shader, then it should "just work" without any change (assuming LUX shaders aren't forcing forward rendering).

    If you try Sunshine out and run into any problems, just let me know and I'll see what I can do to help.
     
  17. bluemoon

    bluemoon

    Joined:
    Dec 14, 2012
    Posts:
    85
    Thanks for the quick reply.

    Yes it must since it replaces the lighting and specular with a physically accurate blinphong or cooktorance lighting model. It looks like you get colored spec on metals in deffuse as well.
    It will be a bit before I get more funding, but lux being a free, open source addon you should check it out. Tomaszek's RTP shaders now use it as well as Larsbertram1's foliage shaders. Maybe you could get some cross promotion if Sunshine Was compatible.
     
  18. goldencruz

    goldencruz

    Joined:
    Oct 2, 2013
    Posts:
    94
    I am thinking of buying this sunshine but does this work with other light like point, spot, and does it work well in indoors.
     
  19. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Sorry, Sunshine only works with a single Directional Light. I think the light rays look great when they're streaming indoors through windows/holes, but if you're 100% indoors it won't really do anything.
     
  20. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    Hey PolyVector!
    I'm having troubles with the scattering effect and my custom vertex displacement shaders:
    I have modified the occluder shader of sunshine to include my own render tag. Shadows are working perfectly, but scattering is really weird. It don't seems to work with my vertex shader displaced meshes and messes with the regular objects scatter too.
    Since I don't have a clue how you are performing the scatering in the first place, I really don't know what's going on...
    Do I have to modify/add anything in the sunshine shaders to make the scatter work with my vertex shader displaced meshes?

    I have extended Sunshine's Light Distance to 20000 since I'm working with really large distances, and I'm using 4 cascades manually split to cover this large distance.

    also I'm using unity's default fog and it's quite visible in the scene.
     
    Last edited: Jun 17, 2014
  21. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Sorry for the slow reply. That's very strange because the shadows and the light rays both use the exact same source data. If you could PM me a small test scene that demonstrates the problem, I'll investigate it for you.
     
  22. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    Mmm... that will be quite hard right now, since it's a big super secret project (specially the shaders, since the magic is there)...
    It's not priority number 1 right now and ray lights weren't the reason I chose Sunshine for the shadows in this project (customizable cascade distances, shadow filtering and overall better quality than Unity pro shadows was)

    I have to work in other complicated things right now. I'll make a barebone project to show this behaviour when I'll have some spare time.

    thanks for the support anyway! :)
     
  23. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Fair enough. Something I would take a look if you have time is the scale of your scene. See if the light rays look correct with a shorter Light Distance. Since the shadows themselves look correct, this could simply be a matter of floating-point precision since the Light Rays go through more preprocessing steps to make the math efficient.

    Also, there's the chance a cascade bug slipped in there, so I would also test with a single cascade to see if that affects the issue.
     
  24. KyleOlsen

    KyleOlsen

    Joined:
    Apr 3, 2012
    Posts:
    237
    We're trying to get this set up with RTP 3 with no luck so far. If you or anyone else has any pointers on what needs changed in his terrain shaders I'd appreciate it! :)

    Some info:
    -We're using Deferred rendering
    -Our Sunshine Cameras (there's two) are instantiated at runtime


    Update
    :
    I removed Sunshine from the project, reimported everything, then before testing I restarted the editor and I'm getting shadows! I could have swore that I did this before, but all is well now. Works great with RTP.
     
    Last edited: Jul 11, 2014
  25. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Whatever the problem was, I'm glad to hear it's working now!

    You shouldn't have to modify any shaders to get Sunshine working in the Deferred renderer (unless it's a forward-only shader like something alpha blended), so it may have been some kind of internal configuration issue.
     
  26. Skunkie

    Skunkie

    Joined:
    Jul 2, 2012
    Posts:
    75
    Sunshine 1.5.8 is Available in the Unity Asset Store!

    • Fixed Banding issues with lower Scatter Intensity
    • Added HDR Support
    • Fixed a divide-by-zero error when Light was perfectly horizontal (in SunshineCamera.ConfigureOvercast)
    • Shader installation is now "Manual" by default to prevent accidental material changes
    • Removed some unused math.
    • Added AtsFoliage samples in Sunshine Occluder.shader... Uncomment to support these shaders.
    Sunshine is the volumetric lighting tech in the currently popular game: The Forest, available on Steam.
     
    KyleOlsen likes this.
  27. grimmy

    grimmy

    Joined:
    Feb 2, 2009
    Posts:
    409
    Hi, I downloaded the android apk with the robot but there are no shadows. I want to check its performance on device. What do I do? Cheers.
     
  28. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    I'll double check to make sure the demo's still working on my end and get back to you asap.
     
  29. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Okay, it looks like shadows are working for me on our Ouya, and Nexus 7 (2013), so maybe it's a specific compatibility problem. What device are you testing with?
     
  30. grimmy

    grimmy

    Joined:
    Feb 2, 2009
    Posts:
    409
    Last edited: Jul 16, 2014
  31. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Strange... A Note 10.1 should be much more powerful than an Ouya. It's probably a specific compatibility problem, and unfortunately I don't have another device to test on apart from the Ouya and Nexus 7.
     
  32. grimmy

    grimmy

    Joined:
    Feb 2, 2009
    Posts:
    409
    Hmm, odd. Normal shadows work fine on it. I'd really like to try both Sunshine and Shadow softener to see if they improve my game and at the same time maintain a similar framerate but I'm reluctant to buy any before I can test. Is there any way I could get a trail version of each to see if they are suitable?
     
  33. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Sunshine shadows are a completely separate system from Unity's built-in shadows, so there's always the chance that one will work and not the other (which is how we got Sunshine running on an Ouya).

    Shadow Softener is definitely more compatible since it merely alters the filtering code of the built-in shadows. For best results on mobile, make sure the shadows are set to "Hard" and you follow the "Advanced" instructions for mobile compatibility.

    We don't really do trial versions, but you can feel free to return whichever one(s) don't work out for your project.
     
  34. vivin

    vivin

    Joined:
    Jul 10, 2013
    Posts:
    15
    Hey guys, we are using sunshine for our project, and its working very well for the most part. I have run into an issue where the volumetric rays are passing through some objects?
    I cant figure out why its doing such a thing, I am checking out the "Visualize Lightmap" option to see what is happening, It doesnt seem to be obeying the ground geo I have and instead, casting right through it, down into an area below. I have tried to add some light blockers with little success. It might be a scale issue? as the area of ground used to block the light is rather huge.

    any help would be much appreciated!
     
  35. gian-reto-alig

    gian-reto-alig

    Joined:
    Apr 30, 2013
    Posts:
    756
    I have a question that might be hard to answer though:

    I am currently building a nighttime scene with lots of active lights. 2 directional celestial lights (Moons) and about 20-30 spotlights are casting shadows at the moment.

    As you can guess, even with lightmaps, the built in Unity shadow system is at its limits (doubling the amount of draw calls).

    My question: could Sunshine help me here? Does it work differently to the built in shadows when it comes to amount of draw calls needed? Does it support spotlights? Can it be combined with lightmap baking and will this improve performance?


    Thanks for your help in advance

    Gian-Reto
     
  36. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Hmmm, it almost sounds like it's related to the shader(s) those particular objects are using. I would try using the default Diffuse shader as a quick test to check if it's being caused by the shader.

    You might also try adjusting the Light Bias, and checking if those objects are non-uniform scale (I know Unity can have trouble with this).

    If all else fails, feel free to send me a test scene and I'll see if I can track down the issue.

    I don't believe Sunshine will work for you in this situation. Sunshine only supports a single directional light and any performance differences will be negligible in with so many other lights using the built-in shadows.

    Your best bet might be to work at reducing the over-all draw call by other means, such as merging meshes, using baked Occlusion Culling, and strictly controlling which objects need to cast shadows.
     
  37. gian-reto-alig

    gian-reto-alig

    Joined:
    Apr 30, 2013
    Posts:
    756
    Thanks for the answer. I am aware that what I am trying here might be impossible to really optimize, just wanted to know if your Asset might have helped me.
    I guess supporting multiple directional lights or spot lights will be out of scope for sunshine also in the future?

    If yes, I might be back when I gave up my current (probably stupid) plan and switch to a single light source ;)


    Thanks for the information

    Gian-Reto
     
  38. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    The way Sunshine works really limits the capabilities to a single directional light, so it's out of the scope in the future. Our Shadow Softener package is designed to work with multiple lights/types, but it's in no way going to speed up your project since it basically just does higher quality filtering.

    Wish I had better advice, but shadows just tend to be costly in any engine, especially Unity.
     
  39. TheDevGuy

    TheDevGuy

    Joined:
    Mar 3, 2014
    Posts:
    78
    Hi i am considering the purchase and would like some insight on the capabilities.

    I have a spaceship level and i need to be able to cast the light through some windows facing the sun and apply the effects of Sunshine to this, but before i purchased, i put the directional light into my scene and it lights up the interiors also for some reason, even with shadows on?

    Any reason for this, as this is the only thing thats stopped me from buying it.

    Also, i see that you have stated this only works with directional lights, is there any prospect for supporting spotlights? If not i might be better purchasing a fog volume asset and tweaking it as i already bought your guys shadow softener asset
     
  40. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    The built-in directional light shadows aren't working for you? I've seen this before on some chipsets with Unity, so it may be a compatibility problem to report to the Unity guys.

    Sunshine is completely separate from the built-in shadows so they may work for you even if the built-in don't, but unfortunately there are no plans to support other light types since it's impractical for the way Sunshine works.
     
  41. tripknotix

    tripknotix

    Joined:
    Apr 21, 2011
    Posts:
    744
    Theres quite a lot of work to be done when changing scenes and loading levels, is it possible you could add in some default ways to look for directional lights when scenes load "OnLevelWasLoaded()" is one way, then call another method you make up called "CheckForDirectionalLight" or something. and that way people know they can manually call that when loading map data in other ways. This would also work for custom maps where a directional light could be added and removed, so that we can switch it on and off.

    instead of a standard enable/disable, or keep those there and add another component class that enables and disables the main script.
     
  42. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Sunshine should handle a Light being removed/destroyed gracefully, and disabled itself. If you want to dynamically change the light source, it's fairly straightforward:

    Code (csharp):
    1. void OnLevelWasLoaded(int levelID)
    2. {
    3.     // Use the first Directional Light in the scene.
    4.     Sunshine.Instance.SunLight = Light.GetLights(LightType.Directional, -1)[0];
    5.  
    6.     // Make sure Sunshine hasn't disabled itself from a previously removed light ;)
    7.     Sunshine.Instance.enabled = true;
    8. }
    I feel like adding additional APIs wouldn't simplify the need for essentially the same code.
     
  43. Project-Mysh

    Project-Mysh

    Joined:
    Nov 3, 2013
    Posts:
    223
    Hi PolyVecor,

    I need some help implementing Sunshine with custom shaders made on ShaderForge. Here is a simple shader that I modified but its not working for me:
    Code (CSharp):
    1. Shader "Sunshine/Mysh_DiffVetex" {
    2.     Properties {
    3.         _Dif_Cube ("Dif_Cube", Cube) = "_Skybox" {}
    4.         _FresnelPower ("Fresnel Power", Range(0, 10)) = 1
    5.         _IntensidadFresnel ("Intensidad Fresnel", Range(0, 10)) = 1
    6.     }
    7.     SubShader {
    8.         Tags {
    9.             "RenderType"="Opaque"
    10.         }
    11.         Pass {
    12.             Name "ForwardBase"
    13.             Tags {
    14.                 "LightMode"="ForwardBase"
    15.             }
    16.             Cull Off
    17.        
    18.        
    19.             CGPROGRAM
    20.             #pragma vertex vert
    21.             #pragma fragment frag
    22.             #define UNITY_PASS_FORWARDBASE
    23.             #include "UnityCG.cginc"
    24.             #include "AutoLight.cginc"
    25.             #pragma multi_compile_fwdbase_fullshadows
    26.             #include "Assets/Sunshine/Shaders/Sunshine.cginc"
    27.             #pragma multi_compile SUNSHINE_DISABLED SUNSHINE_FILTER_PCF_4x4 SUNSHINE_FILTER_PCF_3x3 SUNSHINE_FILTER_PCF_2x2 SUNSHINE_FILTER_HARD
    28.             #pragma exclude_renderers xbox360 ps3 flash d3d11_9x
    29.             #pragma target 3.0
    30.             #pragma glsl
    31.             uniform float4 _LightColor0;
    32.             uniform samplerCUBE _Dif_Cube;
    33.             uniform float _FresnelPower;
    34.             uniform float _IntensidadFresnel;
    35.             struct VertexInput {
    36.                 float4 vertex : POSITION;
    37.                 float3 normal : NORMAL;
    38.                 float4 Color : COLOR;
    39.                 SUNSHINE_INPUT_PARAMS;
    40.             };
    41.             struct VertexOutput {
    42.                 float4 pos : SV_POSITION;
    43.                 float4 posWorld : TEXCOORD0;
    44.                 float3 normalDir : TEXCOORD1;
    45.                 float4 vertexColor : COLOR;
    46.                 LIGHTING_COORDS(2,3)
    47.             };
    48.             VertexOutput vert (VertexInput v) {
    49.                 VertexOutput o;
    50.                 o.vertexColor = v.Color;
    51.                 o.normalDir = mul(float4(v.normal,0), _World2Object).xyz;
    52.                 o.posWorld = mul(_Object2World, v.vertex);
    53.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    54.                 TRANSFER_VERTEX_TO_FRAGMENT(o)
    55.                 SUNSHINE_WRITE_VERTEX(v, o);
    56.                 return o;
    57.             }
    58.             fixed4 frag(VertexOutput i) : COLOR {
    59.                 i.normalDir = normalize(i.normalDir);
    60.                 float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
    61. /////// Normals:
    62.                 float3 normalDirection =  i.normalDir;
    63.            
    64.                 float nSign = sign( dot( viewDirection, i.normalDir ) ); // Reverse normal if this is a backface
    65.                 i.normalDir *= nSign;
    66.                 normalDirection *= nSign;
    67.            
    68.                 float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);
    69. ////// Lighting:
    70.                 float attenuation = SUNSHINE_ATTENUATION(i);
    71.                 float3 attenColor = attenuation * _LightColor0.xyz;
    72.                 float Pi = 3.141592654;
    73.                 float InvPi = 0.31830988618;
    74. /////// Diffuse:
    75.                 float NdotL = dot( normalDirection, lightDirection );
    76.                 float3 diffuse = max( 0.0, NdotL)*InvPi * attenColor + UNITY_LIGHTMODEL_AMBIENT.rgb;
    77. ////// Emissive:
    78.                 float3 emissive = (pow(1.0-max(0,dot(normalDirection, viewDirection)),_FresnelPower)*_IntensidadFresnel*_LightColor0.rgb);
    79.                 float3 finalColor = 0;
    80.                 float3 diffuseLight = diffuse;
    81.                 float4 node_3 = texCUBElod(_Dif_Cube,float4(i.normalDir,2.0));
    82.                 diffuseLight += (node_3.rgb*(node_3.a*1.0)); // Diffuse Ambient Light
    83.                 finalColor += diffuseLight * (i.vertexColor.rgb*2.0);
    84.                 finalColor += emissive;
    85. /// Final Color:
    86.                 return fixed4(finalColor,1);
    87.             }
    88.             ENDCG
    89.         }
    90.         Pass {
    91.             Name "ForwardAdd"
    92.             Tags {
    93.                 "LightMode"="ForwardAdd"
    94.             }
    95.             Blend One One
    96.             Cull Off
    97.        
    98.        
    99.             Fog { Color (0,0,0,0) }
    100.             CGPROGRAM
    101.             #pragma vertex vert
    102.             #pragma fragment frag
    103.             #define UNITY_PASS_FORWARDADD
    104.             #include "UnityCG.cginc"
    105.             #include "AutoLight.cginc"
    106.             #pragma multi_compile_fwdadd_fullshadows
    107.             #include "Assets/Sunshine/Shaders/Sunshine.cginc"
    108.             #pragma multi_compile SUNSHINE_DISABLED SUNSHINE_FILTER_PCF_4x4 SUNSHINE_FILTER_PCF_3x3 SUNSHINE_FILTER_PCF_2x2 SUNSHINE_FILTER_HARD
    109.             #pragma exclude_renderers xbox360 ps3 flash d3d11_9x
    110.             #pragma target 3.0
    111.             #pragma glsl
    112.             uniform float4 _LightColor0;
    113.             uniform float _FresnelPower;
    114.             uniform float _IntensidadFresnel;
    115.             struct VertexInput {
    116.                 float4 vertex : POSITION;
    117.                 float3 normal : NORMAL;
    118.                 float4 Color : COLOR;
    119.                 SUNSHINE_INPUT_PARAMS;
    120.             };
    121.             struct VertexOutput {
    122.                 float4 pos : SV_POSITION;
    123.                 float4 posWorld : TEXCOORD0;
    124.                 float3 normalDir : TEXCOORD1;
    125.                 float4 vertexColor : COLOR;
    126.                 LIGHTING_COORDS(2,3)
    127.             };
    128.             VertexOutput vert (VertexInput v) {
    129.                 VertexOutput o;
    130.                 o.vertexColor = v.Color;
    131.                 o.normalDir = mul(float4(v.normal,0), _World2Object).xyz;
    132.                 o.posWorld = mul(_Object2World, v.vertex);
    133.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    134.                 TRANSFER_VERTEX_TO_FRAGMENT(o)
    135.                 SUNSHINE_WRITE_VERTEX(v, o);
    136.                 return o;
    137.             }
    138.             fixed4 frag(VertexOutput i) : COLOR {
    139.                 i.normalDir = normalize(i.normalDir);
    140.                 float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
    141. /////// Normals:
    142.                 float3 normalDirection =  i.normalDir;
    143.            
    144.                 float nSign = sign( dot( viewDirection, i.normalDir ) ); // Reverse normal if this is a backface
    145.                 i.normalDir *= nSign;
    146.                 normalDirection *= nSign;
    147.            
    148.                 float3 lightDirection = normalize(lerp(_WorldSpaceLightPos0.xyz, _WorldSpaceLightPos0.xyz - i.posWorld.xyz,_WorldSpaceLightPos0.w));
    149. ////// Lighting:
    150.                 float attenuation = SUNSHINE_ATTENUATION(i);
    151.                 float3 attenColor = attenuation * _LightColor0.xyz;
    152.                 float Pi = 3.141592654;
    153.                 float InvPi = 0.31830988618;
    154. /////// Diffuse:
    155.                 float NdotL = dot( normalDirection, lightDirection );
    156.                 float3 diffuse = max( 0.0, NdotL)*InvPi * attenColor;
    157.                 float3 finalColor = 0;
    158.                 float3 diffuseLight = diffuse;
    159.                 finalColor += diffuseLight * (i.vertexColor.rgb*2.0);
    160. /// Final Color:
    161.                 return fixed4(finalColor * 1,0);
    162.             }
    163.             ENDCG
    164.         }
    165.     }
    166.     FallBack "Diffuse"
    167.     CustomEditor "ShaderForgeMaterialInspector"
    168. }
    169.  
    Can you help me?

    Ohh, one more question:
    There is any way to get 2 shadow systems working together? ( one updated every frame and other updating every 30 frames or more, the first doing 1024px lightmap and the second 4096px ) this could be interesting to get good perormance in realtime day cycles with very far shadows.
     
    Last edited: Aug 1, 2014
  44. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Okay, so the main issue with your shader was the SUNSHINE_INPUT_PARAMS should be in the VertexOutput struct, but there was also an issue with Unity's GLSL Optimizer that was triggered by PCF4x4, so I had to limit it to PCF3x3 and smaller filtering:

    Code (csharp):
    1. Shader"Sunshine/Mysh_DiffVetex" {
    2. Properties {
    3. _Dif_Cube ("Dif_Cube", Cube) = "_Skybox" {}
    4. _FresnelPower ("FresnelPower", Range(0, 10)) = 1
    5. _IntensidadFresnel ("IntensidadFresnel", Range(0, 10)) = 1
    6. }
    7. SubShader {
    8. Tags {
    9. "RenderType"="Opaque"
    10. }
    11. Pass {
    12. Name"ForwardBase"
    13. Tags {
    14. "LightMode"="ForwardBase"
    15. }
    16. CullOff
    17.  
    18.  
    19. CGPROGRAM
    20. #pragmavertexvert
    21. #pragmafragmentfrag
    22. #defineUNITY_PASS_FORWARDBASE
    23. #include "UnityCG.cginc"
    24. #include "AutoLight.cginc"
    25. #pragmamulti_compile_fwdbase_fullshadows
    26.  
    27. #include "Assets/Sunshine/Shaders/Sunshine.cginc"
    28. #pragmamulti_compileSUNSHINE_DISABLEDSUNSHINE_FILTER_PCF_3x3SUNSHINE_FILTER_PCF_2x2SUNSHINE_FILTER_HARD
    29.  
    30. #pragmaexclude_renderersxbox360ps3flashd3d11_9x
    31. #pragmatarget3.0
    32. #pragmaglsl
    33.  
    34. uniformfloat4_LightColor0;
    35. uniformsamplerCUBE_Dif_Cube;
    36. uniformfloat_FresnelPower;
    37. uniformfloat_IntensidadFresnel;
    38. structVertexInput {
    39. float4vertex : POSITION;
    40. float3normal : NORMAL;
    41. float4Color : COLOR;
    42. };
    43. structVertexOutput {
    44. float4pos : SV_POSITION;
    45. float4posWorld : TEXCOORD0;
    46. float3normalDir : TEXCOORD1;
    47. float4vertexColor : COLOR;
    48.  
    49. //RequiredSunshineParams:
    50. SUNSHINE_INPUT_PARAMS : TEXCOORD2;
    51.  
    52. LIGHTING_COORDS(3,4)
    53. };
    54. VertexOutputvert (VertexInputv) {
    55. VertexOutputo;
    56. o.vertexColor = v.Color;
    57. o.normalDir = mul(float4(v.normal,0), _World2Object).xyz;
    58. o.posWorld = mul(_Object2World, v.vertex);
    59. o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    60.  
    61. //WriteSunshineParams:
    62. SUNSHINE_WRITE_VERTEX(v, o);
    63.  
    64. TRANSFER_VERTEX_TO_FRAGMENT(o)
    65. returno;
    66. }
    67. fixed4frag(VertexOutputi) : COLOR {
    68. i.normalDir = normalize(i.normalDir);
    69. float3viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
    70. /////// Normals:
    71. float3normalDirection = i.normalDir;
    72.  
    73. floatnSign = sign( dot( viewDirection, i.normalDir ) ); //Reversenormalifthisisabackface
    74. i.normalDir *= nSign;
    75. normalDirection *= nSign;
    76.  
    77. float3lightDirection = normalize(_WorldSpaceLightPos0.xyz);
    78. ////// Lighting:
    79. floatattenuation = SUNSHINE_ATTENUATION(i);
    80. float3attenColor = attenuation * _LightColor0.xyz;
    81. floatPi = 3.141592654;
    82. floatInvPi = 0.31830988618;
    83. /////// Diffuse:
    84. floatNdotL = dot( normalDirection, lightDirection );
    85. float3diffuse = max( 0.0, NdotL)*InvPi * attenColor + UNITY_LIGHTMODEL_AMBIENT.rgb;
    86. ////// Emissive:
    87. float3emissive = (pow(1.0-max(0,dot(normalDirection, viewDirection)),_FresnelPower)*_IntensidadFresnel*_LightColor0.rgb);
    88. float3finalColor = 0;
    89. float3diffuseLight = diffuse;
    90. float4node_3 = texCUBElod(_Dif_Cube,float4(i.normalDir,2.0));
    91. diffuseLight += (node_3.rgb*(node_3.a*1.0)); //DiffuseAmbientLight
    92. finalColor += diffuseLight * (i.vertexColor.rgb*2.0);
    93. finalColor += emissive;
    94. /// FinalColor:
    95. returnfixed4(finalColor,1);
    96. }
    97. ENDCG
    98. }
    99. Pass {
    100. Name"ForwardAdd"
    101. Tags {
    102. "LightMode"="ForwardAdd"
    103. }
    104. BlendOneOne
    105. CullOff
    106.  
    107.  
    108. Fog { Color (0,0,0,0) }
    109. CGPROGRAM
    110. #pragmavertexvert
    111. #pragmafragmentfrag
    112. #defineUNITY_PASS_FORWARDADD
    113. #include "UnityCG.cginc"
    114. #include "AutoLight.cginc"
    115. #pragmamulti_compile_fwdadd_fullshadows
    116. #include "Assets/Sunshine/Shaders/Sunshine.cginc"
    117. #pragmamulti_compileSUNSHINE_DISABLEDSUNSHINE_FILTER_PCF_3x3SUNSHINE_FILTER_PCF_2x2SUNSHINE_FILTER_HARD
    118. #pragmaexclude_renderersxbox360ps3flashd3d11_9x
    119. #pragmatarget3.0
    120. #pragmaglsl
    121. uniformfloat4_LightColor0;
    122. uniformfloat_FresnelPower;
    123. uniformfloat_IntensidadFresnel;
    124. structVertexInput {
    125. float4vertex : POSITION;
    126. float3normal : NORMAL;
    127. float4Color : COLOR;
    128. };
    129. structVertexOutput {
    130. float4pos : SV_POSITION;
    131. float4posWorld : TEXCOORD0;
    132. float3normalDir : TEXCOORD1;
    133. float4vertexColor : COLOR;
    134.  
    135. //RequiredSunshineParams:
    136. SUNSHINE_INPUT_PARAMS : TEXCOORD2;
    137.  
    138. LIGHTING_COORDS(3,4)
    139. };
    140. VertexOutputvert (VertexInputv) {
    141. VertexOutputo;
    142. o.vertexColor = v.Color;
    143. o.normalDir = mul(float4(v.normal,0), _World2Object).xyz;
    144. o.posWorld = mul(_Object2World, v.vertex);
    145. o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    146.  
    147. //WriteSunshineParams:
    148. SUNSHINE_WRITE_VERTEX(v, o);
    149.  
    150. TRANSFER_VERTEX_TO_FRAGMENT(o)
    151. returno;
    152. }
    153. fixed4frag(VertexOutputi) : COLOR {
    154. i.normalDir = normalize(i.normalDir);
    155. float3viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
    156. /////// Normals:
    157. float3normalDirection = i.normalDir;
    158.  
    159. floatnSign = sign( dot( viewDirection, i.normalDir ) ); //Reversenormalifthisisabackface
    160. i.normalDir *= nSign;
    161. normalDirection *= nSign;
    162.  
    163. float3lightDirection = normalize(lerp(_WorldSpaceLightPos0.xyz, _WorldSpaceLightPos0.xyz - i.posWorld.xyz,_WorldSpaceLightPos0.w));
    164. ////// Lighting:
    165. floatattenuation = SUNSHINE_ATTENUATION(i);
    166. float3attenColor = attenuation * _LightColor0.xyz;
    167. floatPi = 3.141592654;
    168. floatInvPi = 0.31830988618;
    169. /////// Diffuse:
    170. floatNdotL = dot( normalDirection, lightDirection );
    171. float3diffuse = max( 0.0, NdotL)*InvPi * attenColor;
    172. float3finalColor = 0;
    173. float3diffuseLight = diffuse;
    174. finalColor += diffuseLight * (i.vertexColor.rgb*2.0);
    175. /// FinalColor:
    176. returnfixed4(finalColor * 1,0);
    177. }
    178. ENDCG
    179. }
    180. }
    181. FallBack"Diffuse"
    182. CustomEditor"ShaderForgeMaterialInspector"
    183. }
    Sunshine only supports a single instance unfortunately. One feature I would love to add is allowing staggered cascade rendering so that farther cascades could be updated less frequently, but I haven't had much luck getting it to work to be honest.

    Anyways, hope this helps.

    Edit: I should mention that shadows didn't show up in this shader for me, but I'm probably not using it as intended... When I simply return attenuation, I can see the shadows themselves are functioning fine.
     
  45. Project-Mysh

    Project-Mysh

    Joined:
    Nov 3, 2013
    Posts:
    223
    Thank you for responding so quickly!
    I will try now to follow the same pattern you did modifying this shader and lets see if this works with all Shader Forge shaders. Maybe i will try to combine your sunshine shaders with the "Shadow Volumes" package, letting sunshine the far and static shadows updating every 100 frames. Maybe I get a good result in performance.

    Thanks again for your help.
     
  46. Project-Mysh

    Project-Mysh

    Joined:
    Nov 3, 2013
    Posts:
    223
    This is the error that im getting now:
    Shader error in 'Shader Forge/Mysh_Sun_DiffVetex': D3D shader assembly failed with: (8): error X5639: dcl usage+index: texcoord,2 has already been specified for an output register.
    (21): error X5704: Attempt to write undeclared components of output register o5 (*): *x/0 *y/1 z/2 w/3. Components of o# registers to be written must be declared by a dcl statement.
    (33): error X5704: Attempt to write undeclared components of output register o5 (*): x/0 y/1 *z/2 *w/3. Components of o# registers to be written must be declared by a dcl statement.

    What im doing worng?

    Ok nothing, simply i changed SUNSHINE_INPUT_PARAMS : TEXCOORD2; to SUNSHINE_INPUT_PARAMS; and now its working fine.

    P.D: You are not getting any shadows with the shader cause you have to assign a cubemap to the shader first.
     
  47. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Ah okay, I'm glad you got it working. You're right that the TEXCOORD2 semantic is optional and I was only specifying it to make sure it worked in that particular shader...
     
  48. Project-Mysh

    Project-Mysh

    Joined:
    Nov 3, 2013
    Posts:
    223
    Sorry if I'm bothering you a lot,

    But yes, the shaders are working but with a couple of strange warnings. And now I tested what this warnings effect, and I can't compile to any mobile platform (sunshine is configured with mobile shaders). The shader without any sunshine modification works on all platforms without any problem.

    This are the warnings I get when the editor compile the shader:

    And this is the error that the mobile platform gives to me:
    And if you need again the shader code ( there is no PCF pragma cause I only use hard edges, but with PCF 3x3 gives the same error).

    Code (CSharp):
    1. // Shader created with Shader Forge Beta 0.36
    2. // Shader Forge (c) Joachim Holmer - http://www.acegikmo.com/shaderforge/
    3. // Note: Manually altering this data may prevent you from opening it in Shader Forge
    4. /*SF_DATA;ver:0.36;sub:START;pass:START;ps:flbk:,lico:1,lgpr:1,nrmq:1,limd:1,uamb:True,mssp:True,lmpd:False,lprd:False,enco:True,frtr:True,vitr:True,dbil:False,rmgx:True,rpth:0,hqsc:True,hqlp:False,tesm:0,blpr:0,bsrc:0,bdst:0,culm:2,dpts:2,wrdp:True,ufog:True,aust:True,igpj:False,qofs:0,qpre:1,rntp:1,fgom:False,fgoc:False,fgod:False,fgor:False,fgmd:0,fgcr:0.5,fgcg:0.5,fgcb:0.5,fgca:1,fgde:0.01,fgrn:0,fgrf:300,ofsf:0,ofsu:0,f2p0:False;n:type:ShaderForge.SFN_Final,id:1,x:32719,y:32712|diff-2245-OUT,emission-101-OUT,amdfl-8-OUT;n:type:ShaderForge.SFN_VertexColor,id:2,x:33322,y:32550;n:type:ShaderForge.SFN_Cubemap,id:3,x:33426,y:32826,ptlb:Dif_Cube,ptin:_Dif_Cube|DIR-5-OUT,MIP-4-OUT;n:type:ShaderForge.SFN_Vector1,id:4,x:33632,y:32900,v1:2;n:type:ShaderForge.SFN_NormalVector,id:5,x:33632,y:32741,pt:False;n:type:ShaderForge.SFN_Multiply,id:6,x:33250,y:32906|A-3-A,B-7-OUT;n:type:ShaderForge.SFN_Vector1,id:7,x:33439,y:33027,v1:1;n:type:ShaderForge.SFN_Multiply,id:8,x:33072,y:32845|A-3-RGB,B-6-OUT;n:type:ShaderForge.SFN_Fresnel,id:99,x:33439,y:31491|EXP-103-OUT;n:type:ShaderForge.SFN_Multiply,id:101,x:32990,y:32303|A-99-OUT,B-105-OUT,C-2244-RGB;n:type:ShaderForge.SFN_Slider,id:103,x:33738,y:31518,ptlb:Fresnel Power,ptin:_FresnelPower,min:0,cur:1,max:10;n:type:ShaderForge.SFN_Slider,id:105,x:33557,y:31650,ptlb:Intensidad Fresnel,ptin:_IntensidadFresnel,min:0,cur:1,max:10;n:type:ShaderForge.SFN_LightColor,id:2244,x:33599,y:32008;n:type:ShaderForge.SFN_Multiply,id:2245,x:33101,y:32637|A-2-RGB,B-2246-OUT;n:type:ShaderForge.SFN_Vector1,id:2246,x:33303,y:32714,v1:2;proporder:3-103-105;pass:END;sub:END;*/
    5.  
    6. Shader "Sunshine/Mysh_Sun_DiffVetex" {
    7.     Properties {
    8.         _Dif_Cube ("Dif_Cube", Cube) = "_Skybox" {}
    9.         _FresnelPower ("Fresnel Power", Range(0, 10)) = 1
    10.         _IntensidadFresnel ("Intensidad Fresnel", Range(0, 10)) = 1
    11.     }
    12.     SubShader {
    13.         Tags {
    14.             "RenderType"="Opaque"
    15.         }
    16.         Pass {
    17.             Name "ForwardBase"
    18.             Tags {
    19.                 "LightMode"="ForwardBase"
    20.             }
    21.             Cull Off
    22.          
    23.          
    24.             CGPROGRAM
    25.             #pragma vertex vert
    26.             #pragma fragment frag
    27.             #define UNITY_PASS_FORWARDBASE
    28.             #include "UnityCG.cginc"
    29.             #include "AutoLight.cginc"
    30.             #pragma multi_compile_fwdbase_fullshadows
    31.             #include "Assets/Sunshine/Shaders/Sunshine.cginc"
    32.             #pragma multi_compile SUNSHINE_DISABLED SUNSHINE_FILTER_HARD
    33.             #pragma target 3.0
    34.             #pragma glsl
    35.             uniform float4 _LightColor0;
    36.             uniform samplerCUBE _Dif_Cube;
    37.             uniform float _FresnelPower;
    38.             uniform float _IntensidadFresnel;
    39.             struct VertexInput {
    40.                 float4 vertex : POSITION;
    41.                 float3 normal : NORMAL;
    42.                 float4 Color : COLOR;
    43.             };
    44.             struct VertexOutput {
    45.                 float4 pos : SV_POSITION;
    46.                 float4 posWorld : TEXCOORD0;
    47.                 float3 normalDir : TEXCOORD1;
    48.                 float4 vertexColor : COLOR;
    49.                 SUNSHINE_INPUT_PARAMS;
    50.                 LIGHTING_COORDS(2,3)
    51.             };
    52.             VertexOutput vert (VertexInput v) {
    53.                 VertexOutput o;
    54.                 o.vertexColor = v.Color;
    55.                 o.normalDir = mul(float4(v.normal,0), _World2Object).xyz;
    56.                 o.posWorld = mul(_Object2World, v.vertex);
    57.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    58.                 SUNSHINE_WRITE_VERTEX(v, o);
    59.                 TRANSFER_VERTEX_TO_FRAGMENT(o)
    60.                 return o;
    61.             }
    62.             fixed4 frag(VertexOutput i) : COLOR {
    63.                 i.normalDir = normalize(i.normalDir);
    64.                 float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
    65. /////// Normals:
    66.                 float3 normalDirection =  i.normalDir;
    67.              
    68.                 float nSign = sign( dot( viewDirection, i.normalDir ) ); // Reverse normal if this is a backface
    69.                 i.normalDir *= nSign;
    70.                 normalDirection *= nSign;
    71.              
    72.                 float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);
    73. ////// Lighting:
    74.                 float attenuation = SUNSHINE_ATTENUATION(i);
    75.                 float3 attenColor = attenuation * _LightColor0.xyz;
    76.                 float Pi = 3.141592654;
    77.                 float InvPi = 0.31830988618;
    78. /////// Diffuse:
    79.                 float NdotL = dot( normalDirection, lightDirection );
    80.                 float3 diffuse = max( 0.0, NdotL)*InvPi * attenColor + UNITY_LIGHTMODEL_AMBIENT.rgb;
    81. ////// Emissive:
    82.                 float3 emissive = (pow(1.0-max(0,dot(normalDirection, viewDirection)),_FresnelPower)*_IntensidadFresnel*_LightColor0.rgb);
    83.                 float3 finalColor = 0;
    84.                 float3 diffuseLight = diffuse;
    85.                 float4 node_3 = texCUBElod(_Dif_Cube,float4(i.normalDir,2.0));
    86.                 diffuseLight += (node_3.rgb*(node_3.a*1.0)); // Diffuse Ambient Light
    87.                 finalColor += diffuseLight * (i.vertexColor.rgb*2.0);
    88.                 finalColor += emissive;
    89. /// Final Color:
    90.                 return fixed4(finalColor,1);
    91.             }
    92.             ENDCG
    93.         }
    94.         Pass {
    95.             Name "ForwardAdd"
    96.             Tags {
    97.                 "LightMode"="ForwardAdd"
    98.             }
    99.             Blend One One
    100.             Cull Off
    101.          
    102.          
    103.             Fog { Color (0,0,0,0) }
    104.             CGPROGRAM
    105.             #pragma vertex vert
    106.             #pragma fragment frag
    107.             #define UNITY_PASS_FORWARDADD
    108.             #include "UnityCG.cginc"
    109.             #include "AutoLight.cginc"
    110.             #include "Assets/Sunshine/Shaders/Sunshine.cginc"
    111.             #pragma multi_compile SUNSHINE_DISABLED SUNSHINE_FILTER_HARD
    112.             #pragma multi_compile_fwdadd_fullshadows
    113.             #pragma target 3.0
    114.             #pragma glsl
    115.             uniform float4 _LightColor0;
    116.             uniform float _FresnelPower;
    117.             uniform float _IntensidadFresnel;
    118.             struct VertexInput {
    119.                 float4 vertex : POSITION;
    120.                 float3 normal : NORMAL;
    121.                 float4 Color : COLOR;
    122.             };
    123.             struct VertexOutput {
    124.                 float4 pos : SV_POSITION;
    125.                 float4 posWorld : TEXCOORD0;
    126.                 float3 normalDir : TEXCOORD1;
    127.                 float4 vertexColor : COLOR;
    128.                 SUNSHINE_INPUT_PARAMS;
    129.                 LIGHTING_COORDS(2,3)
    130.             };
    131.             VertexOutput vert (VertexInput v) {
    132.                 VertexOutput o;
    133.                 o.vertexColor = v.Color;
    134.                 o.normalDir = mul(float4(v.normal,0), _World2Object).xyz;
    135.                 o.posWorld = mul(_Object2World, v.vertex);
    136.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    137.                 SUNSHINE_WRITE_VERTEX(v, o);
    138.                 TRANSFER_VERTEX_TO_FRAGMENT(o)
    139.                 return o;
    140.             }
    141.             fixed4 frag(VertexOutput i) : COLOR {
    142.                 i.normalDir = normalize(i.normalDir);
    143.                 float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
    144. /////// Normals:
    145.                 float3 normalDirection =  i.normalDir;
    146.              
    147.                 float nSign = sign( dot( viewDirection, i.normalDir ) ); // Reverse normal if this is a backface
    148.                 i.normalDir *= nSign;
    149.                 normalDirection *= nSign;
    150.              
    151.                 float3 lightDirection = normalize(lerp(_WorldSpaceLightPos0.xyz, _WorldSpaceLightPos0.xyz - i.posWorld.xyz,_WorldSpaceLightPos0.w));
    152. ////// Lighting:
    153.                 float attenuation = SUNSHINE_ATTENUATION(i);
    154.                 float3 attenColor = attenuation * _LightColor0.xyz;
    155.                 float Pi = 3.141592654;
    156.                 float InvPi = 0.31830988618;
    157. /////// Diffuse:
    158.                 float NdotL = dot( normalDirection, lightDirection );
    159.                 float3 diffuse = max( 0.0, NdotL)*InvPi * attenColor;
    160.                 float3 finalColor = 0;
    161.                 float3 diffuseLight = diffuse;
    162.                 finalColor += diffuseLight * (i.vertexColor.rgb*2.0);
    163. /// Final Color:
    164.                 return fixed4(finalColor * 1,0);
    165.             }
    166.             ENDCG
    167.         }
    168.     }
    169.     FallBack "Diffuse"
    170.     CustomEditor "ShaderForgeMaterialInspector"
    171. }
    172.  
     
  49. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Strange, I'm able to compile your shader for my Nexus 7 without an error. Perhaps it's a difference between Mac/Windows in the GLSL compiler? I'll try virtualizing Windows and see if I can reproduce the errors.

    Edit: Looks like it works on Android, but it doesn't seem to like compiling for iOS. I'm actually not sure why that is... hmm..
     
    Last edited: Aug 4, 2014
  50. goldencruz

    goldencruz

    Joined:
    Oct 2, 2013
    Posts:
    94
    will this work with unistorm by chance