Gamestudio Links
Zorro Links
Newest Posts
FXCM demo test failed
by qin. 01/13/26 13:53
Camera always moves upwards?
by NeoDumont. 01/12/26 09:39
Alpaca Plugin v1.5.2 Release
by kzhao. 01/11/26 13:42
Alpaca Plugin v1.4.0
by kzhao. 01/11/26 13:38
separating groups of 3 digits by a comma
by joe_kane. 01/11/26 00:01
MRC.c and WFO
by joe_kane. 01/10/26 23:58
BarOffset (default = 940 for daily bars?
by joe_kane. 01/10/26 23:46
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (Quad), 6,361 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
promfast, joe_kane, Namitha_NN, Syndrela, agasior
19190 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 7 1 2 3 4 5 6 7
[SUB] Planet Shader Contribution #210857
06/13/08 12:40
06/13/08 12:40
Joined: Jul 2004
Posts: 1,710
MMike Offline OP
Serious User
MMike  Offline OP
Serious User

Joined: Jul 2004
Posts: 1,710
Hello here is my planet atmosphere shader.


Falloff, for the iluminated area only. The out edges glows giving the feeling of light scattering of an gaseous atmosphere.

Assign this material to the planet entity in your game.
Also i used an entity* sunobjecta to give planets the difuse and specular direction...

Also you can changee the sun color.
The atmosphere color could be change in the fallof parameter (fx file)
Code:
function SHADER_planet_skills{

while(1){


if(sun_objecta!=null){


 mtl.Skill1=floatv(sun_objecta.x); sun object position in space, sun_objecta is an entity in space with a action.
 mtl.Skill2=floatv(sun_objecta.y);
 mtl.Skill3=floatv(sun_objecta.z);
 
 mtl.Skill5=float(100/100);//Sun color  red percentage /100
 mtl.Skill6=float(100/100);//sun color  green percentage /100
 mtl.Skill7=float(100/100);//sun color  blue percentage /100
 
}
wait(1);	
}
}



material SHADER_planet{

effect="planet.fx";

flags = ENABLE_VIEW; 	
event=shader_planet_skills;

}




THEFX FILE:
Quote:
/******************************************************************************
* The following code was generated by the mental mill(R) *
* *
* Copyright 1986-2007 by mental images GmbH, Fasanenstr. 81, D-10623 *
* Berlin, Germany. All rights reserved. *
******************************************************************************/

//
// Values for the light_type parameter of light shaders
//
#define LIGHT_POINT 0
#define LIGHT_SPOT 1
#define LIGHT_INFINITE 2
#define LIGHT_PLANAR 3

//
// The light iterator structure holds the return values resulting from
// evaluating a light.
//
struct Light_iterator {
float3 _point;
float4 contribution;
float4 raw_contribution;
float dot_nl;
float3 direction;
float distance;
float4 shadow;
int count;
};

struct Ray {
float3 origin;
float3 direction;
};

Ray __Ray_ctor(float3 o, float3 d)
{
Ray r;
r.origin = o;
r.direction = d;
return r;
}

float2 __float2_ctor(float v)
{
return v.xx;
}

float3 __float3_ctor(float v)
{
return v.xxx;
}

float4 __float4_ctor(float v)
{
return v.xxxx;
}


//
// The following are for Depth Peeling
//



void __make_basis(const float3 n, const float3 u, const float3 v,
out float3 t, out float3 b)
{
b = normalize(cross(u,n));
t = cross(n,b);
if (dot(b,v) < 0.0) b = -b;
}

float3 __perspective_divide(float4 pt)
{
return pt.xyz/pt.w;
}

#ifndef mi_falloff__Scalar__Vector3__Vector3__Scalar
#define mi_falloff__Scalar__Vector3__Vector3__Scalar 1
float mi_falloff(
float3 direction,
float3 normal,
float amount)
{
float f;
f = (saturate((dot((-direction), normal))));
f = (1.0 - (pow(f, (1.0 / amount))));
return f;
}
#endif

#ifndef mi_phong_specular__Scalar__Vector3__Vector3__Vector3__Scalar
#define mi_phong_specular__Scalar__Vector3__Vector3__Vector3__Scalar 1
float mi_phong_specular(
float3 lightDir,
float3 eyeDir,
float3 n,
float specular_shininess)
{
float3 refl = ((2.f * (-(dot(eyeDir, n)))) * n) + eyeDir;
float h = dot(refl, lightDir);
return ((pow((max(h, 0.f)), specular_shininess)) * (specular_shininess + 2.f)) / (2.0 * 3.14159265358979323846f);
}
#endif


//
// The state structure is used internally within the fragment shader to
// commonly used values.
//
struct State
{
float4 tex_coord[4];
float3 position;
float3 normal;
float3 direction;
float3 light_position;
float3 light_to_surface;
float light_distance;
float light_dotnl;
};

//
// The following are free parameters of the shader that should be set by the
// application at runtime.
//
float4 __light0_Light_point_1_color= float4(1.000000, 1.000000, 1.000000, 1.000000);
float __light0_Light_point_1_intensity = 1.500000;
float __light0_Light_point_1_distance_falloff_exponent= 1.000000;
float __light0_Light_point_1_distance_falloff_start = 0.000000;
float __light0_Light_point_1_distance_falloff_limit = 1000.000000;
float __light0_Light_point_1_distance_scale= 60.000000; //distance fades intensity
float3 __light0_position : Position = float3(0.000000, 0.000000, 0.000000);
float4 Illumination_phong_1_diffuse_color = float4(1.000000, 1.000000, 1.000000, 1.000000);
float Illumination_phong_1_diffuse_scalar = 1.0;
float4 Illumination_phong_1_specular_color= float4(1.000000, 1.000000, 1.000000, 1.000000);
float Illumination_phong_1_specular_scalar = 0.095532;
float Illumination_phong_1_specular_shininess = 9.219858;
texture entSkin1;

sampler2D Texture_lookup_2d_1_texture = sampler_state {
Texture = <entSkin1>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
};

float Component_falloff_1_amount = 2.3;
float4 Color_gamma_1_gamma = float4(0.477049, 0.477049, 0.477049, 1.000000);
float4 Math_color_multiply_2_right = float4(0.475410, 0.638807, 1.000000, 1.000000);
float Color_brightness_1_amount=1.6;

//
// The following are parameters representing non-varying state variables
// referenced by the shader. These should be set by the application at runtime.
// Note that vector parameters should be provided in camera space.
//
float4x4 matWorldViewProj;
float4x4 matWorldInv ;
float4x4 matWorld ;
float4x4 matViewInv ;
float4 __scene_ambient : Ambient= 0;

//
// The App2vert structure defines the vertex attributes used by the vertex
// shader. The application should supply a vertex stream containing these
// elements.
//
struct App2vert
{
float3 position : POSITION;
float3 normal : NORMAL;
float4 texcoord0 : TEXCOORD0;
float4 texcoord1 : TEXCOORD1;
float4 texcoord2 : TEXCOORD2;
float4 texcoord3 : TEXCOORD3;
};

//
// The Vert2frag_out structure defines values output by the vertex shader.
//
struct Vert2frag_out
{
float4 hpos : POSITION;
float4 tex_coord[4] : TEXCOORD0;
float3 position : TEXCOORD4;
float3 normal : TEXCOORD5;
};

//
// The Vert2frag_in structure defines values used by the fragment shader.
//
struct Vert2frag_in
{
float4 hpos : POSITION;
float4 tex_coord[4] : TEXCOORD0;
float3 position : TEXCOORD4;
float3 normal : TEXCOORD5;
float2 raster : VPOS;
};

//
// This function is the main method of the vertex shader.
//
Vert2frag_out vertex_main(
App2vert vs_in)
{
Vert2frag_out vs_out;
float4 position = float4(vs_in.position, 1);
vs_out.hpos = mul(position, matWorldViewProj);
vs_out.position = mul(position, matWorld).xyz;
vs_out.normal = mul((float3x3)matWorldInv, vs_in.normal);
vs_out.tex_coord[0] = vs_in.texcoord0;
vs_out.tex_coord[1] = vs_in.texcoord1;
vs_out.tex_coord[2] = vs_in.texcoord2;
vs_out.tex_coord[3] = vs_in.texcoord3;
return vs_out;
}

//
// The following functions are generated from the MetaSL implementation of
// the shaders that are part of the compiled shader graph.
//

void Light_point_main(
float4 color,
float intensity,
float distance_falloff_exponent,
float distance_falloff_start,
float distance_falloff_limit,
float distance_scale,
State state,
out float4 result,
out float4 light_shadow)
{
{
float d = saturate((((state.light_distance) / (distance_scale - distance_falloff_start)) / (distance_falloff_limit - distance_falloff_start)));
float f = 1.0 / (1.0 + (pow(d, distance_falloff_exponent)));
result = ((color * intensity) * f);
light_shadow = (float4(1,1,1,1));
result *= 3.14159265358979323846f;
}
}

void Light_point_1_main(
float4 Light_point_1_color,
float Light_point_1_intensity,
float Light_point_1_distance_falloff_exponent,
float Light_point_1_distance_falloff_start,
float Light_point_1_distance_falloff_limit,
float Light_point_1_distance_scale,
float3 __light_position,
State state,
out Light_iterator __light)
{
{
float4 light_shadow = float4(0.000000, 0.000000, 0.000000, 0.000000);
float4 result = float4(0.000000, 0.000000, 0.000000, 0.000000);
__light.direction = (__light_position - (state.position));
__light.distance = (length(__light.direction));
__light.direction /= __light.distance;
__light.dot_nl = (dot(__light.direction, (state.normal)));
__light.contribution = 0.0;
__light.raw_contribution = 0.0;
__light.count = 0.0;
__light.shadow = 0.0;
__light._point = 0.0;
(state.light_to_surface) = (-__light.direction);
(state.light_distance) = __light.distance;
(state.light_dotnl) = __light.dot_nl;
(state.light_position) = __light_position;
Light_point_main(Light_point_1_color, Light_point_1_intensity, Light_point_1_distance_falloff_exponent, Light_point_1_distance_falloff_start, Light_point_1_distance_falloff_limit, Light_point_1_distance_scale, (state), result, light_shadow);
__light._point = __light_position;
__light.shadow = light_shadow;
__light.count = 0;
__light.raw_contribution = result;
__light.contribution = (result * light_shadow);
}
}
float4 vecSkill1;
float4 vecSkill5;
void Illumination_phong_main(
float4 diffuse_color,
float diffuse_scalar,
float4 specular_color,
float specular_scalar,
float specular_shininess,
State state,
out float4 sum,
out float4 diffuse,
out float4 specular)
{
{
diffuse = (float4(0, 0, 0, 0));
specular = (float4(0, 0, 0, 0));
float4 Rd = diffuse_color * diffuse_scalar;
float4 Rs = specular_color * specular_scalar;
float3 vdir = state.direction;
Light_iterator light;
__light0_Light_point_1_color=float4(vecSkill5.x,vecSkill5.y,vecSkill5.z,1);
{
{
__light0_position=float4(vecSkill1.x,vecSkill1.z,vecSkill1.y,1);//shift z with y, gs engine problem
Light_point_1_main(__light0_Light_point_1_color, __light0_Light_point_1_intensity, __light0_Light_point_1_distance_falloff_exponent, __light0_Light_point_1_distance_falloff_start, __light0_Light_point_1_distance_falloff_limit, __light0_Light_point_1_distance_scale, __light0_position, (state), light);
float cos = saturate(light.dot_nl);
if (cos > 0.0)
{
diffuse += ((cos / 3.14159265358979323846f) * light.contribution);
float s = mi_phong_specular(light.direction, vdir, (state.normal), specular_shininess);
specular += ((s * cos) * light.contribution);
}
}
}
diffuse *= Rd;
specular *= Rs;

;
diffuse += (Rd * (__scene_ambient));
diffuse.a = 1.0;
specular.a = 1.0;
sum = (diffuse + specular);
}
}

void Texture_lookup_2d_main(
sampler2D _texture,
int texture_space,
float2 texture_uv,
State state,
out float4 result)
{
{
result = (tex2D(_texture, texture_uv));
}
}

void Component_falloff_main(
float amount,
State state,
out float4 result)
{
{
float falloff = mi_falloff((state.direction), (state.normal), amount);
result = (float4(falloff, falloff, falloff, 1.0));
}
}

void Math_color_invert_main(
float4 color,
State state,
out float4 result)
{
{
result = ((float4(1, 1, 1, 1)) - color);
result.a = 1.0;
}
}

void Color_gamma_main(
float4 color,
float4 gamma,
State state,
out float4 result)
{
{
result = (pow(color, ((__float4_ctor(1.0)) / gamma)));
}
}

void Math_color_multiply_main(
float4 left,
float4 right,
State state,
out float4 result)
{
{
result = (left * right);
}
}

void Color_brightness_main(
float4 color,
float amount,
State state,
out float4 result)
{
{
result = (color * amount);
}
}

void Math_color_add_main(
float4 left,
float4 right,
State state,
out float4 result)
{
{
result = (left + right);
}
}

//
// The following method is the root function of the shader graph
//
float4 Math_color_add_1_eval(State state)
{
float4 result;
float4 Illumination_phong_1_sum = float4(0.000000, 0.000000, 0.000000, 0.000000);
float4 Illumination_phong_1_diffuse = float4(0.000000, 0.000000, 0.000000, 0.000000);
float4 Illumination_phong_1_specular = float4(0.000000, 0.000000, 0.000000, 0.000000);
Illumination_phong_main(Illumination_phong_1_diffuse_color, Illumination_phong_1_diffuse_scalar, Illumination_phong_1_specular_color, Illumination_phong_1_specular_scalar, Illumination_phong_1_specular_shininess, (state), Illumination_phong_1_sum, Illumination_phong_1_diffuse, Illumination_phong_1_specular);
float4 Texture_lookup_2d_1_result = float4(0.000000, 0.000000, 0.000000, 0.000000);
Texture_lookup_2d_main(Texture_lookup_2d_1_texture, 0, (state.tex_coord)[0].xy, (state), Texture_lookup_2d_1_result);
float4 Component_falloff_1_result = float4(0.000000, 0.000000, 0.000000, 0.000000);
Component_falloff_main(Component_falloff_1_amount, (state), Component_falloff_1_result);
float4 Math_color_invert_1_result = float4(0.000000, 0.000000, 0.000000, 0.000000);
Math_color_invert_main(Component_falloff_1_result, (state), Math_color_invert_1_result);
float4 Color_gamma_1_result = float4(0.000000, 0.000000, 0.000000, 0.000000);
Color_gamma_main(Math_color_invert_1_result, Color_gamma_1_gamma, (state), Color_gamma_1_result);
float4 Math_color_multiply_1_result = float4(0.000000, 0.000000, 0.000000, 1.000000);
Math_color_multiply_main(Texture_lookup_2d_1_result, Color_gamma_1_result, (state), Math_color_multiply_1_result);
float4 Math_color_multiply_3_result = float4(0.000000, 0.000000, 0.000000, 1.000000);
Math_color_multiply_main(Illumination_phong_1_sum, Math_color_multiply_1_result, (state), Math_color_multiply_3_result);
float4 Math_color_multiply_2_result = float4(0.000000, 0.000000, 0.000000, 1.000000);
Math_color_multiply_main(Component_falloff_1_result, Math_color_multiply_2_right, (state), Math_color_multiply_2_result);
float4 Color_brightness_1_result = float4(0.000000, 0.000000, 0.000000, 0.000000);
Color_brightness_main(Math_color_multiply_2_result, Color_brightness_1_amount, (state), Color_brightness_1_result);
float4 Math_color_multiply_4_result = float4(0.000000, 0.000000, 0.000000, 1.000000);
Math_color_multiply_main(Illumination_phong_1_sum, Color_brightness_1_result, (state), Math_color_multiply_4_result);
Math_color_add_main(Math_color_multiply_3_result, Math_color_multiply_4_result, (state), result);
return result;
}

//
// This function is the main method of the fragment shader. It initializes the
// values in the state structure that are used by nodes in the shader graph
// and produces the final result of the shader.
//
float4 fragment_main(
Vert2frag_in fs_in) : COLOR
{

State state;
state.position = fs_in.position;
state.normal = normalize(fs_in.normal);
state.tex_coord = fs_in.tex_coord;
float3 eye_to_pos = state.position - matViewInv[3];
state.direction = normalize(eye_to_pos);
state.light_position = 0;
state.light_to_surface = 0;
state.light_distance = 0;
state.light_dotnl = 0;
return Math_color_add_1_eval(state);
}

//
// The following define the default technique and pass of the effect.
//
technique T0
{
pass P0
{
ZEnable = TRUE;
ZWriteEnable = TRUE;
CullMode = none;
VertexShader = compile vs_3_0 vertex_main();
PixelShader = compile ps_3_0 fragment_main();
}
}



Last edited by MMike; 06/13/08 15:06.
Re: [SUB] Planet Shader Contribution [Re: MMike] #211241
06/15/08 20:13
06/15/08 20:13
Joined: Nov 2005
Posts: 1,007
jigalypuff Offline
Serious User
jigalypuff  Offline
Serious User

Joined: Nov 2005
Posts: 1,007
is this for c script or lite c?


Why does everyone like dolphins? Never trust a species which smiles all the time!
Re: [SUB] Planet Shader Contribution [Re: jigalypuff] #211248
06/15/08 20:52
06/15/08 20:52
Joined: Oct 2007
Posts: 5,211
İstanbul, Turkey
Quad Online
Senior Expert
Quad  Online
Senior Expert

Joined: Oct 2007
Posts: 5,211
İstanbul, Turkey
material definiton is c-script. But i guess it will work with lite-c with some minor changes.


3333333333
Re: [SUB] Planet Shader Contribution [Re: Quad] #211273
06/15/08 22:38
06/15/08 22:38
Joined: Jul 2004
Posts: 1,710
MMike Offline OP
Serious User
MMike  Offline OP
Serious User

Joined: Jul 2004
Posts: 1,710
its for c-script.. but can work in lite-c of course.

Last edited by MMike; 06/15/08 22:39.
Re: [SUB] Planet Shader Contribution [Re: MMike] #211443
06/16/08 18:50
06/16/08 18:50
Joined: Nov 2005
Posts: 1,007
jigalypuff Offline
Serious User
jigalypuff  Offline
Serious User

Joined: Nov 2005
Posts: 1,007
i`m getting an error when trying to use this, i copied the shader code into a txt file and renamed that to .fx i copied the material code into a script and made a planet action to call it, i get this error
Code:
sun_objecta!=null
parameter unknown sun_objecta


scratch that above lol i fixed it, now i get this error
Code:
syntax error nonexistent/empty function floatv


Last edited by jigalypuff; 06/16/08 18:56.

Why does everyone like dolphins? Never trust a species which smiles all the time!
Re: [SUB] Planet Shader Contribution [Re: jigalypuff] #211492
06/16/08 22:09
06/16/08 22:09
Joined: Jul 2004
Posts: 1,710
MMike Offline OP
Serious User
MMike  Offline OP
Serious User

Joined: Jul 2004
Posts: 1,710
ok if you use lite-c use just float(...) ok?

Re: [SUB] Planet Shader Contribution [Re: MMike] #211493
06/16/08 22:09
06/16/08 22:09
Joined: Jul 2004
Posts: 1,710
MMike Offline OP
Serious User
MMike  Offline OP
Serious User

Joined: Jul 2004
Posts: 1,710
floatv its for c-script convert var to float variable..

Re: [SUB] Planet Shader Contribution [Re: MMike] #211494
06/16/08 22:14
06/16/08 22:14
Joined: May 2005
Posts: 2,713
Lübeck
Slin Offline
Expert
Slin  Offline
Expert

Joined: May 2005
Posts: 2,713
Lübeck
Wrong, floatv() is for the latest C-Script Version AND for Lite-C to convert var to float (typecasting to float somehow doesn´t work in this case). If you use C-Script and floatv() doesn´t work, use the old float() instead.

Re: [SUB] Planet Shader Contribution [Re: Slin] #211575
06/17/08 11:22
06/17/08 11:22
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
could you post the shot of the sphere without the shader applied?

Re: [SUB] Planet Shader Contribution [Re: Joey] #211583
06/17/08 12:02
06/17/08 12:02
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline
Expert
Joozey  Offline
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
Looks great grin thanx for the contribution.


Click and join the 3dgs irc community!
Room: #3dgs
Page 1 of 7 1 2 3 4 5 6 7

Moderated by  Blink, Hummel, Superku 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1