Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

silvermace

Help with Very Simple Cg Program

This topic is 5479 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi, these 2 cg programs dont work (nothing is displayed on the screen (nonthing that i can see anyway) im a newbie to gc and shaders in general, so yea, anythng goes ! vertex_p.cg

// geometric input (sent by application)

struct appin
{
	float4 Position     : POSITION;
	float3 Normal       : NORMAL;
	float3 TCoords0     : TEXCOORD0;
	float3 TCoords1     : TEXCOORD1;
};

// vertex program output

struct V2FI
{
	float4 HPosition    : POSITION;
	float2 TCoords0     : TEXCOORD0;
	float2 TCoords1     : TEXCOORD1;
	float3 Normal       : TEXCOORD2;
	float3 ViewVector   : TEXCOORD3;
	float3 LightVector  : TEXCOORD4;
};

V2FI main
(
	appin IN,
	uniform float4x4 Proj   : register(c0), // projection matrix

	uniform float4x4 View   : register(c4), // modelview  matrix

	uniform float4x4 ViewI  : register(c8),
	uniform float4x4 ViewIT : register(c12),
	uniform float4   LightPos               // light pos in object space

) 
{
	V2FI OUT;

		// compute view vector

		float4 pos       = mul(View, IN.Position);
		OUT.ViewVector   = -pos.xyz;

		// compute light vector

		float4 lightpos  = mul(View, LightPos);
		OUT.LightVector  = (lightpos-pos).xyz;

		// project point onto screen

		OUT.HPosition    = mul(Proj, pos);

		// transform normal - should use inverse transpose !

		OUT.Normal       = mul(ViewIT, float4(IN.Normal,0.0)).xyz;

		// copy texture coordinates

		OUT.TCoords0     = IN.TCoords0;
                OUT.TCoords1     = IN.TCoords1;

	return OUT;
}



fragment_p.cg
   

// data interpolated from vertex program output

struct V2FI
{
	float4 HPosition    : POSITION;
	float2 TCoords0     : TEXCOORD0;
	float2 TCoords1     : TEXCOORD1;
	float3 Normal       : TEXCOORD2;
	float3 ViewVector   : TEXCOORD3;
	float3 LightVector  : TEXCOORD4;
};

// fragment program output

struct PixelOut 
{
    half4 COL;
    half DEPR;
};

PixelOut main(	V2FI IN,
		uniform sampler2D Texture0 : TEXUNIT0
		uniform sampler2D Texture1 : TEXUNIT1
		)
{
	// texture lookup

	half4 texcolor = h4tex2D(Texture0, IN.TCoords0.xy);

	// normalize (interp. per-fragment => norm != 1.0)

	half3 n = normalize(IN.Normal.xyz);
	half3 v = normalize(IN.ViewVector.xyz);
	half3 l = normalize(IN.LightVector.xyz);

	// compute specular coeff

	half3 r = reflect(-v,n);
	half  spec = pow(clamp( dot(l, r), 0.0, 1.0 ), 30.0);

	// compute diffuse coeff

	// -> clamp to keep an ambient illumination

	half diff = clamp(dot(n, l), 0.3, 1.0);

	// computes final color - uses alpha component for specular attenuation

	half4 color = texcolor * diff + ( spec * texcolor.w );


	PixelOut OUT;
	OUT.COL = color;

    return OUT;
}


A GOOD friend will come bail you out of jail... but, a TRUE friend will be sitting next to you saying, "Damn, we fucked up." Ingite 3D Game Engine Home -- Just click it [edited by - silvermace on August 15, 2003 6:05:01 PM]

Share this post


Link to post
Share on other sites
Advertisement

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!