Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (TipmyPip, AndrewAMD, Quad, aliswee, degenerate_762), 970 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
bubbles #60402
12/11/05 17:49
12/11/05 17:49
Joined: Mar 2002
Posts: 221
USA
zefor Offline OP
Member
zefor  Offline OP
Member

Joined: Mar 2002
Posts: 221
USA
Can Anybody see what is wrong here. I used rendermonkey to create this bubble script(dx9), then I referenced MP3HiSTOPH3L3S old (dx8) rendermonkey bubble script, and the 3dgs manual. my model "squirms" like a bubble, but it is black. In fact, every script I use produces black models except for when I use sphere. I have an ati 9600. any thoughts here?

fx file (Bubbles.fx):
--------------------------------------------------------------------------------
//MATERIAL mat_bubbles
//{
//flags = tangent;

//effect
//"
matrix matWorldViewProj;
matrix matWorld;
matrix matWorldView;

texture entSkin1;
texture entSkin2;

vector vecSkill41;

technique bubbles
{
pass p0
{
Texture[0] = <entSkin1>; //basemap
Texture[1] = <entSkin2>; //cubemap

///////////////////changed from this from rendermonkey///////////////
// c0 - { 0.0, 0.5, 1.0, 2.0}
// c1 - { 4.0, .5pi, pi, 2pi}
// c2 - {1, -1/3!, 1/5!, -1/7!} for sin (1.0f, -1.0f/6.0f, 1.0f/120.0f, -1.0f/5040.0f)
// c3 - {1/2!, -1/4!, 1/6!, -1/8!} for cos (1.0f/2.0f, -1.0f/24.0f, 1.0f/720.0f, -1.0f/40320.0f)
// c4-7 - Composite World-View-Projection Matrix
// c8 - Model Space Camera Position
// c10 - {1.02, 0.04, 0, 0} fixup factor for Taylor series imprecision
// c11 - {0.5, 0.5, 0.25, 0.25} waveHeight0, waveHeight1, waveHeight2, waveHeight3
// c12 - {0.0, 0.0, 0.0, 0.0} waveOffset0, waveOffset1, waveOffset2, waveOffset3
// c13 - {0.6, 0.7, 1.2, 1.4} waveSpeed0, waveSpeed1, waveSpeed2, waveSpeed3
// c14 - {0.0, 2.0, 0.0, 4.0} waveDirX0, waveDirX1, waveDirX2, waveDirX3
// c15 - {2.0, 0.0, 4.0, 0.0} waveDirY0, waveDirY1, waveDirY2, waveDirY3
// c16 - { time }
// c17 - {-0.00015, 1.0, 0.0, 0.0} base texcoord distortion x0, y0, x1, y1
// c18 - World Martix
////////////////////////To This referencing old dx8 code////////////////////////////
VertexShaderConstant[0] = {0.0,0.5,1.0,2.0};
VertexShaderConstant[1] = {4.0, 1.570909,3.141818, 6.283636} ;
VertexShaderConstant[2] = {1.0f,-0.1666667f,0.008333f,-0.000198412698f};
VertexShaderConstant[3] = {0.5f,-0.0416666667f,0.00138888f,-2.4801587301f};
VertexShaderConstant[4] = <matWorldViewProj>; //Composite World-View-Projection Matrix
VertexShaderConstant[8] = {0,0,100,1};
VertexShaderConstant[10] = {1.02, 0.04, 0, 0}; //fixup factor for Taylor series imprecision
VertexShaderConstant[11] = {0.5, 0.5, 0.25, 0.25}; //waveHeight0, waveHeight1, waveHeight2, waveHeight3
VertexShaderConstant[12] = {0.0, 0.0, 0.0, 0.0}; //waveOffset0, waveOffset1, waveOffset2, waveOffset3
VertexShaderConstant[13] = {0.6, 0.7, 1.2, 1.4}; //waveSpeed0, waveSpeed1, waveSpeed2, waveSpeed3
VertexShaderConstant[14] = {0.0, 2.0, 0.0, 4.0}; //waveDirX0, waveDirX1, waveDirX2, waveDirX3
VertexShaderConstant[15] = {2.0, 0.0, 4.0, 0.0}; //waveDirY0, waveDirY1, waveDirY2, waveDirY3
VertexShaderConstant[16] = <vecSkill41>;
VertexShaderConstant[17] = {-0.00015, 1.0, 0.0, 0.0}; //base texcoord distortion x0, y0, x1, y1
VertexShaderConstant[18] = <matWorld>;

///////////////////dx 8 code///////////////
//VertexShaderConstant[0] = {0.0f,0.5f,1.0f,2.0f};
//VertexShaderConstant[1] = {4.0f, 1.570909f,3.141818f, 6.283636f} ;
//VertexShaderConstant[2] = {1.0f,-0.1666667f,0.008333f,-0.000198412698f}; /////////////////1f to 1.0f
//VertexShaderConstant[3] = {0.5f,-0.0416666667f,0.00138888f,-2.4801587301f};
//VertexShaderConstant[4] = <matWorldViewProj>; //Composite World-View-Projection Matrix
//VertexShaderConstant[8] = {0f,0f,100f,1f};
//VertexShaderConstant[10] = {1.02f, 0.04f, 0f, 0f}; //fixup factor for Taylor series imprecision
//VertexShaderConstant[11] = {0.5f, 0.5f, 0.25f, 0.25f}; //waveHeight0, waveHeight1, waveHeight2, waveHeight3
//VertexShaderConstant[12] = {0.0f, 0.0f, 0.0f, 0.0f}; //waveOffset0, waveOffset1, waveOffset2, waveOffset3
//VertexShaderConstant[13] = {0.6f, 0.7f, 1.2f, 1.4f}; //waveSpeed0, waveSpeed1, waveSpeed2, waveSpeed3
//VertexShaderConstant[14] = {0.0f, 2.0f, 0.0f, 4.0f}; //waveDirX0, waveDirX1, waveDirX2, waveDirX3
//VertexShaderConstant[15] = {2.0f, 0.0f, 4.0f, 0.0f}; //waveDirY0, waveDirY1, waveDirY2, waveDirY3
//VertexShaderConstant[16] = <vecSkill41>;
//VertexShaderConstant[17] = {-0.00015f, 1.0f, 0.0f, 0.0f}; //base texcoord distortion x0, y0, x1, y1
//VertexShaderConstant[18] = <matWorld>;
///////////////////////////////////////////////

PixelShaderConstant[0] = {0.0, 0.5, 1.0, -0.75};
PixelShaderConstant[1] = {0.6, 0.1, 0.0, 0.0}; // Alpha Scale and bias
/////////////////////////////////////////////////////////////////////////


VertexShader =
asm{

vs.1.1

dcl_position v0
dcl_normal v1
dcl_texcoord v2
dcl_tangent v3



mul r0, c14, v2.x // use tex coords as inputs to sinusoidal warp
mad r0, c15, v2.y, r0 // use tex coords as inputs to sinusoidal warp

mov r1, c16.x // time...
mad r0, r1, c13, r0 // add scaled time to move bumps according to frequency
add r0, r0, c12
frc r0.xy, r0 // take frac of all 4 components
frc r1.xy, r0.zwzw
mov r0.zw, r1.xyxy

mul r0, r0, c10.x // multiply by fixup factor (due to inaccuracy of taylor series)
sub r0, r0, c0.y // subtract .5
mul r0, r0, c1.w // mult tex coords by 2pi coords range from(-pi to pi)

mul r5, r0, r0 // (wave vec)^2
mul r1, r5, r0 // (wave vec)^3
mul r6, r1, r0 // (wave vec)^4
mul r2, r6, r0 // (wave vec)^5
mul r7, r2, r0 // (wave vec)^6
mul r3, r7, r0 // (wave vec)^7
mul r8, r3, r0 // (wave vec)^8

mad r4, r1, c2.y, r0 // (wave vec) - ((wave vec)^3)/3!
mad r4, r2, c2.z, r4 // + ((wave vec)^5)/5!
mad r4, r3, c2.w, r4 // - ((wave vec)^7)/7!

mov r0, c0.z // 1
mad r5, r5, c3.x ,r0 // -(wave vec)^2/2!
mad r5, r6, c3.y, r5 // +(wave vec)^4/4!
mad r5, r7, c3.z, r5 // -(wave vec)^6/6!
mad r5, r8, c3.w, r5 // +(wave vec)^8/8!

dp4 r0, r4, c11 // multiply wave heights by waves

mul r0, r0, v1 // apply deformation in direction of normal

add r0.xyz, r0, v0 // add to position
mov r0.w, c0.z // homogenous component

m4x4 oPos, r0, c4 // OutPos = WorldSpacePos * Composite View-Projection Matrix
mov oT0, v2 // Pass along texture coordinates

//This is where the shader starts to diverge a bit from the Ocean shader. First the binormal is computed

mov r3, v1
mul r4, v3.yzxw, r3.zxyw
mad r4, v3.zxyw, -r3.yzxw, r4 // cross product to find binormal

//Then the normal is warped based on the tangent space basis vectors (tangent and binormal).

mul r1, r5, c11 // cos * waveheight
dp4 r9.x, -r1, c14 // amount of normal warping in direction of binormal
dp4 r9.y, -r1, c15 // amount of normal warping in direction of tangent
mul r1, r4, r9.x // normal warping in direction of binormal
mad r1, v3, r9.y, r1 // normal warping in direction of tangent
mad r5, r1, c10.y, v1 // warped normal move nx, ny: cos * wavedir * waveheight

//The normal is then renormalized.

mov r10, r5
m3x3 r5, r10, c18 // transform normal
dp3 r10.x, r5, r5
rsq r10.y, r10.x
mul r5, r5, r10.y // normalize warped normal

// Next the view vector is computed:
mov r10, r0
m4x4 r0, r10, c18 // transform vertex position

sub r2, c8, r0 // view vector
dp3 r10.x, r2, r2
rsq r10.y, r10.x
mul r2, r2, r10.y // normalized view vector

; Then the dot product of the view vector and the warped normal is computed:

dp3 r7, r5, r2 // N.V
mov oT2, r7 // Pass along N.V

// This is used to compute the reflection vector.

add r6, r7, r7 // 2N.V
mad r6, r6, r5, -r2 // 2N(N.V)-V
mov oT1, r6 // reflection vector


}; /////////ADDED THIS//////////////////////

/////////////ps///////////////
// c0 - (0.0, 0.5, 1.0, -0.75)
// c1 - (0.6, 0.1, 0.0, 0.0) Alpha Scale and bias


pixelshader=
asm
{


ps.1.4

texld r0, t0
texld r1, t1
texcrd r2.rgb, t2


cmp r2.r, r2.r, r2.r, -r2.r // abs(V.N)
+mad_x4_sat r1.a, r1.a, r1.a, c0.a // 4 * (a^2 - .75), clamped


mul_x2_sat r2.rgb, r0, r1 // base * env (may change scale factor later)
+mad r2.a, 1-r2.r, c1.x, c1.y // alphascale * abs(V.N) + alphabias


lrp r0.rgb, r1.a, r1, r2 // Lerp between Env and Base*Env based on glow map
+add r0.a, r2.a, r1.a // Add glow map to Fresnel term for alpha

};
}
}
//";
//}

