Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

Help with some complicated C coding


  • Please log in to reply

#1
stettybet0

stettybet0

    Trusted Tech

  • Technician
  • 2,579 posts
I'm trying to combine two mods for the PC game STALKER. I've had a fair bit of success, but now I've reached a point where the coding is a bit over my head. The code is written in C. Attached are two versions of two files. The first versions (designated by a 1 at the end) are from one mod. When they are used, the game works fine. The second versions (designated by a 2 at the end) are from another mod. When they are used, the game crashes. I am wanting the second versions to work, as they contain special code that adds Parallax Occlusion Mapping to the game. Can anyone tell me what I need to do to the second versions to make them work, while keeping the special POM feature? The code pertaining to POM is marked off by comments.

Thanks,

Attached Files


  • 0

Advertisements


#2
Will_00

Will_00

    Member

  • Member
  • PipPipPip
  • 226 posts
Could you please repost these with the "correct" format - this is important as many parts of the code dwell upon the fact of formatting.
  • 0

#3
stettybet0

stettybet0

    Trusted Tech

  • Topic Starter
  • Technician
  • 2,579 posts
The formatting that you see when you download the files is the same as it actually is. I don't think formatting is the problem, because separately both of these mods work. Thanks for the thought though. :)
  • 0

#4
Will_00

Will_00

    Member

  • Member
  • PipPipPip
  • 226 posts
It seems that some of the variables are not correctly assigned.
  • 0

#5
stettybet0

stettybet0

    Trusted Tech

  • Topic Starter
  • Technician
  • 2,579 posts
If you could be a bit more specific, that would be helpful. :)
  • 0

#6
Will_00

Will_00

    Member

  • Member
  • PipPipPip
  • 226 posts
I would suggest checking the following:

From Common1:
float 	calc_cyclic 	(float x)				{
	float 	phase 	= 1/(2*3.141592653589f);
	float 	sqrt2	= 1.4142136f;
	float 	sqrt2m2	= 2.8284271f;
	float 	f 	= sqrt2m2*frac(x)-sqrt2;	// [-sqrt2 .. +sqrt2] !No changes made, but this controls the grass wave (which is violent if I must say)
	return 	f*f - 1.f;				// [-1	 .. +1]
}
float2 	calc_xz_wave 	(float2 dir2D, float frac)		{
	// Beizer
	float2  ctrl_A	= float2(0.f,		0.f	);
	float2 	ctrl_B	= float2(dir2D.x,	dir2D.y	);
	return  lerp	(ctrl_A, ctrl_B, frac);

Common2:

float4 offsetBest = float4(vTexCurrentOffset,0,0);
	vTexCurrentOffset.xy -= vTexOffsetPerStep;
   	float fPrevHeight = tex2Dlod( s_base, float4(vTexCurrentOffset.xy,0,0) ).a+Brightness;
   	if (fPrevHeight > Q2) fPrevHeight = 1.0f;
	  else if (fPrevHeight < Q1) fPrevHeight = 0.0f;
	  else fPrevHeight = (fPrevHeight - Q1)/(Q2-Q1);
	float error = 1.0;
	float t1 = fCurrentBound;
	float t0 = t1 + fStepSize;
	float delta1 = t1 - fCurrHeight;
	float delta0 = t0 - fPrevHeight;
	float4 intersect = float4(vDelta, vDelta + tc);
	for (int i=0; i<3 && abs(error) > 0.01; i++)
	{
	  float denom = (delta1 - delta0);
	  float t = (t0 * delta1 - t1 * delta0) / denom;
	  offsetBest.xy = -t * intersect.xy + intersect.zw;
	  float NB = tex2Dlod(s_base, offsetBest).a+Brightness;
	  if (NB > Q2) NB = 1.0f;
		else if (NB < Q1) NB = 0.0f;
		else NB = (NB - Q1)/(Q2-Q1);
	  error = t - NB;

  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP