Gamestudio Links
Zorro Links
Newest Posts
Newbie Questions
by fairtrader. 12/05/23 10:32
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
Combine USD & BTC Pairs In Asset Loop
by TipmyPip. 11/26/23 08:30
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
6 registered members (AndrewAMD, alibaba, fairtrader, ozgur, TipmyPip, Quad), 604 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 3 1 2 3
Re: Opionion to this shaderidea [Re: xXxGuitar511] #123901
04/16/07 13:35
04/16/07 13:35
Joined: Jan 2007
Posts: 651
Germany
R
RedPhoenix Offline OP
User
RedPhoenix  Offline OP
User
R

Joined: Jan 2007
Posts: 651
Germany
Well I am going to use as base the multitexture terrainshader from the templates. The textures I will connect as you suggested, but for changing the textures during gameplay there has to be a dynamic blending. If the blending is set with the channels of the first skin, that will may be difficult. I had something in mind like giving the blending through entityskills to the shader, so that they could easily be changed. The problem is to build a good code, that changes these vars in the right way. To get it more realistic I thought of may be fading between several stats of textures. That means I have for example
a terrain with two textures gras and snow, a base blending where gras is most (may be saved as channels in a picture) and another state let's say winter, where snow texture dominates (may be also saved as channels in a picture).
To get a realistic switch between these two "extreme" stats, it would be necessary to calculate the differences of color in each channel for each texture coordinate of the two state picture (don't know how to do it I don't think that this could be done via script, may be a second shader is necessary). Then a code could make a soft fading between the two stats, and give the information to the shader.

I have not so much experience with shaders by now, but from what I learned so far I think that this should be possible.

I hope that you getting my point my English isn't so good, I didn't know how to explain my idea better

EDIT: @xXxGuitar511 In your previous post you suggested doing it with first skin as mask for 4 ground textures and using the last 2 for the blending.
In these skins such stats may be could be saved. So there the shader would have all information which he needs, the difference between the mask and the blendingstats should be easy to get, only difficulty is how to make a good looking fading between them. And this should have a connection to the script as well. So may be a game with a year-circle, over a long period of time. The shader has to get the timeinformation, to know how much to blend between the stats

Last edited by RedPhoenix; 04/16/07 14:13.
Re: Opionion to this shaderidea [Re: RedPhoenix] #123902
04/16/07 19:01
04/16/07 19:01
Joined: Dec 2000
Posts: 4,608
mk_1 Offline

Expert
mk_1  Offline

Expert

Joined: Dec 2000
Posts: 4,608
blending 6 textures at once doesn't sound very efficient. You better split the big terrain in several smaller ones using only three textures. It's way faster (remember that every pixel of your terrain needs to be blended six times... that would cut your fps down).


Follow me on twitter
Re: Opionion to this shaderidea [Re: mk_1] #123903
04/16/07 20:17
04/16/07 20:17
Joined: Jan 2007
Posts: 651
Germany
R
RedPhoenix Offline OP
User
RedPhoenix  Offline OP
User
R

Joined: Jan 2007
Posts: 651
Germany
Ok I got the multitexture shader working with 5 textures, now I'll try the blending.

@mk_1 Yes you are probably right, it was more a question to me what is possible and what is not. When I have the shader working I will try to make it a way that it fits with performance

Re: Opionion to this shaderidea [Re: RedPhoenix] #123904
04/17/07 17:27
04/17/07 17:27
Joined: Jan 2007
Posts: 651
Germany
R
RedPhoenix Offline OP
User
RedPhoenix  Offline OP
User
R

Joined: Jan 2007
Posts: 651
Germany
Ok I have a first version of the code working...

