Page 1 of 1

Found useful stuffs.....

Posted: Sat Jan 01, 2011 9:20 pm
by Flashbang232
Browsing (and trying to learn basic LUA scripting) around ta3d folder, and i found this....
edit:please go to ta3d directory \scripts\ta3d.lh

looks like a code that controls how ta3d uses ta scripts or something. I see familiar ta-bos script commands.
Is this it? Because I remember matman said that the script animations were buggy.

also, i think i found the files that control water animation.

Code: Select all

varying vec2 t_coord;
varying vec3 dir;

void main()
{
	gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
	t_coord = vec2(gl_TextureMatrix[0] * gl_MultiTexCoord0);
	dir = (gl_ModelViewMatrixInverse[3] - gl_Vertex ).xyz;
}
taken from water_pass1.vert
[/ta3d/shaders]
*bigger wall of code*

Code: Select all

varying vec2 t_coord;
varying vec3 dir;
uniform float t;
uniform vec2 factor;
uniform sampler2D lava;
uniform sampler2D map;

vec3 wave_grad( vec2 d, float p, float type )
{
	vec2 base_grad = 2.0 * texture2D( map, vec2( dot( d, t_coord ) + p, type ) ).xy - vec2( 1.0, 1.0 );
	vec3 grad = vec3( d.x * base_grad.x, base_grad.y, d.y * base_grad.x );
	return normalize( grad );
}

void main()
{
	vec3 N =  wave_grad( vec2( 65.0, 15.1 ), 0.15 * t, 0.8 )
			+ wave_grad( vec2( 19.7, -33.1 ), 0.21 * t, 0.3 )
			+ wave_grad( vec2( -27.0, 23.3 ), 0.13 * t, 0.45 )
			+ wave_grad( vec2( 77.0, -130.3 ), 0.13 * t, 0.65 )
			+ wave_grad( vec2( 97.0, 87.1 ), 0.17 * t, 0.77 );

	N=normalize(N);

	vec2 lava_coord = (t_coord-vec2(0.5,0.5))*factor+vec2(0.5,0.5);
	float lava_c = 0.5 * texture2D(lava,lava_coord).r + 0.5;
	if (lava_coord.x < 0.0 || lava_coord.y < 0.0 || lava_coord.x > 1.0 || lava_coord.y > 1.0)
		lava_c = 0.0;

	gl_FragColor = vec4(0.5*(N+vec3(1.0,1.0,1.0)),lava_c);
}
this is water_pass1_low.frag

i notice that some of this is similar to the LUA scripting style....are these types of scripting/coding connected somehow?

Water "Simulator" [water_simulator2.frag]

Code: Select all

varying vec2 t_coord;
uniform float dt;
uniform sampler2D sim;

const vec2 du = vec2(0.00390625, 0.0);
const vec2 dv = vec2(0.0, 0.00390625);

void main()
{
    vec4 P0 = texture2DLod( sim, t_coord, 0.0 );
    vec4 PU = texture2DLod( sim, t_coord - du, 0.0 );
    vec4 PV = texture2DLod( sim, t_coord - dv, 0.0 );
    P0.y += dt * (P0.x + P0.z - PU.x - PV.z);
    gl_FragColor = P0;
}
now, if this is what i think it is, then we can fix those nasty white lines that appear on a coast. They appear when the water is set to ultimate level graphics and that, is unacceptable. (mr. mc taco mcbean) <--idk
well it isnt unacceptable but we can surely do without.

Now, I am going on a tutorial hunt.

I hope im not breaking forum rules somehow. :P

Re: Found useful stuffs.....

Posted: Sat Jan 01, 2011 9:36 pm
by Balthazar
nope, you are doing great so far ) wellcome onboard!

Re: Found useful stuffs.....

Posted: Sat Jan 01, 2011 10:03 pm
by Flashbang232
Yay! And i like helping now. It makes me feel all warm and snuggly inside.

You should have seen me on TAuniverse.com I was a real dumba*s. :?

Re: Found useful stuffs.....

