Gamestudio Links
Zorro Links
Newest Posts
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
Release 2.68 replacement of the .par format
by Martin_HH. 09/23/25 20:48
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (dBc), 17,971 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
water -> sin() wave + normals? #355906
01/29/11 20:39
01/29/11 20:39
Joined: May 2002
Posts: 7,441
ventilator Offline OP
Senior Expert
ventilator  Offline OP
Senior Expert

Joined: May 2002
Posts: 7,441
i haven't done any shader programming since a long time... laugh

i have to do a very simple water shader with a sin() wave. my question is, does anyone have any tips about how to handle the normals? how should i transform them to still get a correct lighting? rotate them with sin()/cos() somehow or is there a better way?

this is what i have so far (it needs to be shader model 1.1 unfortunately):
Code:
MATERIAL* mtl_water =
{
	effect =
	"
		float3 vecSunDir;
		float4 vecTime;
		float4x4 matWorld;
		float4x4 matWorldViewProj;
	   
		texture entSkin1;
		
		sampler SKIN1 = sampler_state {texture = <entSkin1>;};
		
		//----------------------------------------------------------------------- color
		void p0mainVS(
			in float4 inPosition : POSITION0,
			in float2 inTexCoord : TEXCOORD0,
			in float3 inNormal : NORMAL,
			out float4 outPosition : POSITION0,
			out float2 outTexCoord : TEXCOORD0,
			out float3 outDiffuse : COLOR0) 
		{
			inPosition.y += sin((vecTime.w + inPosition.x) * 0.1) * 8;
			outPosition = mul(inPosition, matWorldViewProj);
			outTexCoord = inTexCoord;
			outDiffuse = saturate(dot(mul(inNormal, matWorld), -vecSunDir)) * 0.6 + 0.4;
		}
		
		void p0mainPS(
			in float4 inTexCoord: TEXCOORD0,
			in float3 inDiffuse : COLOR0,
			out float4 outColor : COLOR0)
		{
			float4 color = tex2D(SKIN1, inTexCoord);
			outColor = color * float4(inDiffuse, 0.8);
		}
		
		//----------------------------------------------------------------------- technique
		technique t0
		{
			pass p0
		 	{
				//zWriteEnable = false;
  				VertexShader = compile vs_1_1 p0mainVS();
  				PixelShader = compile ps_1_1 p0mainPS();
		 	}
		}
		
	";
}



Re: water -> sin() wave + normals? [Re: ventilator] #355914
01/29/11 21:01
01/29/11 21:01
Joined: May 2005
Posts: 2,713
Lübeck
Slin Offline
Expert
Slin  Offline
Expert

Joined: May 2005
Posts: 2,713
Lübeck
I usually use the cross product of the directions to two other points close to the current vertex. In your case one could of course simplify that a bit. No idea if it fits into the shadermodel though...

If I didn´t confuse a1-3 and b1-3 something like this should do the job:
Code:
float height = sin((vecTime.w + inPosition.x) * 0.1) * 8;
float heightnext = sin((vecTime.w + inPosition.x+VERTDISTINX) * 0.1) * 8;
inPosition.y += height;
inNormal = normalize(float3((heightnext-height)*VERTDISTINX, -VERTDISTINX*VERTDISTINX, 0.0));



Last edited by Slin; 01/29/11 21:43.
Re: water -> sin() wave + normals? [Re: Slin] #355915
01/29/11 21:05
01/29/11 21:05
Joined: May 2002
Posts: 7,441
ventilator Offline OP
Senior Expert
ventilator  Offline OP
Senior Expert

Joined: May 2002
Posts: 7,441
good idea, thanks!

this didn't come to my mind since i thought i have no access to other vertices anyway. but in a grid it's easy to figure out their position actually. laugh

simple 1.1 hatching shader? [Re: ventilator] #355927
01/29/11 21:51
01/29/11 21:51
Joined: May 2002
Posts: 7,441
ventilator Offline OP
Senior Expert
ventilator  Offline OP
Senior Expert

Joined: May 2002
Posts: 7,441
another thing i have to do is a simple hatching shader.

do you have any tips how to solve this with shader model 1.1?

i would like to have 3 hatching patterns in the rgb channels of a texture.

how can i best switch between those depending on the diffuse value? 0.0-0.3 -> use r channel, 0.3-0.6 -> use g channel, 0.6-0.9 -> use b channel.

does a 1.1 pixel shader support enough instructions for this?

Re: simple 1.1 hatching shader? [Re: ventilator] #355936
01/29/11 22:21
01/29/11 22:21
Joined: May 2005
Posts: 2,713
Lübeck
Slin Offline
Expert
Slin  Offline
Expert

Joined: May 2005
Posts: 2,713
Lübeck
The only idea I can come up with for now is to use another texcoord register which you already set depending on the diffuse color within the vertexshader.
In the pixelshader you can then just use the dotproduct with the hatching pattern textures color.
The problem there is interpolation, but I doubt that you will stay wthin the limits otherwize. I would try "if", as I think that calculating the values would be a bit more complex in the end.

Re: simple 1.1 hatching shader? [Re: Slin] #355943
01/29/11 23:00
01/29/11 23:00
Joined: May 2002
Posts: 7,441
ventilator Offline OP
Senior Expert
ventilator  Offline OP
Senior Expert

Joined: May 2002
Posts: 7,441
Quote:

if(inDiffuse.x < 0.15) outColor = float4(color2.b, color2.b, color2.b, 1.0);
else if(inDiffuse.x < 0.3) outColor = float4(color2.g, color2.g, color2.g, 1.0);
else if(inDiffuse.x < 0.45) outColor = float4(color2.r, color2.r, color2.r, 1.0);
else if(inDiffuse.x < 0.6) outColor = float4(color1.b, color1.b, color1.b, 1.0);
else if(inDiffuse.x < 0.75) outColor = float4(color1.g, color1.g, color1.g, 1.0);
else outColor = float4(color1.r, color1.r, color1.r, 1.0);


with if it works nicely, even with shader model 1.1.
what does this get translated into?
does this have any disadvantages?

edit: weird! how can so many ifs work with 1.1 (which just supported 8 assembler instructions if i remember correctly)? could it be that ps_1_1 gets ignored and the shader model of the gpu always gets used? which would be really stupid since my card supports 4.0 and i have to develop for 1.1. is there some way to force 1.1?

Quote:
The problem there is interpolation, but I doubt that you will stay wthin the limits otherwize.
the hard borders don't look as well as i had imagined. so interpolation probably would be better anyway.

Re: simple 1.1 hatching shader? [Re: ventilator] #355958
01/30/11 01:43
01/30/11 01:43
Joined: May 2002
Posts: 7,441
ventilator Offline OP
Senior Expert
ventilator  Offline OP
Senior Expert

Joined: May 2002
Posts: 7,441
crap, it seems like 1.1 pixel shaders aren't supported anymore with hlsl and it silently compiles to 2.0 instead. i hate assembler. tongue

Re: simple 1.1 hatching shader? [Re: ventilator] #355963
01/30/11 02:29
01/30/11 02:29
Joined: Mar 2006
Posts: 3,538
WA, Australia
J
JibbSmart Offline
Expert
JibbSmart  Offline
Expert
J

Joined: Mar 2006
Posts: 3,538
WA, Australia
Originally Posted By: ventilator
crap, it seems like 1.1 pixel shaders aren't supported anymore with hlsl and it silently compiles to 2.0 instead. i hate assembler. tongue
Really? Where'd you find that?

Jibb


Formerly known as JulzMighty.
I made KarBOOM!
Re: simple 1.1 hatching shader? [Re: JibbSmart] #355964
01/30/11 02:33
01/30/11 02:33
Joined: May 2002
Posts: 7,441
ventilator Offline OP
Senior Expert
ventilator  Offline OP
Senior Expert

Joined: May 2002
Posts: 7,441
http://msdn.microsoft.com/en-us/library/bb509709%28v=vs.85%29.aspx

here and i also found it mentioned on some other pages.

it seems to be true since i can use a ridiculous amount of hlsl commands which for sure won't result in just 8 assembler instructions.

Re: simple 1.1 hatching shader? [Re: ventilator] #355966
01/30/11 02:39
01/30/11 02:39
Joined: Mar 2006
Posts: 3,538
WA, Australia
J
JibbSmart Offline
Expert
JibbSmart  Offline
Expert
J

Joined: Mar 2006
Posts: 3,538
WA, Australia
Wow. That makes sense. I was surprised to not need to write 1.1 fallbacks for KarBOOM, since compiling for 1.1 appeared to work.

Jibb


Formerly known as JulzMighty.
I made KarBOOM!
Page 1 of 2 1 2

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