MATERIAL mtl_terraintex3
{
skin1 = ter_tex4; //defined bmap
skin2 = ter_tex5; //defined bmap
skin3 = ter_blend1; //defined bmap
skin4 = ter_blend2; //defined bmap
effect = "

//enable: DirectX Lighting
//help: Use the DirectX Formula for dynamic lights.
//help: Otherwise use the Conitec Formula that produces smoother light.
//id: 11
//#define DXLIGHTING

//enable: DirectX Fog
//help: Use the DirectX Formula for z-based fog.
//help: Otherwise use the Conitec Formula that produces distance-based fog.
//id: 12
#define DXFOG

//I deleted the shader fallback to 1_0 because 2_0 is needed
//I deleted the shadowmapsupport to get more textures working

#include <transform>
#include <sun>
#include <lights>
#include <fog>
#include <normal>

Texture entSkin1; // RGBA Texture for base mask
Texture entSkin2; // Base texture
Texture entSkin3; // Red masked tiled texture
Texture entSkin4; // Green masked tiled texture
Texture mtlSkin1; // blue masked tiled texture
Texture mtlSkin2; // alpha masked tiled texture
Texture mtlSkin3; // First extreme blending mask (with addition values)
Texture mtlSkin4; // Second extreme blending mask (with subtraction values)

float4 vecSkill41; //first three elements used for the texturescales
//fourth used as input for percentual blending
float fAmbient;

sampler sMaskTex = sampler_state { Texture = <entSkin1>; };
sampler sBaseTex = sampler_state { Texture = <entSkin2>; };
sampler sRedTex = sampler_state { Texture = <entSkin3>; };
sampler sGreenTex = sampler_state { Texture = <entSkin4>; };
sampler sBlueTex = sampler_state { Texture = <mtlSkin1>; };
sampler sAlphaTex = sampler_state { Texture = <mtlSkin2>; };
sampler sb1maskTex = sampler_state { Texture = <mtlSkin3>; };
sampler sb2maskTex = sampler_state { Texture = <mtlSkin4>; };

//////////////////////////////////////////////////////////////////////
struct out_terraintex3 // Output to the pixelshader fragment
{
float4 Pos : POSITION;
float4 Color : COLOR0;
float Fog : FOG;
float2 MaskCoord: TEXCOORD0;
float2 BaseCoord: TEXCOORD1;
float2 RedCoord : TEXCOORD2;
float2 GreenCoord: TEXCOORD3;
float2 BlueCoord: TEXCOORD4;
float2 AlphaCoord: TEXCOORD5;
float2 B1Coord: TEXCOORD6;
float2 B2Coord: TEXCOORD7;
};

out_terraintex3 vs_terraintex3(
float4 inPos : POSITION,
float3 inNormal : NORMAL,
float2 inTexCoord0 : TEXCOORD0)
{
out_terraintex3 Out;

Out.Pos = DoTransform(inPos); // transform to screen coordinates

// rotate and normalize the normal
float3 N = DoNormal(inNormal);
float3 P = mul(inPos,matWorld);

Out.Color = fAmbient + DoSunLight(N); // Add ambient and sun light
for (int i=0; i<6; i++) // Add 6 dynamic lights (maximum for vs 1.1)
Out.Color += DoLight(P,N,i);
Out.Fog = DoFog(inPos); // Add fog

// scale the texture coordinates for the masked textures
Out.MaskCoord = inTexCoord0.xy;
Out.BaseCoord = inTexCoord0.xy * vecSkill41.x;
Out.RedCoord = inTexCoord0.xy * vecSkill41.y;
Out.GreenCoord = inTexCoord0.xy * vecSkill41.z;
Out.BlueCoord = inTexCoord0.xy * vecSkill41.y; //condition: redtex same scales as bluetex
Out.AlphaCoord = inTexCoord0.xy * vecSkill41.z;//condition: greentex same scales as alphatex
Out.B1Coord = inTexCoord0.xy;
Out.B2Coord = inTexCoord0.xy;
return Out;
}

float4 ps_terraintex3_13(out_terraintex3 In): COLOR
{
// retrieve the pixels for the textures and the masks
float4 MaskColor = tex2D(sMaskTex,In.MaskCoord);
float4 BaseColor = tex2D(sBaseTex,In.BaseCoord);
float4 RedColor = tex2D(sRedTex,In.RedCoord);
float4 GreenColor = tex2D(sGreenTex,In.GreenCoord);
float4 BlueColor = tex2D(sBlueTex,In.BlueCoord);
float4 AlphaColor = tex2D(sAlphaTex,In.AlphaCoord);
float4 B1MaskColor = tex2D(sb1maskTex,In.B1Coord);
float4 B2MaskColor = tex2D(sb2maskTex,In.B2Coord);

// blend the textures over the base texture
//Add or subtract the other masks
//min-max for avoiding to low or high values
float4 BaseRed = lerp(BaseColor,RedColor,max(min(MaskColor.r+(B1MaskColor.r-B2MaskColor.r)*vecSkill41[3],255),0));
float4 BaseGreen = lerp(BaseRed,GreenColor,max(min(MaskColor.g+(B1MaskColor.g-B2MaskColor.g)*vecSkill41[3],255),0));
float4 BaseBlue = lerp(BaseGreen,BlueColor,max(min(MaskColor.b+(B1MaskColor.b-B2MaskColor.b)*vecSkill41[3],255),0));
float4 FinalColor = lerp(BaseBlue,AlphaColor,max(min(MaskColor.a+(B1MaskColor.a-B2MaskColor.a)*vecSkill41[3],255),0));

// Add the vertex light

FinalColor *= In.Color;
FinalColor.a = 1.0f; // prevent transparency
return FinalColor;
}

technique terraintex3_13
{
pass one
{
sampler[0] = (sMaskTex);
sampler[1] = (sBaseTex);
sampler[2] = (sRedTex);
sampler[3] = (sGreenTex);
sampler[4] = (sBlueTex);
sampler[5] = (sAlphaTex);
sampler[6] = (sb1maskTex);
sampler[7] = (sb2maskTex);

VertexShader = compile vs_2_0 vs_terraintex3();
PixelShader = compile ps_2_0 ps_terraintex3_13();
}
}

// fallback if nothing works
technique fallback { pass one { } }

";
}

ACTION terrain_base {
var proc;
MY.MATERIAL = mtl_terraintex3;
my.skill41 = float(15);
my.skill42 = float(15);
my.skill43 = float(15);
WHILE (1) {
WHILE (proc < 100) {
proc += time;
MY.SKILL44 = float(proc/100);
WAIT (1);
}
WHILE (proc > 0) {
proc -= time;
MY.SKILL44 = float(proc/100);
WAIT (1);
}
}
}

I changed the shaderversion to 2_0 because I needed more Texturecoords. If there is another possibility to avoid this, please explain it to me!

This has only a very simple blending system by now, I'll try to improve it.
It simply adds the components of the first blending mask to the normal mask, and subtracts the components of the second one. So the blending mask should only contain additions or subtractions to the original mask. I used the skill44 for a percentual value the contains how much the blending is done. The big disadvantage is that this changes all textures the same time, so in this version of the code, it only makes sense to have single colored blending masks.
I would need more entityskills to give a value for each texture.

The second disadvantage is that this produces a fluently (sorry for my english)
"morphing" of the textures. For filling a terrain with snow, this doesn't make sense, but I had no idea to create a "random" morphing so that it doesn't change the same kind at every point of the region.

The action is very simple and only for showing the effect.

Please post your ideas to improve the shader

Re: Opionion to this shaderidea [Re: RedPhoenix] #123905
04/17/07 22:15
04/17/07 22:15
Joined: Mar 2006
Posts: 2,503
SC, United States
xXxGuitar511 Offline
Expert
xXxGuitar511  Offline
Expert

Joined: Mar 2006
Posts: 2,503
SC, United States
For mixing colors:

outColor = lerp(Color1, Color2, percentage);

percentage (0 - 1) is how much of each color to blend between. 0 will = color1, 1 = color2, 0.5 = both evenly, etc.


xXxGuitar511
- Programmer
Re: Opionion to this shaderidea [Re: xXxGuitar511] #123906
04/17/07 22:44
04/17/07 22:44
Joined: Oct 2003
Posts: 4,131
M
Matt_Aufderheide Offline
Expert
Matt_Aufderheide  Offline
Expert
M