---------------------------------------------------------------------------------
wdl code (bub.wdl)

material mat_bubbles //assaign all models this material in script
{

flags = tangent;
}

function load_bubbles
{
effect_load(mat_bubbles,"Bubbles.fx");

wait(5);
}
------------------------------------------------------------------------------
and include the action at the bottom of main level wdl:
var count;
ACTION bubbles
{
my.material = mat_bubbles;
while(1)
{
my.skill41=float(count);
my.skill42=float(0);
my.skill43=float(0);
my.skill44=float(0);
count += 0.07*time;
wait(1);
}
}
-------------------------------------------------------------------------------
I put in main:
load_bubbles();


Thanks

Last edited by zefor; 12/11/05 17:52.
Re: bubbles [Re: zefor] #60403
12/11/05 21:33
12/11/05 21:33
Joined: Mar 2002
Posts: 221
USA
zefor Offline OP
Member
zefor  Offline OP
Member

Joined: Mar 2002
Posts: 221
USA
If I use 2 32 bit .tga files for the skins, skin 2 has alpha, it seems to work, only, my models are grey regardless of what colors I use??????

update:
I have determined my models are grey because they are displaying the alpha channel as the skin. I have tried switching around the skins, putting alpha skin as skin 1 , etc.. only to see a black model??????????
right now skin 1 is just a blue .tga saved in 32 bit.
skin 2 has a pattern, and its grayscale "copy of itself" in alpha, and saved as a 32 bit .tga.
Can anybody see what I am doing wrong?

