Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9425 for data


Ignore:
Timestamp:
Oct 31, 2012, 6:02:05 PM (12 years ago)
Author:
davidsa
Message:

Improved glow effect, added some minor documentation to the glow.material file.

Location:
data/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • data/trunk/materials/glow.material

    r9424 r9425  
    11vertex_program glow_vs cg
    22{
    3         source vs_glow.cg
    4         entry_point main
    5         profiles vs_1_1 arbvp1
     3        source vs_glow.cg
     4        entry_point main
     5        profiles vs_1_1 arbvp1
    66}
    77
    88fragment_program glow_ps cg
    99{
    10         source ps_glow.cg
    11         entry_point main
    12         profiles ps_2_0 arbfp1 
     10        source ps_glow.cg
     11        entry_point main
     12        profiles ps_2_0 arbfp1 
    1313}
    14 
    1514
    1615material glow
    1716{
    18         technique
    19         {
    20                 pass
    21                 {
    22                         scene_blend alpha_blend
    23                         depth_check on
    24                         lighting off
    25                         emissive 0.5 0.9 1.0 0.0
    26                        
    27                         vertex_program_ref glow_vs
    28                         {
    29                                 param_named_auto worldViewProjMatrix worldviewproj_matrix
    30                                 param_named size_value float 0.3
    31                                 param_named_auto time time_0_x 50
    32                         }
    33                        
    34                         fragment_program_ref glow_ps
    35                         {
    36                                 param_named alpha_value float 0.4
    37                                 param_named_auto time time_0_x 50
    38                                 param_named_auto color surface_emissive_colour
    39                         }
    40                 }
    41                
    42         }
     17        technique
     18        {
     19                pass
     20                {
     21                        scene_blend alpha_blend
     22                        depth_check on
     23                        depth_func less_equal
     24                        lighting off
     25                        emissive 0.5 0.9 1.0 0.0 //what color should the glow be, emissive light can be changed through ogre as well
     26                       
     27                        vertex_program_ref glow_vs
     28                        {
     29                                param_named_auto iWorldTMatrix inverse_transpose_world_matrix //don't worry about auto parameters here, they are given
     30                                param_named_auto iViewMatrix inverse_view_matrix
     31                                param_named_auto worldMatrix   world_matrix
     32                                param_named_auto viewProjMatrix viewproj_matrix
     33                                param_named inflate float 0.05 //how much should the glow expand from the model, usually a small value
     34                        }
     35                       
     36                        fragment_program_ref glow_ps
     37                        {
     38                                param_named alphaValue float 0.5 //base alpha value of glow
     39                                param_named cutoffAngle float 70.0 //from which view to surface normal angle on should the intensity of the glow decrease
     40                                param_named exponent float 2.5 //by which exponent should the intensity decrease
     41                                param_named_auto time time_0_x 50 //how fast should the light pulsate
     42                                param_named_auto color surface_emissive_colour //don't worry about this one, it makes sure we use the emissive color value
     43                        }
     44                }
     45               
     46        }
    4347}
    4448
     
    6771                        vertex_program_ref glow_vs
    6872                        {
    69                                 param_named_auto worldViewProjMatrix worldviewproj_matrix
    70                                 param_named size_value float 0.2
    71                                 param_named_auto time time_0_x 50
     73                                param_named_auto iWorldTMatrix inverse_transpose_world_matrix
     74                                param_named_auto iViewMatrix inverse_view_matrix
     75                                param_named_auto worldMatrix   world_matrix
     76                                param_named_auto viewProjMatrix viewproj_matrix
     77                                param_named inflate float 0.2
    7278                        }
    7379                       
    7480                        fragment_program_ref glow_ps
    7581                        {
    76                                 param_named alpha_value float 0.4
     82                                param_named alphaValue float 0.4
     83                                param_named cutoffAngle float 70.0
     84                                param_named exponent float 2.5
    7785                                param_named_auto time time_0_x 50
    7886                                param_named_auto color surface_emissive_colour
  • data/trunk/programs/ps_glow.cg

    r9408 r9425  
    1 float4 main(uniform float alpha_value, uniform float time, uniform float4 color) : COLOR
     1struct vertexOut
    22{
    3     color.w =  alpha_value * ((sin(time * 5.0) / 3.14 + 1.0) / 2.0 );
     3    float4 position : POSITION;
     4    float2 uv : TEXCOORD0;
     5    float3 worldNormal : TEXCOORD1;
     6    float3 worldView : TEXCOORD2;
     7};
     8
     9float4 main(vertexOut input, uniform float alphaValue, uniform float cutoffAngle, uniform float exponent, uniform float time, uniform float4 color) : COLOR
     10{
     11    float3 Nn = normalize(input.worldNormal);
     12    float3 Vn = normalize(input.worldView);
     13    float alphaMod = dot(Nn, Vn);//this is a measure for how close we are to the edge of a model according to our view
     14    float cutoff=cos(cutoffAngle * 3.14 / 180.0);//pi divided by 180
     15    if(alphaMod<cutoff)//transform output range so it only affects angles close to 90 degrees
     16    {
     17        alphaMod/=cutoff;
     18    }
     19    else
     20    {
     21        alphaMod=1.0;
     22    }
     23    alphaMod = pow(alphaMod,exponent); //how fast should the intensity of the glow decrease
     24    color.w = alphaMod * alphaValue * ((sin(time)/3.14 + 1.0) / 2.0 + 0.1);
    425    return color;
    526}
  • data/trunk/programs/vs_glow.cg

    r9408 r9425  
    1 void main(float4 position : POSITION, float3 normal : NORMAL, float2 uv : TEXCOORD0, out float4 oPosition : POSITION, out float2 oUv : TEXCOORD0, out float4 colour : COLOR,
    2           uniform float4x4 worldViewProjMatrix, uniform float size_value, uniform float time )
     1struct vertexIn
    32{
    4    float4 myPosition = position;
    5    myPosition.xyz += size_value * (1.0 + (sin(time * 5.0) + 1.0)  / 5.0 ) * normal;
    6    oPosition = mul(worldViewProjMatrix, myPosition);
     3    float4 position : POSITION;
     4    float4 normal : NORMAL;
     5    float2 uv : TEXCOORD0;
     6};
     7
     8struct vertexOut
     9{
     10    float4 position : POSITION; //<! transformed position
     11    float2 uv : TEXCOORD0; //<! passing on uv information
     12    float3 worldNormal : TEXCOORD1; //<! surface normal transformed into world
     13    float3 worldView : TEXCOORD2; //<! view direction transformed into world
     14};
     15
     16vertexOut main(vertexIn input, uniform float4x4 iWorldTMatrix, uniform float4x4 iViewMatrix, uniform float4x4 worldMatrix, uniform float4x4 viewProjMatrix, uniform float inflate )
     17{
     18   vertexOut output;
     19   float4 myPosition = input.position;
     20   output.worldNormal=mul(iWorldTMatrix, input.normal).xyz; //transforming the normal
     21   input.normal = normalize(float4(input.normal.xyz,0)); //normalizing the normal according to the three relevant parts
     22   myPosition.xyz += inflate * input.normal; //inflating the model into a bigger shape
     23   myPosition = mul(worldMatrix, myPosition); //transforming position into world
     24   output.worldView = normalize(float3(iViewMatrix[0].w, iViewMatrix[1].w, iViewMatrix[2].w) - myPosition.xyz);//view direction according to world
     25   output.position = mul(viewProjMatrix, myPosition); //finish transformation of the position into the projection space
     26   output.uv = input.uv; //passing on uv information
     27   return output;
    728}
    8 
Note: See TracChangeset for help on using the changeset viewer.