Unity Community


Page 3 of 5 FirstFirst 12345 LastLast
Results 41 to 60 of 91

  1. Location
    Thailand
    Posts
    436
    You cannot rotate the sphere, you have to offset the textures, same result visually.
    Last edited by nikko; 01-05-2011 at 06:24 AM.


  2. Location
    Land of wine & cheese
    Posts
    841
    Was referring not to rotation (easy enough to resolve) but rather the "scale / world position" issues; if I recall, by default, the effect fails if the planet is anywhere other than 0,0,0 and there were some strange scale issues as well.

    As mentioned, already managed to sort them out, but if you're maintaining the code & charging for it, might be nice to include similar fixes.
    ByDesign Games
    Fresh Fun Games
    http://www.bydesigngames.com


  3. Location
    Thailand
    Posts
    436
    Did you successfully solved the rotation issue ( I haven't)
    The scale issue is not really an issue, you have to change proportionally the inside and outside bounds of the ground and atmosphere shaders.
    ( scale : 1000, in 995, out 1100 / scale 500, in 497, out 1050 as an example)
    To resume, if you x2 the size you have to x2 the in and out of the ground and atmosphere.


  4. Location
    Hawaii
    Posts
    17
    Hows this coming? from the images it looks amazing. Nikko - any word on when this will be up for purchase or how much it will cost/license/etc?


  5. Location
    Dallas, Tx
    Posts
    1,251
    Awesome work!
    I don't suppose anyone could post some sample parameters to use, or such? Having trouble getting anything but a black ball.



  6. Posts
    197
    Quote Originally Posted by m-a
    great job!


  7. Location
    Dallas, Tx
    Posts
    1,251
    This would be even MORE awesome
    if someone would post a sample project, with values used, for the shaders.


  8. Posts
    9
    Cool stuff!
    I tryed modified this PRD shader to atmospheric scattering from groung but fail ))
    How port this shader to unity, using PRD shader work ?


    Its original glsl shader "SkyFromAtmosphere"

    Code:  
    1. //
    2. // Atmospheric scattering vertex shader
    3. //
    4. // Author: Sean O'Neil
    5. //
    6. // Copyright (c) 2004 Sean O'Neil
    7. //
    8.  
    9. uniform vec3 v3CameraPos;       // The camera's current position
    10. uniform vec3 v3LightPos;        // The direction vector to the light source
    11. uniform vec3 v3InvWavelength;   // 1 / pow(wavelength, 4) for the red, green, and blue channels
    12. uniform float fCameraHeight;    // The camera's current height
    13. uniform float fCameraHeight2;   // fCameraHeight^2
    14. uniform float fOuterRadius;     // The outer (atmosphere) radius
    15. uniform float fOuterRadius2;    // fOuterRadius^2
    16. uniform float fInnerRadius;     // The inner (planetary) radius
    17. uniform float fInnerRadius2;    // fInnerRadius^2
    18. uniform float fKrESun;          // Kr * ESun
    19. uniform float fKmESun;          // Km * ESun
    20. uniform float fKr4PI;           // Kr * 4 * PI
    21. uniform float fKm4PI;           // Km * 4 * PI
    22. uniform float fScale;           // 1 / (fOuterRadius - fInnerRadius)
    23. uniform float fScaleDepth;      // The scale depth (i.e. the altitude at which the atmosphere's average density is found)
    24. uniform float fScaleOverScaleDepth; // fScale / fScaleDepth
    25.  
    26. uniform int nSamples;
    27. uniform float fSamples;
    28.  
    29. varying vec3 v3Direction;
    30.  
    31.  
    32. float scale(float fCos)
    33. {
    34.     float x = 1.0 - fCos;
    35.     return fScaleDepth * exp(-0.00287 + x*(0.459 + x*(3.83 + x*(-6.80 + x*5.25))));
    36. }
    37.  
    38. void main(void)
    39. {
    40.     // Get the ray from the camera to the vertex, and its length (which is the far point of the ray passing through the atmosphere)
    41.     vec3 v3Pos = gl_Vertex.xyz;
    42.     vec3 v3Ray = v3Pos - v3CameraPos;
    43.     float fFar = length(v3Ray);
    44.     v3Ray /= fFar;
    45.  
    46.     // Calculate the ray's starting position, then calculate its scattering offset
    47.     vec3 v3Start = v3CameraPos;
    48.     float fHeight = length(v3Start);
    49.     float fDepth = exp(fScaleOverScaleDepth * (fInnerRadius - fCameraHeight));
    50.     float fStartAngle = dot(v3Ray, v3Start) / fHeight;
    51.     float fStartOffset = fDepth*scale(fStartAngle);
    52.  
    53.     // Initialize the scattering loop variables
    54.     //gl_FrontColor = vec4(0.0, 0.0, 0.0, 0.0);
    55.     float fSampleLength = fFar / fSamples;
    56.     float fScaledLength = fSampleLength * fScale;
    57.     vec3 v3SampleRay = v3Ray * fSampleLength;
    58.     vec3 v3SamplePoint = v3Start + v3SampleRay * 0.5;
    59.  
    60.     // Now loop through the sample rays
    61.     vec3 v3FrontColor = vec3(0.0, 0.0, 0.0);
    62.     for(int i=0; i<nSamples; i++)
    63.     {
    64.         float fHeight = length(v3SamplePoint);
    65.         float fDepth = exp(fScaleOverScaleDepth * (fInnerRadius - fHeight));
    66.         float fLightAngle = dot(v3LightPos, v3SamplePoint) / fHeight;
    67.         float fCameraAngle = dot(v3Ray, v3SamplePoint) / fHeight;
    68.         float fScatter = (fStartOffset + fDepth*(scale(fLightAngle) - scale(fCameraAngle)));
    69.         vec3 v3Attenuate = exp(-fScatter * (v3InvWavelength * fKr4PI + fKm4PI));
    70.         v3FrontColor += v3Attenuate * (fDepth * fScaledLength);
    71.         v3SamplePoint += v3SampleRay;
    72.     }
    73.  
    74.     // Finally, scale the Mie and Rayleigh colors and set up the varying variables for the pixel shader
    75.     gl_FrontSecondaryColor.rgb = v3FrontColor * fKmESun;
    76.     gl_FrontColor.rgb = v3FrontColor * (v3InvWavelength * fKrESun);
    77.     gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
    78.     v3Direction = v3CameraPos - v3Pos;
    79. }

    Code:  
    1. //
    2. // Atmospheric scattering fragment shader
    3. //
    4. // Author: Sean O'Neil
    5. //
    6. // Copyright (c) 2004 Sean O'Neil
    7. //
    8.  
    9. uniform vec3 v3LightPos;
    10. uniform float g;
    11. uniform float g2;
    12.  
    13. varying vec3 v3Direction;
    14.  
    15.  
    16. void main (void)
    17. {
    18.     float fCos = dot(v3LightPos, v3Direction) / length(v3Direction);
    19.     float fRayleighPhase = 0.75 * (1.0 + fCos*fCos);
    20.     float fMiePhase = 1.5 * ((1.0 - g2) / (2.0 + g2)) * (1.0 + fCos*fCos) / pow(1.0 + g2 - 2.0*g*fCos, 1.5);
    21.     gl_FragColor = fRayleighPhase * gl_Color + fMiePhase * gl_SecondaryColor;
    22.     //gl_FragColor.a = gl_FragColor.b;
    23. }

    Its sources from GpuGems2 ch 16
    http://http.download.nvidia.com/deve...Content/16.zip


  9. Posts
    9
    Well done its "work" ))
    But i dont know true parameters for c# script
    Math is not my hobby ))

    Code:  
    1. Shader "AtmosphereFromEarth" {
    2.     Properties {
    3.       _v4CameraPos("Camera Position",Vector) = (0,0,0,0)
    4.       _v4LightDir("Light Direction",Vector) = (0,0,0,0)
    5.       _cInvWaveLength("Inverse WaveLength",Color) = (0,0,0,0)
    6.       _fCameraHeight("Camera Height",Float) = 0
    7.       _fCameraHeight2("Camera Height2",Float) = 0
    8.       _fOuterRadius("Outer Radius",Float) = 0
    9.       _fOuterRadius2("Outer Radius 2",Float) = 0
    10.       _fInnerRadius("Inner Radius",Float) = 0
    11.       _fInnerRadius2("Inner Radius 2",Float) = 0
    12.       _fKrESun("KrESun",Float) = 0
    13.       _fKmESun("KmESun",Float) = 0
    14.       _fKr4PI("Kr4PI",Float) = 0
    15.       _fKm4PI("Km4PI",Float) = 0
    16.       _fScale("Scale",Float) = 0
    17.       _fScaleDepth("Scale Depth",Float) = 0
    18.       _fScaleOverScaleDepth("Scale Over Scale Depth",Float) = 0
    19.       _Samples("Samples",Float) = 0
    20.       _G("G",Float) = 0
    21.       _G2("G2",Float) = 0
    22.     }
    23.     SubShader {
    24.       Tags {"Queue" = "Transparent" }
    25.       Pass {
    26.         Cull Front
    27.         Blend One One
    28.        
    29. CGPROGRAM
    30. #pragma vertex vert
    31. #pragma fragment frag
    32. #include "UnityCG.cginc"
    33.  
    34. float4 _v4CameraPos;
    35. float4 _v4LightDir;
    36. float4 _cInvWaveLength;
    37. float _fCameraHeight;
    38. float _fCameraHeight2;   
    39. float _fOuterRadius;
    40. float _fOuterRadius2;     
    41. float _fInnerRadius;
    42. float _fInnerRadius2;
    43. float _fKrESun;
    44. float _fKmESun;
    45. float _fKr4PI;
    46. float _fKm4PI;
    47. float _fScale;
    48. float _fScaleDepth;
    49. float _fScaleOverScaleDepth;
    50. float _Samples;
    51. float _G;
    52. float _G2;
    53.  
    54. struct v2f {
    55.   float4 position : POSITION;
    56.   float3 c0 : COLOR0;
    57.   float3 c1 : COLOR1;
    58.   float3 t0 : TEXCOORD0;
    59. };
    60.  
    61.  
    62. float expScale (float cos) {
    63.     float x = 1 - cos;
    64.     return _fScaleDepth * exp(-0.00287 + x*(0.459 + x*(3.83 + x*(-6.80 + x*5.25))));
    65. }
    66.  
    67. v2f vert (float4 vertex : POSITION) {  
    68.   float3 v3Pos = vertex.xyz;
    69.   float3 v3Ray = v3Pos - _v4CameraPos.xyz;
    70.   float fFar = length(v3Ray);
    71.   v3Ray /= fFar;   
    72.  
    73.  // Calculate the ray's starting position, then calculate its scattering offset
    74. float3 v3Start = v3Pos;
    75. float v3StartAngle = dot(v3Ray,v3Start) / _fOuterRadius;
    76. float v3StartDepth = exp (_fScaleOverScaleDepth * (_fInnerRadius - _fCameraHeight));
    77. float v3StartOffset = v3StartDepth * expScale(v3StartAngle);
    78.  
    79.   float fSampleLength = fFar / _Samples;
    80.   float fScaledLength = fSampleLength * _fScale;
    81.   float3 sampleRay = v3Ray * fSampleLength;
    82.   float3 samplePoint = v3Start + sampleRay * 0.5f;
    83.  
    84.   float3 frontColor = float3(0,0,0);
    85.   float3 attenuate;
    86.  
    87.   for (int i = 0; i < 1; i++) {
    88.     float height = length (samplePoint);
    89.     float depth = exp(_fScaleOverScaleDepth * (_fInnerRadius - height));
    90.     float lightAngle = dot(_v4LightDir.xyz, samplePoint) / height;
    91.     float cameraAngle = dot(-v3Ray, samplePoint) / height;
    92.     float scatter = (v3StartOffset + depth * (expScale (lightAngle) - expScale (cameraAngle)));
    93.  
    94.     attenuate = exp(-scatter * (_cInvWaveLength.xyz * _fKr4PI + _fKm4PI));
    95.     frontColor += attenuate * (depth * fScaledLength);
    96.     samplePoint += sampleRay;
    97.   }
    98.  
    99.   v2f OUT;
    100.   OUT.position = mul( glstate.matrix.mvp, vertex);
    101.   OUT.t0 = _v4CameraPos.xyz - vertex.xyz;
    102.   OUT.c0.rgb = frontColor * (_cInvWaveLength.xyz * _fKrESun);
    103.   OUT.c1.rgb = frontColor * _fKmESun;
    104.   return OUT;
    105. }
    106. ////// SkyFromAtmos(Space) frag
    107. float4 frag (v2f INPUT) : COLOR {
    108.   float cos = dot(_v4LightDir.xyz, INPUT.t0) / length(INPUT.t0);
    109.   float cos2 = cos * cos;
    110.   float miePhase = 1.5 * ((1.0 - _G2) / (2.0 + _G2)) * (1.0 + cos2) / pow(1.0 + _G2 - 2.0*_G*cos, 1.5);
    111.   float rayleighPhase = 0.75 * (1.0 + cos2);
    112.   float4 fragColor;
    113.  
    114.   fragColor.xyz = (rayleighPhase * INPUT.c0) + (miePhase * INPUT.c1);
    115.   fragColor.w = fragColor.z;
    116.   return fragColor; 
    117. }
    118.  
    119. ENDCG   
    120.       }
    121.     }
    122.     FallBack "None"
    123. }


  10. Location
    France
    Posts
    9
    If you want to make a SkyFromAtmosphere shader you can try what i've made using Sean O'Neil's shaders and the scripts form the forum.

    It's really like what you've made, gonza, but there are 3 places where i got different things after copying form O'Neil's shaders.

    Edit: Diffs:

    float cameraAngle = dot(-v3Ray,dot(v3Ray, samplePoint) / height;

    float v3StartDepth = exp (_fScaleOverScaleDepth * (_fInnerRadius( - _fInnerRadius + _fCameraHeight));

    float3 v3Start = v3Pos _v4CameraPos.xyz;


    Hope it will help.

    Screenshots :








    Code :


    Code:  
    1. Shader "NewShader" {
    2.    Properties {
    3.      _v4CameraPos("Camera Position",Vector) = (0,0,0,0)
    4.      _v4LightDir("Light Direction",Vector) = (0,0,0,0)
    5.      _cInvWaveLength("Inverse WaveLength",Color) = (0,0,0,0)
    6.      _fCameraHeight("Camera Height",Float) = 0
    7.      _fCameraHeight2("Camera Height2",Float) = 0
    8.      _fOuterRadius("Outer Radius",Float) = 0
    9.      _fOuterRadius2("Outer Radius 2",Float) = 0
    10.      _fInnerRadius("Inner Radius",Float) = 0
    11.      _fInnerRadius2("Inner Radius 2",Float) = 0
    12.      _fKrESun("KrESun",Float) = 0
    13.      _fKmESun("KmESun",Float) = 0
    14.      _fKr4PI("Kr4PI",Float) = 0
    15.      _fKm4PI("Km4PI",Float) = 0
    16.      _fScale("Scale",Float) = 0
    17.      _fScaleDepth("Scale Depth",Float) = 0
    18.      _fScaleOverScaleDepth("Scale Over Scale Depth",Float) = 0
    19.      _Samples("Samples",Float) = 0
    20.      _G("G",Float) = 0
    21.      _G2("G2",Float) = 0
    22.    }
    23.    SubShader {
    24.      Tags {"Queue" = "Transparent" }
    25.       Pass {
    26.          Cull Front
    27.          Blend One One
    28.          
    29. CGPROGRAM
    30. #pragma vertex vert
    31. #pragma fragment frag
    32. #include "UnityCG.cginc"
    33.  
    34. float4 _v4CameraPos;
    35. float4 _v4LightDir;
    36. float4 _cInvWaveLength;
    37. float _fCameraHeight;
    38. float _fCameraHeight2;    
    39. float _fOuterRadius;
    40. float _fOuterRadius2;    
    41. float _fInnerRadius;
    42. float _fInnerRadius2;
    43. float _fKrESun;
    44. float _fKmESun;
    45. float _fKr4PI;
    46. float _fKm4PI;
    47. float _fScale;
    48. float _fScaleDepth;
    49. float _fScaleOverScaleDepth;
    50. float _Samples;
    51. float _G;
    52. float _G2;
    53.  
    54. struct v2f {
    55.   float4 position : POSITION;
    56.   float3 c0 : COLOR0;
    57.   float3 c1 : COLOR1;
    58.   float3 t0 : TEXCOORD0;
    59. };
    60.  
    61. float expScale (float cos) {
    62.    float x = 1 - cos;
    63.    return _fScaleDepth * exp(-0.00287 + x*(0.459 + x*(3.83 + x*(-6.80 + x*5.25))));
    64. }
    65.  
    66. v2f vert (float4 vertex : POSITION) {
    67.   float3 v3Pos = vertex.xyz;
    68.   float3 v3Ray = v3Pos - _v4CameraPos.xyz;
    69.   float fFar = length(v3Ray);
    70.   v3Ray /= fFar;  
    71.  
    72. float3 v3Start = _v4CameraPos.xyz;
    73.  
    74.  
    75.   float v3StartAngle = dot(v3Ray,v3Start) / length(v3Start);
    76.  
    77.   float v3StartDepth = exp (_fScaleOverScaleDepth * ( - _fInnerRadius + _fCameraHeight));
    78.  
    79.   float v3StartOffset = v3StartDepth * expScale(v3StartAngle);
    80.  
    81.   float fSampleLength = fFar / _Samples;
    82.   float fScaledLength = fSampleLength * _fScale;
    83.   float3 sampleRay = v3Ray * fSampleLength;
    84.   float3 samplePoint = v3Start + sampleRay * 0.5f;
    85.  
    86.   float3 frontColor = float3(0,0,0);
    87.   float3 attenuate;
    88.  
    89.   for (int i = 0; i < 1; i++) {
    90.     float height = length (samplePoint);
    91.     float depth = exp(_fScaleOverScaleDepth * (_fInnerRadius - height));
    92.     float lightAngle = dot(_v4LightDir.xyz, samplePoint) / height;
    93.     float cameraAngle = dot(v3Ray, samplePoint) / height;
    94.     float scatter = (v3StartOffset + depth * (expScale (lightAngle) - expScale (cameraAngle)));
    95.  
    96.     attenuate = exp(-scatter * (_cInvWaveLength.xyz * _fKr4PI + _fKm4PI));
    97.     frontColor += attenuate * (depth * fScaledLength);
    98.     samplePoint += sampleRay;
    99.   }
    100.  
    101.   v2f OUT;
    102.   OUT.position = mul( glstate.matrix.mvp, vertex);
    103.   OUT.t0 = _v4CameraPos.xyz - vertex.xyz;
    104.   OUT.c0.rgb = frontColor * (_cInvWaveLength.xyz * _fKrESun);
    105.   OUT.c1.rgb = frontColor * _fKmESun;
    106.   return OUT;
    107. }
    108.  
    109. float4 frag (v2f INPUT) : COLOR {
    110.   float cos = dot(_v4LightDir.xyz, INPUT.t0) / length(INPUT.t0);
    111.   float cos2 = cos * cos;
    112.   float miePhase = 1.5 * ((1.0 - _G2) / (2.0 + _G2)) * (1.0 + cos2) / pow(1.0 + _G2 - 2.0*_G*cos, 1.5);
    113.   float rayleighPhase = 0.75 * (1.0 + cos2);
    114.  
    115.   //fmiePhase *= 0.0015 * 15;
    116.   //rayleighPhase *= 0.0025 * 15;
    117.  
    118.   float4 fragColor;
    119.  
    120.   fragColor.xyz = (rayleighPhase * INPUT.c0) + (miePhase * INPUT.c1);
    121.   fragColor.w = fragColor.z;
    122.  
    123.   if(fragColor.x > 1.0){ fragColor.x = 1.0;}
    124.   if(fragColor.y > 1.0){ fragColor.y = 1.0;}
    125.   if(fragColor.z > 1.0){ fragColor.z = 1.0;}
    126.  
    127.   return fragColor;  
    128. }
    129.  
    130. ENDCG  
    131.       }
    132.    }
    133.    FallBack "None"
    134. }

    Code:  
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class NewShader : MonoBehaviour {
    5.  
    6.     public Transform mainCamera;
    7.     public GameObject sunLight;
    8.     private Vector3 sunLightDirection;
    9.     private Color waveLength;
    10.     private Color invWaveLength;
    11.     private float cameraHeight;
    12.     private float cameraHeight2;
    13.     private float outerRadius;
    14.     private float outerRadius2;
    15.     private float innerRadius;
    16.     private float innerRadius2;
    17.     public float ESun;
    18.     public float Kr;
    19.     public float Km;
    20.     private float KrESun;
    21.     private float KmESun;
    22.     private float Kr4PI;
    23.     private float Km4PI;
    24.     private float scale;
    25.     private float scaleDepth;
    26.     private float scaleOverScaleDepth;
    27.     private float samples;
    28.     private float g;
    29.     private float g2;
    30.    
    31.     void Start() {
    32.       sunLight = GameObject.Find("Sun");
    33.       mainCamera = GameObject.Find("Main Camera").transform;
    34.       sunLightDirection = sunLight.transform.TransformDirection (-Vector3.forward);
    35.       waveLength = new Color(0.650f, 0.570f, 0.475f, 0.5f);
    36.       invWaveLength = new Color (pow(waveLength[0],4),pow(waveLength[1],4),pow(waveLength[2],4),0.5f);
    37.       cameraHeight = mainCamera.position.magnitude;
    38.       outerRadius = 6530.28f;
    39.       outerRadius2 = outerRadius * outerRadius;
    40.       innerRadius = 6371;
    41.       innerRadius2 = innerRadius * innerRadius;
    42.       ESun = 15;
    43.       Kr = 0.0025f;
    44.       Km = 0.0015f;
    45.       KrESun = Kr * ESun;
    46.       KmESun = Km * ESun;
    47.       Kr4PI = Kr * 4.0f * Mathf.PI;
    48.       Km4PI = Km * 4.0f * Mathf.PI;
    49.       scale = 1 / (outerRadius - innerRadius);
    50.       scaleDepth = 0.25f;
    51.       scaleOverScaleDepth = scale / scaleDepth;
    52.       samples = 4;
    53.       g = -0.85f;
    54.       g2 = g*g;
    55.     }
    56.    
    57.     //void OnGUI() {
    58.       //if (debug) {
    59.         //waveLength = DebugUtility.RGBSlider (new Rect (10,10,100,20), waveLength);
    60.         //ESun = DebugUtility.LabelSlider(new Rect (10,70,100,20), ESun, 50,"ESun: " + ESun );
    61.         //Kr = DebugUtility.LabelSlider(new Rect (10,90,100,20), Kr, 0.01f,"Kr: " + Kr);
    62.         //Km = DebugUtility.LabelSlider(new Rect (10,110,100,20), Km, 0.01f,"Km: " + Km);
    63.         //scaleDepth = DebugUtility.LabelSlider(new Rect (10,130,100,20), scaleDepth, 1.0f,"Scale Depth: " + scaleDepth);
    64.         //g = DebugUtility.LabelSlider(new Rect (10,150,100,20), g, -1.0f,"G: " + g);
    65.       //}
    66.     //}
    67.    
    68.     // Update is called once per frame
    69.     void LateUpdate () {
    70.        
    71.       KrESun = Kr * ESun;
    72.       KmESun = Km * ESun;
    73.       Kr4PI = Kr * 4.0f * Mathf.PI;
    74.       Km4PI = Km * 4.0f * Mathf.PI;
    75.        
    76.       sunLightDirection = sunLight.transform.TransformDirection (-Vector3.forward);
    77.       cameraHeight = mainCamera.position.magnitude;
    78.       cameraHeight2 = cameraHeight * cameraHeight;
    79.      
    80.       // Pass in variables to the Shader
    81.       renderer.material.SetVector("_v4CameraPos",new Vector4(mainCamera.position[0],mainCamera.position[1],mainCamera.position[2], 0));
    82.      
    83.       renderer.material.SetVector("_v4LightDir", new Vector4(sunLightDirection[0],sunLightDirection[1],sunLightDirection[2],0));
    84.       renderer.material.SetColor("_cInvWaveLength", invWaveLength);
    85.       renderer.material.SetFloat("_fCameraHeight", cameraHeight);
    86.       renderer.material.SetFloat("_fCameraHeight2", cameraHeight2);
    87.       renderer.material.SetFloat("_fOuterRadius", outerRadius);
    88.       renderer.material.SetFloat("_fOuterRadius2", outerRadius2);
    89.       renderer.material.SetFloat("_fInnerRadius", innerRadius);
    90.       renderer.material.SetFloat("_fInnerRadius2", innerRadius2);
    91.       renderer.material.SetFloat("_fKrESun",KrESun);
    92.       renderer.material.SetFloat("_fKmESun",KmESun);
    93.       renderer.material.SetFloat("_fKr4PI",Kr4PI);
    94.       renderer.material.SetFloat("_fKm4PI",Km4PI);
    95.       renderer.material.SetFloat("_fScale",scale);
    96.       renderer.material.SetFloat("_fScaleDepth",scaleDepth);
    97.       renderer.material.SetFloat("_fScaleOverScaleDepth",scaleOverScaleDepth);
    98.       renderer.material.SetFloat("_Samples",samples);
    99.       renderer.material.SetFloat("_G",g);
    100.       renderer.material.SetFloat("_G2",g2);
    101.     }
    102.    
    103.     float pow(float f, int p) {
    104.       return 1 / Mathf.Pow(f,p);
    105.     }
    106. }


  11. Posts
    3
    Hey all,

    I was just wondering if anyone has tried these Shaders in Unity 3.0?

    The reason I ask is that, try as I might, I cannot get them to work and hence was wondering if anyone else has these problems. I hooked them up to my own scene and subsequently downloaded the example provided by PRD, but no luck.

    Any suggestions would be welcome!

    q


  12. Location
    France
    Posts
    9
    I also tried to rewrite the shaders for Unity 3.0 but it's not working.
    If someone can give hints to how to convert the shaders to 3.0, he' ll be welcome.

    [Edit] I think i found the solution with surface shaders, i'm on my way, starting with SkyFromGround...
    Last edited by Sbach; 11-07-2010 at 07:50 AM.

  13. PRD PRD is offline

    Posts
    29
    I am going to try to rewrite these as surface shaders as well. I will post them when we finish moving our project into Unity3. This will include SkyFromGround, SkyFromSpace and GroundFromSpace.


  14. Location
    Belarus
    Posts
    721
    If these shaders do not need to react to Unity's lighting, then there's no need for implementing them as a surface shader, afaik.


  15. Location
    Montreal, Canada
    Posts
    10
    Hm. Not to bump this pre-emptively, but has there been any motion on this, PRD? I'm looking at your prior example in Unity 3, and I still can't seem to make it work (for one thing, the vertex shader gets unrolled by CG and shatters the instruction limit).

    Any thoughts?


  16. Location
    Thailand
    Posts
    436
    I am in the process to make something similar. I got the GroundFromSpace shader with day/night and some kind of custom bump mapping but I had to partially change the Neil algorithm and use a gradient to get a good visual result it took me weeks to get it to work...

    For the atmosphere I have sent a bug report (case #388467) with several example of what I think makes this shader not compatible with Unity 3.
    Logically there is no need to use surface shader, because there is no interaction with the light or the shadows. I think there is maybe a bug in the blending system that prevent this shader to work? I have submitted the source code with the bug report, hopefully I will get some interesting answer soon. Still working on it when I have some free time.
    Attached Images  
    Last edited by nikko; 01-17-2011 at 06:11 AM.


  17. Posts
    413
    Sorry to resurrect this post, but I'm in real need of an atmospheric scattering setup, and my knowledge of shader programming is really not up to the task (to say the least)...

    So, I've downloaded the package from page 2 and imported into my project, but it doesn't look at all like the screenshots... tweaking the shader parameters I sometimes get a grayish gradient, that looks real bad, and that's as far as I got...

    I also created shaders from pretty much all the code posted on this thread, but that worked even less, since the shader needs a script to keep it updated, and that requires knowing what values to give to those parameters... regardless, even tweaking up a looks-good-from-one-angle situation by pure trial-and-error, I can't get anything that looks even remotely similar to the shots here...

    I notice scale has a big impact on the shaders... but I'm at a loss as to how to figure out those values...

    Also, I'm on Unity 3.2... Are the shaders completely incompatible?
    (None of the webplayer previews posted seem to work for me... the player crashes every time)

    (GPU is Nvidia GTX460... more recent than the original shader itself )

    So, can anyone offer any help on this?

    As always, thanks in advance!!

    Cheers
    Last edited by HarvesteR; 03-08-2011 at 12:54 PM.
    The limit of the willing suspension of disbelief for a given element is directly proportional to the element's coolness.

  18. Tried PRD's atmospheric scattering example but the atmosphere doesn't work. I tried fixing it myself but I'm horrible when it comes to math + programming. Is this because of Unity 3? Do you need pro for this to work? Help?


  19. Posts
    413
    Ok, I got the shaders to work on Unity 3. (Pro, but shouldn't matter)...

    It really wasn't easy... took me a few days of trying...

    I could only get it to work after reading Sean O'Neil's article some 4 or 5 times... and understanding exactly what each parameter is and how it's calculated.
    Then I got a sphere, and gave it the AtmosphereFromSpace shader, without the controller script, and tweaked the values until I saw something change... then I went about changing and unchanging things until I saw that it did in fact work.

    I then had to modify the controller scripts a little to allow for experimenting and tweaking... this script is feeding the shader it's values, so it'll lock the editor controls...

    First thing I did was to make every single variable public, and comment out some arbitrary values that are fed into it on Start(), so I could tweak them in the editor... then I put some code in the update function to keep the values that are derived from others updated... and got to tweaking...

    So here's what I've found:

    Scale does NOT actually matter... what matters is that OuterRadius and InnerRadius are in proportion to the world radius of the sphere object.
    For the sphere object, I highly recommend using a sphere that is 1 unit in radius... this way, it's scale property will also be it's world radius and you'll save yourself a big headache. The atmosphere_100 mesh that comes included works fine for that.

    Outer Radius must be exactly the sphere's radius.
    Inner radius must be Outer Radius * 0.975... 2.5% less than the atmosphere's radius. This is the most important thing... the atmosphere only works with real-world proportions, so if your world is 100 units in radius, your atmosphere should be 102.5 units.
    The paper says if you would tweak that proportion, you must also account for the hard-coded density and depth equations there... those were hardcoded in, since the shader was much too heavy with the original calculations... I actually tried to modify the scale depth equation, but if you (like me) aren't really good at calculus and numerical analysis, I'd say don't go there...

    The shader can also fail if the sphere is perfectly round... (don't ask)... what I did to solve this was to give it a little nudge on it's x scale, from 100 to 100.1... pretty unnoticeable by eye, and it made the shader work... I guess these shaders account for the oblateness of Earth? Or it may just be a bug...

    One more thing... the controller scripts have public fields for the sun light and the target camera, and you might me inclined to drag and drop yours in... then you get an error... turns out that despite having a public reference to those objects, the scripts are trying to find them by name on Start()... I just commented those lines out, so I could have my own objects with whatever names I wished them to have.

    BTW, if you're trying (like me) to make some kind of accurate scale model of a planet with this, Unity will wrong you when you try to make your sphere a few dozen km wide... unity is no good with very large objects, and floats will lose precision and actually cause framerate losses when they're too small (really small numbers happen a lot on really big scales)... what I did was have 2 'scenes' within the scene...

    One is the main game scene, where 1 unit = 1 meter, so as to not upset physX and it's rigid scaling thing. The other has the planet as a 100 unit radius sphere (actually, one for each shader), and a camera with a controller script that will have it follow the motions of the main camera, but on a proportional scale... this camera renders behind the main one, and that worked quite well ...This approach will also work for planets that should be somewhere other than world 0,0,0... just have your scaled 'subscene' there, and the actual planet somewhere else.

    I also strongly suggest writing or grabbing a Sun script to control your sun light's position (there's one in the Wiki, IIRC). This will make it easier (and awesomer) to test out different values and see how that affects every phase of the day, without having to pan around to be on different 'time zones' and see the effect from there.

    Well, that's about all the help I can offer at this point. I'm still trying to tweak it so it looks more realistic... right now it looks pretty much as the screenshots from the previous pages... I'm trying to make the atmosphere seem thicker... right now it looks way to tenuous, which might be good for a NASA web app (which was it's original purpose I believe), but doesn't really cut it for a game taking place on a planet's surface...

    Has anyone been able to tweak the apparent atmospheric density, without screwing up other things? This shader is VERY finnicky, and all tweaks must be done with the greatest caution... Some values will range from 0.000something to 0.001something... and unity's inspector will very easily overrun those values as you drag them about, which makes it really hard to fine-tune it...
    What I'm trying to achieve is an almost white horizon line, and a dark-ish blue zenith at surface level.... right now it's more like a darkish blue at horizon and a pitch black zenith, as if the atmosphere was actually 100x thinner than what it's supposed to be... I heard PRD (or Nikko, can't remember) toned it down for his purpose, so I wonder if the shaders included here are the toned down versions...

    Thanks in advance for any help on this

    Cheers
    The limit of the willing suspension of disbelief for a given element is directly proportional to the element's coolness.

Page 3 of 5 FirstFirst 12345 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •