Gamestudio Links
Zorro Links
Newest Posts
Executing Trades on Next Bar Open
by Zheka. 06/20/24 14:26
Lapsa's very own thread
by rki. 06/19/24 11:27
A simple game ...
by VoroneTZ. 06/18/24 10:50
Face player all the time ...
by bbn1982. 06/18/24 10:25
Zorro Beta 2.61: PyTorch
by jcl. 06/10/24 14:42
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (TipmyPip, ozgur), 1,240 guests, and 10 spiders.
Key: Admin, Global Mod, Mod
Newest Members
squik, AemStones, LucasJoshua, Baklazhan, Hanky27
19060 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Basic Shader Questions #282579
08/02/09 11:12
08/02/09 11:12
Joined: May 2004
Posts: 1,510
Denmark
Claus_N Offline OP
Serious User
Claus_N  Offline OP
Serious User

Joined: May 2004
Posts: 1,510
Denmark
Hi,

I've started playing around with some basic HLSL shaders, however I got a few questions laugh

1. How do I scale a mesh from the vertex shader?
I've tried this:
Code:
struct VS_OUTPUT1
{
	float4 Pos :	POSITION;
};

VS_OUTPUT1 vs_main1(float4 inPos: POSITION,float3 inNormal: NORMAL)
{
	VS_OUTPUT1 Out;
	
	inPos.x += inNormal.x;
	inPos.y += inNormal.y;
	inPos.z += inNormal.z;
	
	Out.Pos = mul(inPos,matWorldViewProj);
	
	return Out;
}


It doesn't seem to be the best way of doing it though - look at the screenshot below, as the black outline is scaled using this code (the outline got a few flaws).

2. How do I render pass2 in my technique atop pass1?
I tried using "zenable = false" for my outline in pass1 - it worked fine in RenderMonkey, but when I tried it inside an actual game world, the outline was - of course - drawn atop other objects as well.

Here's a screenshot and my full code:


Code:
MATERIAL* mat_outline =
{
	effect = "
	
	texture entSkin1;
	
	sampler tSkin = sampler_state {Texture = <entSkin1>;};
	
	float4x4 matWorldViewProj;
	
	////////////////////// - PASS ONE CODE - //////////////////////
	struct VS_OUTPUT1
	{
		float4 Pos :	POSITION;
	};
	
	VS_OUTPUT1 vs_main1(float4 inPos: POSITION,float3 inNormal: NORMAL)
	{
		VS_OUTPUT1 Out;
		
		inPos.x += inNormal.x;
		inPos.y += inNormal.y;
		inPos.z += inNormal.z;
		
		Out.Pos = mul(inPos,matWorldViewProj);
		
		return Out;
	}
	
	float4 ps_main1() :	COLOR0
	{
		float4 color;
		
		color[0] = 0;
		color[1] = 0;
		color[2] = 0;
		color[3] = 1;
		
		return color;
	}
	
	////////////////////// - PASS TWO CODE - //////////////////////
	struct VS_OUTPUT2
	{
		float4 Pos :	POSITION;
		float2 Tex :	TEXCOORD0;
	};
	
	VS_OUTPUT2 vs_main2(float4 inPos: POSITION,float2 inTex: TEXCOORD0)
	{
		VS_OUTPUT2 Out;
		
		Out.Pos = mul(inPos,matWorldViewProj);
		Out.Tex = inTex;
		
		return Out;
	}
	
	float4 ps_main2(float2 inTex: TEXCOORD0) :	COLOR0
	{
		float4 color;
		
		color = tex2D(tSkin,inTex);
		
		return color;
	}
	
	////////////////////// - TECHNIQUE CODE - /////////////////////
	technique outline_technique
	{
		pass p1
		{
			zenable = false;
			VertexShader = compile vs_1_1 vs_main1();
			PixelShader = compile ps_2_0 ps_main1();
		}
		
		pass p2
		{
			zenable = true;
			VertexShader = compile vs_1_1 vs_main2();
			PixelShader = compile ps_2_0 ps_main2();
		}
	}
	
	";
}



Re: Basic Shader Questions [Re: Claus_N] #282591
08/02/09 12:07
08/02/09 12:07
Joined: Mar 2006
Posts: 3,538
WA, Australia
J
JibbSmart Offline
Expert
JibbSmart  Offline
Expert
J

Joined: Mar 2006
Posts: 3,538
WA, Australia
Firstly, swap this:
Code:
inPos.x += inNormal.x;
inPos.y += inNormal.y;
inPos.z += inNormal.z;

For this:
Code:
inPos.xyz += inNormal.xyz;



Secondly, don't use "zenable". In your outline pass use "cullmode = cw;", which means it'll render the backfaces of the inflated version.

Jibb


Formerly known as JulzMighty.
I made KarBOOM!
Re: Basic Shader Questions [Re: JibbSmart] #282592
08/02/09 12:27
08/02/09 12:27
Joined: May 2004
Posts: 1,510
Denmark
Claus_N Offline OP
Serious User
Claus_N  Offline OP
Serious User

Joined: May 2004
Posts: 1,510
Denmark
Thank you very much, it's working now! smile

I didn't even think about setting cullmode to 'cw' for the outline, although I tried setting it to 'none' to get less flaws in the outline.

Do you know how to fix the flaws in the outline? Or wouldn't it be possible to get a 'flawless' outline using this approach?

Oh, and to get back to my first question - is there another way of scaling an object from the vertex shader? Without using the vertex normals.

Re: Basic Shader Questions [Re: Claus_N] #282600
08/02/09 14:06
08/02/09 14:06
Joined: Mar 2006
Posts: 3,538
WA, Australia
J
JibbSmart Offline
Expert
JibbSmart  Offline
Expert
J

Joined: Mar 2006
Posts: 3,538
WA, Australia
Happy to help smile

Scaling without using the normals won't be very helpful for outlines. Scaling with the normals isn't a typical scale, it's more like it inflates like a balloon. You could scale the model by multiplying inPos by a scale factor before transforming it with matWorldViewProj, as prior to this transformation inPos just contains the vertex's coordinates in object space. But since frustum culling is based on the model's size in object space prior to what you do in the vertex shader, large scales could produce a noticeable "pop-in" as the large version suddenly appears as the bounds of the normal-sized version come into view.

If you just want to scale the whole model, use ENTITY.scale_x, _y, and _z in your code (but you probably know that).

Basically, if you want to do outlines this way, using the vertex normals is the only way AFAIK.

Those gaps are weird, and I have no idea what's causing them. Perhaps some of the vertices in the guard model aren't welded together when they should be.

Jibb


Formerly known as JulzMighty.
I made KarBOOM!
Re: Basic Shader Questions [Re: JibbSmart] #282606
08/02/09 14:49
08/02/09 14:49
Joined: May 2004
Posts: 1,510
Denmark
Claus_N Offline OP
Serious User
Claus_N  Offline OP
Serious User

Joined: May 2004
Posts: 1,510
Denmark
Thanks for the reply/explanation smile I think you're right that some vertices just needs to be welded together, as it worked fine with another model wink


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