Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
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 (TipmyPip), 18,633 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
Need to access a float array #447846
01/09/15 02:42
01/09/15 02:42
Joined: Jan 2005
Posts: 330
USA
M
MatAllum Offline OP
Senior Member
MatAllum  Offline OP
Senior Member
M

Joined: Jan 2005
Posts: 330
USA
My improved dynamic lighting shader would be perfect if it wasn't for this problem I've run into. Basically, the vertex shader precalculates light direction factors for each of 8 possible dynamic lights and passes that data to the pixel shader to perform the actual attenuation so as to make a nice round light instead of one that clings to the model vertices. The effect looks absolutely beautiful... except for one problem.

Passing the light data requires transmitting 8 float values between vertex and pixel shader. As there is no such data type as a float8, I had to divide it up into two float4s, inLight1 and inLight2. The problem is, they don't overflow. Trying to access inLight1(4) does not give me the value of inLight2(0). I can "solve" the problem with an IF statement and a temp variable, but this puts me over the arithmetic limit and apparently mandates shader model 3.0 (???) which provides a prohibitive performance penalty.

For what it's worth, here's my pixel shader. Is there a more efficient way to access an array of 8?

Code:
float4 mainPS (
in float2 inCoord:TEXCOORD0,
in float3 inPos:TEXCOORD1,
in float3 inNormal:TEXCOORD2,
in float4 inLight1:TEXCOORD3,
in float4 inLight2:TEXCOORD4
) : COLOR
{
	float4 light = 0;
	for (int i = 0; i<iLights; ++i)
	{
		float angle;
		if(i > 3)
		{
			int j = i - 4;
			angle = inLight2[j];
		} 
		else
		{
			angle = inLight1[i];
		}
		light += saturate(angle * saturate(dot(inNormal, normalize(vecLightPos[i].xyz - inPos)))) * vecLightColor[i];
	}
	
	return tex2D(basemap,inCoord) * light;
}


Re: Need to access a float array [Re: MatAllum] #447847
01/09/15 03:20
01/09/15 03:20
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
It should be possible to simply define a float array[8], if not just define it outside (but obviously not as const(ant)) where you set the mat... matrices and set that array to the appropriate content in the pixel shader.

Btw. there's pretty much no reason to support anything below shader model 3.0 anymore. I pursued a sm 2.0 for my game too but one day simply abandoned it because it was way too limiting, the percentage of users, according to a steam survey, dropped from like 9 to ~2% or something like that, too (and those are most certainly not able to run your/ my game anyway).


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: Need to access a float array [Re: Superku] #447848
01/09/15 03:43
01/09/15 03:43
Joined: Jan 2005
Posts: 330
USA
M
MatAllum Offline OP
Senior Member
MatAllum  Offline OP
Senior Member
M

Joined: Jan 2005
Posts: 330
USA
Perhaps I was wrong about the specific shader model being the cause of lag. Maybe the code is just not efficient somehow. But thank you for the thoughts - I should have thought of some of those... I'll try it.


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