Posted: Wed Jan 05, 2011 5:48 pm
by zuzuf
the ta3d.lh header file contains several functions and variables which are used by the engine (like the unit table which contains animation data for Lua animated units) when running Lua scripts, it's not related to GLSL shaders. The Lua API is almost mapped to OTA Bos API with a few differences due to Lua VM specific stuffs: it's designed to allow porting BOS code to Lua (but this won't be optimal, with some performance critical scripts you may want to optimize things a bit to match the way Lua works).

The ugly whites waves are controlled by the "coast_factor" variable in the water_sim_reflec.frag file. The water_simulator*.frag files contain the GPU water simulation code only (not related to coastal waves).

Re: Found useful stuffs.....

Posted: Wed Jan 05, 2011 7:09 pm
by MattyWS
How does one remove that consistent white line in the ultimate water settings?

Re: Found useful stuffs.....

Posted: Thu Jan 06, 2011 11:52 pm
by Flashbang232
Kind of what I was trying to get at matman :P

But Zuzuf should know, he must have helped alot as well with ta3d graphics.

In which file(s) are the coastline wave graphics located, Zuzuf?

And I know i just remember reading about how Matman experienced problems with the script controls/animation...
So then is there an error in the....um....Ta3d.lh? Because that would be the likely factor

Re: Found useful stuffs.....

Posted: Sat Jan 08, 2011 1:50 pm
by zuzuf
The coastline wave is controlled in the water_sim_reflec.frag file.

Re: Found useful stuffs.....

Posted: Sun Jan 09, 2011 7:54 pm
by MattyWS
Sorry, I meant what line would I need to edit and in what way? (i'm not a coder ^^)

Re: Found useful stuffs.....

Posted: Sun Jan 16, 2011 12:47 pm
by zuzuf
I think you can remove those waves by removing these lines:

Code: Select all

        float coast_factor = clamp( 1.0 - 8.0 * depth, 0.0, 1.0 );
        float offset = coast_factor * 3.14 - cos(t) * 1.57 - 2.0;
        float f = cos( offset );
        float f2 = cos( offset - 0.2 );
        f = (f <= f2) ? pow(clamp(f,0.0,1.0),10.0) : f;
        f *= (0.5 * cos(t+0.2) + 0.5);
        procedural_texture += vec4( coast_factor * coast_factor * pow(f * 0.5 + 0.5, 10.0) );
You can also try to improve the effect, here is a small description of what this code does :
  • coast_factor is a number ranging from 0 to 1, 0 meaning plain see and 1 plain coast (it defines the wave area)
  • offset is a 1D position inside a wave pattern (this pattern is defined by the function computed by the other lines)
  • the last line adds the result to the procedural texture for water
It's ugly because of the lack of complexity in the wave pattern (it's a 1D pattern), it may be improved a lot with a more complex pattern like something based on a 2D or 3D texture (at least it won't be a uniform white line synchronized on all the coasts of the map).

Re: Found useful stuffs.....

Posted: Sun Jan 16, 2011 6:02 pm
by Flashbang232

Code: Select all

        float coast_factor = clamp( 1.0 - 8.0 * depth, 0.0, 1.0 );
        float offset = coast_factor * 3.14 - cos(t) * 1.57 - 2.0;
        float f = cos( offset );
        float f2 = cos( offset - 0.2 );
        f = (f <= f2) ? pow(clamp(f,0.0,1.0),10.0) : f;
        f *= (0.5 * cos(t+0.2) + 0.5);
        procedural_texture += vec4( coast_factor * coast_factor * pow(f * 0.5 + 0.5, 10.0) );
coast_factor is a number ranging from 0 to 1, 0 meaning plain see and 1 plain coast (it defines the wave area)
So what you are saying that, in fact, this line defines where the waves show up?
offset is a 1D position inside a wave pattern (this pattern is defined by the function computed by the other lines)
the "float offset = Coast_factor* 3.14 - cos(t) *1.57 - 2.0;"
both defines the pattern of the coastline waves and where the waves show up?
Also, is there a certain line that defines color?
And a certain line that defines when a wave shows up. (ie how close to the coast do they have to be to show up)
If so i can take a look at ota heightmaps and, with guidance, I can find and change the line properly to show up closer to the coast, and maybe even improve it.

So, how would i improve it.

also in the line

Code: Select all

float offset = Coast_factor* 3.14 - cos(t) *1.57 - 2.0;
, I notice that the number Pi [3.14 rounded off actually] is in there.

Is that supposed to represent Pi or just a random coincidence?

Re: Found useful stuffs.....

Posted: Sun Jan 16, 2011 7:57 pm
by zuzuf
Flashbang232 wrote: So what you are saying that, in fact, this line defines where the waves show up?
It's exactly what it does
Flashbang232 wrote: the "float offset = Coast_factor* 3.14 - cos(t) *1.57 - 2.0;"
both defines the pattern of the coastline waves and where the waves show up?
no, the offset is just where to look in the wave pattern and the coast_factor defines where to draw it.
Flashbang232 wrote: Also, is there a certain line that defines color?
yes:

Code: Select all

vec4( coast_factor * coast_factor * pow(f * 0.5 + 0.5, 10.0) )
a vec4 is a vector with 4 components (Red Green Blue Alpha) and this line creates a vec4 with all components equals but you can do something like "value * vec4(1,0,0,0)" which would modulate a color (here red) using the wave pattern.
Flashbang232 wrote: And a certain line that defines when a wave shows up. (ie how close to the coast do they have to be to show up)
If so i can take a look at ota heightmaps and, with guidance, I can find and change the line properly to show up closer to the coast, and maybe even improve it.

Code: Select all

float coast_factor = clamp( 1.0 - 8.0 * depth, 0.0, 1.0 );
the "depth" variable contains depth information relative to see level (positive means under see), so here it defines the coast zone as everything with a depth between 0 and 8.
Flashbang232 wrote: Is that supposed to represent Pi or just a random coincidence?
It represents Pi (offset is used as argument to a cos) but I don't remember why I put so few digits.

Re: Found useful stuffs.....

Posted: Wed Jan 26, 2011 3:54 am
by Flashbang232
Oh god, this is like Algebra 1 to me. >.<
And getting a C- in there, it's not easy.
Yet this makes more sense to me. XD
the "depth" variable contains depth information relative to see level (positive means under see), so here it defines the coast zone as everything with a depth between 0 and 8.
So what if we edited this to be 3-12? !? :D:D:D:D

Re: Found useful stuffs.....

Posted: Wed Jan 26, 2011 7:10 pm
by zuzuf
If you set it to to be 3-12 you must decide how it behaves between 0-3 which would be a small coast line with no waves but we can't just cut the wave at 3 (well we can but the result would be rather sharp).

Re: Found useful stuffs.....

Posted: Mon Jan 31, 2011 3:17 am
by Flashbang232
Is there a tutorial on editing these files?
This thread is hashed up and hurting my brain trying to follow the remarks/coding/codes and making a solution to bad-looking waves and showing it via code tags. :(

Re: Found useful stuffs.....

Posted: Mon Jan 31, 2011 1:25 pm
by zuzuf
You may want to have a look at http://www.opengl.org/documentation/specs/ for GLSL(OpenGL Shading Language) specs.

I've been working a bit on waves and ripples (sprite effects) : in ultimate water setting they produce optical distortion and a basic foam effect. It doesn't replace the ugly procedural wave, I would like to have some feed back first about those new effects then I may remove the ugly wave instead of trying to improve it.

Re: Found useful stuffs.....

Posted: Sat Feb 05, 2011 4:48 am
by Flashbang232
Thank you zuzuf, your a lifesaver. :D

Re: Found useful stuffs.....

Posted: Sun Apr 03, 2011 4:35 am
by Flashbang232
Now what im thinkin is if the wind is high then you can use some sort of detector and say if the wind is around 15-20, you get little caps of white on the ocean, like real life, and maybe affecting units movement (rocking, thus more innacuracy)

and just realism...

the larger the wind, the more noticable the effect is and the larger the white caps.

that would be cool

and if it could have its own toggle button