Joined: Oct 2003
Posts: 4,131
Quote:

blending 6 textures at once doesn't sound very efficient. You better split the big terrain in several smaller ones using only three textures. It's way faster (remember that every pixel of your terrain needs to be blended six times... that would cut your fps down).




On modern hardware its not going to be slow at all.. in fact you can do more than that no problem.. Texture samples and linear interpolation are very fast on the GPU. I have shaders that blend 16 textures on terrain..wihtout any framerate impact


Sphere Engine--the premier A6 graphics plugin.
Re: Opionion to this shaderidea [Re: Matt_Aufderheide] #123907
04/17/07 22:47
04/17/07 22:47
Joined: Mar 2006
Posts: 2,503
SC, United States
xXxGuitar511 Offline
Expert
xXxGuitar511  Offline
Expert

Joined: Mar 2006
Posts: 2,503
SC, United States
With 3DGS? how do you get 16 textures blended with 3DGS?


xXxGuitar511
- Programmer
Re: Opionion to this shaderidea [Re: xXxGuitar511] #123908
04/18/07 13:28
04/18/07 13:28
Joined: Jan 2007
Posts: 651
Germany
R
RedPhoenix Offline OP
User
RedPhoenix  Offline OP
User
R

Joined: Jan 2007
Posts: 651
Germany
@xxx_Guitar511

Yes I already corrected that. But it was working anyway

Ok I now set the scale of the textures to the materialskills, so I have 4 entityskills left for blending each channel seperated. That works well if you keep in mind that that alpha texture is always strongest blending and red textures is weakest, that's because of the order of the lerp commands (first red and last alpha is blended).

For blending the textures on an irregular way you can make the mask of the blending texture in an unregular way, and use values for the percentual blending higher than 100%, this will produce the effect that first the brightest parts of the mask will be filled (and the darker parts only a bit) but then also the darker parts will be filled completly and the brighter parts do not change anymore (because of the minmax limitation). But this still produces no randomeffect, (which would be quite nice I think). To get this you can change the maskbitmaps, but that's not a very good solution. Has anyone an idea how to get a random value inbetween the shader (I can't take it from script because it has to be another value for each pixel)?

EDIT @matt
This would be interesting for me too, how to get so many textures working? I thought of saving four textures together in one skin, but didn't get it working so far.

Last edited by RedPhoenix; 04/18/07 14:07.
Re: Opionion to this shaderidea [Re: RedPhoenix] #123909
04/18/07 16:13
04/18/07 16:13
Joined: Sep 2002
Posts: 8,177
Netherlands
PHeMoX Offline
Senior Expert
PHeMoX  Offline
Senior Expert

Joined: Sep 2002
Posts: 8,177
Netherlands
Quote:

I thought of saving four textures together in one skin, but didn't get it working so far.




Hey that's a good idea. Just change the offset of the texture to a corner. Should be very simple. Then simply render one skin multiple times, but change it's offset each time. I'm going to try this,

Edit: this won't work, you'll get into problems tiling your textures.

Cheers

Last edited by PHeMoX; 04/18/07 16:14.

PHeMoX, Innervision Software (c) 1995-2008

For more info visit: Innervision Software
Re: Opionion to this shaderidea [Re: PHeMoX] #123910
04/18/07 16:33
04/18/07 16:33
Joined: Jan 2007
Posts: 651
Germany
R
RedPhoenix Offline OP
User
RedPhoenix  Offline OP
User
R

Joined: Jan 2007
Posts: 651
Germany
I also thought about the tiling problem. I think that you have to limit the texturecoordinates on some way depending on a var given to the shader, which can switch between the textures. I tried to do it with a modulo operation (the rest of a division through the length of one texture in the skin, multiplicated with 1 or 2 for choosing the texture) but this does not workk very well with floats.

Last edited by RedPhoenix; 04/19/07 11:59.
Page 2 of 3 1 2 3

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