Last edited by zefor; 12/12/05 20:24.
Re: bubbles [Re: zefor] #60404
12/15/05 13:47
12/15/05 13:47
Joined: Mar 2002
Posts: 221
USA
zefor Offline OP
Member
zefor  Offline OP
Member

Joined: Mar 2002
Posts: 221
USA
Working now! Here is the code in .wdl. I some code frome the wiki to work with sun dynamic lights and fog. Have not really tested these new aspecs completely, but they do not hurt. The "grey model" problem I was having was do to some kind of Fog issue. Whatever color I changed FOG 1 to under "Map Properties" in WED, the bubbles would chage to. To solve this problem just put a check in "no fog" under your bubbles properties. Hope my learning experience helps others And a special thanks to MP3HiSTOPH3L3S. Without his code, I wouldnt have learned anything.

MATERIAL mat_bubbles
{
flags = tangent;

effect
"
float4 vecFog;
float4 vecLightPos[8];
float4 vecLightColor[8];
float3 vecFalloff = float3(0.f, 0.f, 2.f);
float4 vecSunDir;
float4 vecSunDiffuse = float4(200.f/255.f, 200.f/255.f, 200.f/255.f, 1.f);

matrix matWorldViewProj;
matrix matWorld;
matrix matWorldView;

float4 DoSunLight(float3 N)
{
// modulate the sunlight by the surface angle
return vecSunDiffuse * dot(N,-vecSunDir);
}

float DoFog(float3 Pos)
{
// convert the vector position to view space to get it's depth (.z)
float3 P = mul(Pos,matWorldView);
// apply the linear fog formula
return saturate((vecFog.y-P.z) * vecFog.z);
}




float4 DoPointLight(float3 P, float3 N, int i)
{
// calculate the light ray pointing from the light to the surface
float3 D = (float3)vecLightPos-P;
// calculate the angle between surface and light ray
float NdotL = dot(N,normalize(D));
// modulate the light by the surface angle
float4 Color = vecLightColor * NdotL;

// calculate the light attenuation factor, DX uses a really strange formula here
float fac = 0.f;
if (NdotL >= 0.f && vecLightPos.w > 0.f)
{
// get the distance factor
float LD = length(D)/vecLightPos.w;
#ifdef DXLIGHTING
if (LD < 1.3f)
fac = 1.f/(vecFalloff.x + vecFalloff.y*LD + vecFalloff.z*LD*LD);
#else // linear Lighting
if (LD < 1.f)
fac = 1.f - LD;
#endif
}
return Color * fac;
}



texture entSkin1;
texture entSkin2;

vector vecSkill41;


struct VS_OUT // Output to the pixelshader fragment
{
float4 Pos : POSITION;
float4 Color: COLOR0;
float Fog: FOG;

};


VS_OUT Test_VS(

float4 inPos : POSITION,
float3 inNormal : NORMAL)
{
VS_OUT Out;

// transform the vector position to screen coordinates
Out.Pos = mul(inPos,matWorldViewProj);

// transform the normal and the position
float3 N = normalize(mul(inNormal,matWorld));
float3 P = mul(inPos,matWorld);
// Add ambient and sun light
Out.Color = vecSkill41.w + DoSunLight(N);
// Add 6 dynamic lights (maximum for vs 1.1)
for (int i=0; i<6; i++)
Out.Color += DoPointLight(P,N,i);
// Add fog
Out.Fog = DoFog(inPos);

// convert texture coordinates or do other stuff


return Out;
}

technique bubbles
{
pass p0
{
Texture[0] = <entSkin1>; //basemap
Texture[1] = <entSkin2>; //cubemap


VertexShaderConstant[0] = {0.0,0.5,1.0,2.0};
VertexShaderConstant[1] = {4.0f, 1.570909f,3.141818f, 6.283636f} ;
VertexShaderConstant[2] = {1.0f,-1.0f/6.0f, 1.0f/120.0f, -1.0f/5040.0f};
VertexShaderConstant[3] = {1.0f/2.0f, -1.0f/24.0f, 1.0f/720.0f, -1.0f/40320.0f};
VertexShaderConstant[4] = <matWorldViewProj>; //Composite World-View-Projection Matrix
VertexShaderConstant[8] = {0,0,100,1};
VertexShaderConstant[10] = {1.02, 0.04, 0, 0}; //fixup factor for Taylor series imprecision
VertexShaderConstant[11] = {0.5, 0.5, 0.25, 0.25}; //waveHeight0, waveHeight1, waveHeight2, waveHeight3
VertexShaderConstant[12] = {0.0, 0.0, 0.0, 0.0}; //waveOffset0, waveOffset1, waveOffset2, waveOffset3
VertexShaderConstant[13] = {0.6, 0.7, 1.2, 1.4}; //waveSpeed0, waveSpeed1, waveSpeed2, waveSpeed3
VertexShaderConstant[14] = {0.0, 2.0, 0.0, 4.0}; //waveDirX0, waveDirX1, waveDirX2, waveDirX3
VertexShaderConstant[15] = {2.0, 0.0, 4.0, 0.0}; //waveDirY0, waveDirY1, waveDirY2, waveDirY3
VertexShaderConstant[16] = <vecSkill41>;
VertexShaderConstant[17] = {-0.00015, 1.0, 0.0, 0.0}; //base texcoord distortion x0, y0, x1, y1
VertexShaderConstant[18] = <matWorld>;


PixelShaderConstant[0] = {0.0, 0.5, 1.0, -0.75};
PixelShaderConstant[1] = {0.6, 0.1, 0.0, 0.0}; // Alpha Scale and bias



VertexShader =

asm{

vs.1.1

dcl_position v0
dcl_normal v1
dcl_texcoord v2
dcl_tangent v3


mul r0, c14, v2.x // use tex coords as inputs to sinusoidal warp
mad r0, c15, v2.y, r0 // use tex coords as inputs to sinusoidal warp

mov r1, c16.x // time...
mad r0, r1, c13, r0 // add scaled time to move bumps according to frequency
add r0, r0, c12
frc r0.xy, r0 // take frac of all 4 components
frc r1.xy, r0.zwzw
mov r0.zw, r1.xyxy

mul r0, r0, c10.x // multiply by fixup factor (due to inaccuracy of taylor series)
sub r0, r0, c0.y // subtract .5
mul r0, r0, c1.w // mult tex coords by 2pi coords range from(-pi to pi)

mul r5, r0, r0 // (wave vec)^2
mul r1, r5, r0 // (wave vec)^3
mul r6, r1, r0 // (wave vec)^4
mul r2, r6, r0 // (wave vec)^5
mul r7, r2, r0 // (wave vec)^6
mul r3, r7, r0 // (wave vec)^7
mul r8, r3, r0 // (wave vec)^8

mad r4, r1, c2.y, r0 // (wave vec) - ((wave vec)^3)/3!
mad r4, r2, c2.z, r4 // + ((wave vec)^5)/5!
mad r4, r3, c2.w, r4 // - ((wave vec)^7)/7!

mov r0, c0.z // 1
mad r5, r5, c3.x ,r0 // -(wave vec)^2/2!
mad r5, r6, c3.y, r5 // +(wave vec)^4/4!
mad r5, r7, c3.z, r5 // -(wave vec)^6/6!
mad r5, r8, c3.w, r5 // +(wave vec)^8/8!

dp4 r0, r4, c11 // multiply wave heights by waves

mul r0, r0, v1 // apply deformation in direction of normal

add r0.xyz, r0, v0 // add to position
mov r0.w, c0.z // homogenous component


m4x4 oPos, r0, c4 // OutPos = WorldSpacePos * Composite View-Projection Matrix
mov oT0, v2 // Pass along texture coordinates

//This is where the shader starts to diverge a bit from the Ocean shader. First the binormal is computed

mov r3, v1
mul r4, v3.yzxw, r3.zxyw
mad r4, v3.zxyw, -r3.yzxw, r4 // cross product to find binormal

//Then the normal is warped based on the tangent space basis vectors (tangent and binormal).

mul r1, r5, c11 // cos * waveheight
dp4 r9.x, -r1, c14 // amount of normal warping in direction of binormal
dp4 r9.y, -r1, c15 // amount of normal warping in direction of tangent
mul r1, r4, r9.x // normal warping in direction of binormal
mad r1, v3, r9.y, r1 // normal warping in direction of tangent
mad r5, r1, c10.y, v1 // warped normal move nx, ny: cos * wavedir * waveheight

//The normal is then renormalized.

mov r10, r5
m3x3 r5, r10, c18 // transform normal
dp3 r10.x, r5, r5
rsq r10.y, r10.x
mul r5, r5, r10.y // normalize warped normal

// Next the view vector is computed:
mov r10, r0
m4x4 r0, r10, c18 // transform vertex position

sub r2, c8, r0 // view vector
dp3 r10.x, r2, r2
rsq r10.y, r10.x
mul r2, r2, r10.y // normalized view vector

; Then the dot product of the view vector and the warped normal is computed:

dp3 r7, r5, r2 // N.V
mov oT2, r7 // Pass along N.V

// This is used to compute the reflection vector.

add r6, r7, r7 // 2N.V
mad r6, r6, r5, -r2 // 2N(N.V)-V
mov oT1, r6 // reflection vector


};

/////////////ps///////////////
// c0 - (0.0, 0.5, 1.0, -0.75)
// c1 - (0.6, 0.1, 0.0, 0.0) Alpha Scale and bias


pixelshader=
asm
{


ps.1.4

texld r0, t0
texld r1, t1
texcrd r2.rgb, t2


cmp r2.r, r2.r, r2.r, -r2.r // abs(V.N)
+mad_x4_sat r1.a, r1.a, r1.a, c0.a // 4 * (a^2 - .75), clamped


mul_x2_sat r2.rgb, r0, r1 // base * env (may change scale factor later)
+mad r2.a, 1-r2.r, c1.x, c1.y // alphascale * abs(V.N) + alphabias


lrp r0.rgb, r1.a, r1, r2 // Lerp between Env and Base*Env based on glow map
+add r0.a, r2.a, r1.a // Add glow map to Fresnel term for alpha

};
}
}


";
}


//------
var count;

ACTION bubbles
{
my.material = mat_bubbles;
while(1)
{
my.skill41=float(count);
my.skill42=float(0);
my.skill43=float(0);
my.skill44=float(0);
count += 0.07*time;
wait(1);
}
}


Moderated by  Blink, Hummel, Superku 

Gamestudio download | chip programmers | 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