Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
4 registered members (fogman, Grant, AndrewAMD, juanex), 989 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
[solved] Basic (?) shader help! Cant get vecAmbient #267495
05/24/09 13:11
05/24/09 13:11
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Firstly, dont flame me for stealing Matts shader code. Im just using it to train myself on.

Problem. I cant make use of the vecAmbient values. They appear to always be zero.
Same with specular and emissive, but not really tested. Diffuse seems locked to 1.0
Ive tried (in main.c) to set them (on the MATERIAL) using vars AND floatv but no effects, at ALL.
Ive also tried various versions of the final return in the PS below, including
just return(vecAmbient); but still nothing.
Can someone tell me, am I missing something basic? Im only new to shader programming...
Thanks
Code:
float4x4 matWorldViewProj;	
float4x4 matWorld;
float4 	 vecLightPos[8];
float4 	 vecLightColor[8];
float4 	 vecViewPos;
float4 	 vecFog;


float4	 vecAmbient;
float4	 vecDiffuse;
float4	 vecSpecular;
float4	 vecEmissive;


texture  entSkin1;
texture  entSkin2;


sampler texts = sampler_state
{
	Texture = <entSkin1>;
	MinFilter = Linear;
	MagFilter = Linear;
	MipFilter = Linear;   
	AddressU  = wrap;
	AddressV  = wrap;
};


sampler bumps = sampler_state
{
	Texture = <entSkin2>;
	MinFilter = Linear;
	MagFilter = Linear;
	MipFilter = Linear;   
	AddressU  = wrap;
	AddressV  = wrap;
};



// -------------------------------------------------------------
// 2.0
// -------------------------------------------------------------
//
struct VS_INPUT
{
	float4 Pos		: POSITION;
	float2 Tex		: TEXCOORD0;
	float3 Normal 	: NORMAL;
	float3 Tangent 	: TEXCOORD2;
};
//
struct VS_OUTPUT
{
	float4	Pos		: POSITION;
	float2	Tex		: TEXCOORD0;
	float3	View	: TEXCOORD1;
	float4	Light1	: TEXCOORD2;
	float4	Light2	: TEXCOORD3;
	float	Fog		: FOG;
};
//
struct PS_INPUT
{
	float2	Tex		: TEXCOORD0;
	float3	View	: TEXCOORD1;
	float4	Light1	: TEXCOORD2;
	float4	Light2	: TEXCOORD3;
};
//
//
//
//
VS_OUTPUT VS_PASS(VS_INPUT In ,uniform float passs )
{
	VS_OUTPUT Out = (VS_OUTPUT)0;      
	float3x3 worldToTangentSpace;
	worldToTangentSpace[0] = mul(In.Tangent, matWorld);
	worldToTangentSpace[1] = mul(cross(In.Tangent, In.Normal), matWorld);
	worldToTangentSpace[2] = mul(In.Normal, matWorld);
    float3 PosWorld = mul(In.Pos, matWorld);
	//misc   
	Out.Pos = mul(In.Pos, matWorldViewProj);
    Out.Tex	 = In.Tex;
    Out.View = mul(worldToTangentSpace, - (PosWorld - vecViewPos));
    //Light 0, 2, 4
    Out.Light1.xyz  = mul(worldToTangentSpace, - (PosWorld - vecLightPos[passs*2]));
    Out.Light1.w 	= distance(PosWorld,vecLightPos[passs*2])/vecLightPos[passs*2].w;
    //Light 1, 3, 5
    Out.Light2.xyz  = mul(worldToTangentSpace, -(PosWorld - vecLightPos[passs*2+1]));
    Out.Light2.w 	= distance(PosWorld,vecLightPos[passs*2+1])/vecLightPos[passs*2+1].w;
	//
	Out.Fog = 1 - (distance(PosWorld, vecViewPos) - vecFog.x) * (vecFog.z);
	//
	return Out;
}
//
//
float4 PS_PASS( PS_INPUT In ,uniform float passs )	:	COLOR
{
	//misc   
    float4 color = tex2D(texts, In.Tex);
    float3 bumpNormal = 2 * (tex2D(bumps, In.Tex) - 0.5);
    float4 gloss = tex2D( bumps, In.Tex );
    float3 ViewDir = normalize(In.View);  
    //Light 0, 2, 4
    float3 dir_1 = normalize(In.Light1);   
    float4 diff1 = saturate(dot(bumpNormal, dir_1));
    float  shad1 = saturate(4 * diff1);
    float3 refl1 = normalize(2 * diff1 * bumpNormal - dir_1);
    float4 spec1 = pow(saturate(dot(refl1, ViewDir)), 15); 
    float4 attn1 = saturate(dot(In.Light1.w, In.Light1.w));
    //Light 1, 3, 5
    float3 dir_2 = normalize(In.Light2);     
    float4 diff2 = saturate(dot(bumpNormal, dir_2));
    float  shad2 = saturate(4 * diff2);
    float3 refl2 = normalize(2 * diff2 * bumpNormal - dir_2);
    float4 spec2 = pow(saturate(dot(refl2, ViewDir)), 15); 
    float4 attn2 = saturate(dot(In.Light2.w, In.Light2.w));
	//
    return
    (  
		
		//////  VecAmbient APPEARS to never get any value from the material ambient values. WHY!

		( vecAmbient * color ) + 		 //////////////

		///////////////////////////////////////////////
		
	    ((shad1 * (color * diff1 + (spec1*gloss.w)) * (1-attn1))*vecLightColor[passs*2]) + 
	    ((shad2 * (color * diff2 + (spec2*gloss.w)) * (1-attn2))*vecLightColor[passs*2+1])
    );	    
}
//
//
//
// -------------------------------------------------------------
// techniques//
// -------------------------------------------------------------
//
// 2.0
technique SpecularNormalMapping_20
{
    pass P0
    {
		alphablendenable=false;
		srcblend=zero;
		// compile shaders
		VertexShader = compile vs_2_0 VS_PASS(0);
		PixelShader  = compile ps_2_0 PS_PASS(0);
    }
	//
    pass P1
    {
		//blend second pass additively with first 
		alphablendenable=true;
   	 	srcblend=one;
		destblend=one;
		// compile shaders
		VertexShader = compile vs_2_0 VS_PASS(1);
		PixelShader  = compile ps_2_0 PS_PASS(1);
    } 
    pass P2
    {
		//blend second pass additively with first and second 
		alphablendenable=true;
		srcblend=one;
		destblend=one;
		// compile shaders
		VertexShader = compile vs_2_0 VS_PASS(2);
		PixelShader  = compile ps_2_0 PS_PASS(2);
    } 
}
//
//
// Fallback; If nothing works
technique fallback { pass one { } }
//



"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: [solved] Basic (?) shader help! Cant get vecAmbient [Re: EvilSOB] #267567
05/25/09 02:09
05/25/09 02:09
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Problem solved. Some retarded person still had a material embedded
in the MDL's skin, and setting the material in code apparently doesnt
override these settings.
Damn it... That was dumb...


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial

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