Adding Wind to Grass

Discussion area about developing with Ogre2 branches (2.1, 2.2 and beyond)
Nickak2003
Gremlin
Posts: 194
Joined: Thu Jun 10, 2004 4:19 am
x 11
Contact:

Re: Adding Wind to Grass

Post by Nickak2003 »

Oh, I see. I didn't consider alignment in that respect. Dark_sylinc, is it ok to use a float without 3 pads or what?

Lax
Orc
Posts: 482
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 30

Re: Adding Wind to Grass

Post by Lax »

Hi,

thanks to all. Grass is now visible and swaying. The padding0, padding1 did help!

The only thing which is not working is the fog. No matter what values I set. I get no fog...

Best Regards
Lax
Image
http://www.lukas-kalinowski.com/Homepage/?page_id=1631
Please support Second Earth Technic Base built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd1 ... b97b79be62
Image

xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 166

Re: Adding Wind to Grass

Post by xrgo »

Lax wrote:
Sun Jul 12, 2020 2:55 pm
The only thing which is not working is the fog. No matter what values I set. I get no fog...
you have to actually use the passBuff fog params in your shader, this is a simple linear fog:

Code: Select all

			float fogDistance = length( inPs.pos );
			float fogFactor = 1.0-clamp((passBuf.fogEnd - fogDistance) / (passBuf.fogEnd - passBuf.fogStart),0.0,1.0);
			finalColour.xyz = lerp( finalColour, passBuf.fogColor, fogFactor );
put it in your @piece( custom_ps_posExecution )

Lax
Orc
Posts: 482
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 30

Re: Adding Wind to Grass

Post by Lax »

Hi xrgo,

Yes I'm already using those equation for fog calculation, but still nothing... No error, the Fog values are set correctly in "OgreHlmsLowLevel":

Code: Select all

mAutoParamDataSource->setFog( mCurrentSceneManager->getFogMode(),
                                          mCurrentSceneManager->getFogColour(),
                                          mCurrentSceneManager->getFogDensity(),
                                          mCurrentSceneManager->getFogStart(),
                                          mCurrentSceneManager->getFogEnd() );
The 800.VertexShader_piece_vs.any script:

Code: Select all

@piece( custom_vs_uniformDeclaration)
	Texture3D texPerlinNoise : register( t14 );
	SamplerState texPerlinNoiseSampler : register( s14);
@end


@piece( custom_vs_preTransform  )
@property(wind_enabled)

	float windFactor = 1.0 - input.uv0.y; 
	float random = texPerlinNoise.SampleLevel(texPerlinNoiseSampler, 0.2 * worldPos.xyz + float3(0.3, 0.3, 0.3) * passBuf.globalTime, 0).xyz - float3(0.2, 0.2, 0.2);
  	worldPos.xyz += random * windFactor * passBuf.windStrength;

@end
@end
The 800.PixelShader_piece_ps.any script:

Code: Select all

@piece(custom_ps_posExecution)
@property(!hlms_shadowcaster)
        //Linear Fog
	float fogDistance = length( inPs.pos );
	float fogFactor = 1.0 - clamp((passBuf.fogParams.y - fogDistance) / (passBuf.fogParams.y - passBuf.fogParams.x), 0.0, 1.0);
	finalColour.xyz = lerp(finalColour, passBuf.fogColor, fogFactor);

@end
@end
The 500.Structs_piece_vs_piece_ps.any script:

Code: Select all

@piece( custom_passBuffer )
	//Fog
	float4 fogParams;
	float4 fogColor;
	//wind
	float windStrength;
	float globalTime;
	float padding0;
	float padding1;
@end
I use the HlmsWind implementation from @nickak:

Code: Select all

...
Ogre::uint32 HlmsWindListener::getPassBufferSize(const Ogre::CompositorShadowNode* shadowNode, bool casterPass, bool dualParaboloid, Ogre::SceneManager* sceneManager) const
	{
		Ogre::uint32 size = 0;

		if (!casterPass)
		{
			unsigned int fogSize = sizeof(float) * 4 * 2; // float4 + float4 in bytes
			unsigned int windSize = sizeof(float);
			unsigned int timeSize = sizeof(float);
			unsigned int padding0 = sizeof(float);
			unsigned int padding1 = sizeof(float);

			size += fogSize + windSize + timeSize + padding0 + padding1;
		}
		return size;
	}
float* HlmsWindListener::preparePassBuffer(const Ogre::CompositorShadowNode* shadowNode, bool casterPass, bool dualParaboloid, Ogre::SceneManager* sceneManager, float* passBufferPtr)
	{
		if (!casterPass)
		{
			//Linear Fog parameters
			*passBufferPtr++ = sceneManager->getFogStart();
			*passBufferPtr++ = sceneManager->getFogEnd();
			*passBufferPtr++ = 0.0f;
			*passBufferPtr++ = 0.0f;

			*passBufferPtr++ = sceneManager->getFogColour().r;
			*passBufferPtr++ = sceneManager->getFogColour().g;
			*passBufferPtr++ = sceneManager->getFogColour().b;
			*passBufferPtr++ = 1.0f;

			*passBufferPtr++ = this->windStrength;

			*passBufferPtr++ = this->globalTime;
			*passBufferPtr++ = 0.0f;
			*passBufferPtr++ = 0.0f;

		}
		return passBufferPtr;
	}
..
                this->hlmsWind = dynamic_cast<HlmsWind*>(Ogre::Root::getSingleton().getHlmsManager()->getHlms(Ogre::HLMS_USER0));
		hlmsWind->setup(this->gameObjectPtr->getSceneManager());
		sceneManager->setFog(Ogre::FOG_LINEAR, Ogre::ColourValue(1, 1, 1), 0.0f, 10.0f, 300.0f);
See: http://www.lukas-kalinowski.com/Homepag ... /NoFog.mp4

The grass swaying does work correctly.

What could that be? I tried everything.

Best Regards
Lax
Image
http://www.lukas-kalinowski.com/Homepage/?page_id=1631
Please support Second Earth Technic Base built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd1 ... b97b79be62
Image

Nickak2003
Gremlin
Posts: 194
Joined: Thu Jun 10, 2004 4:19 am
x 11
Contact:

Re: Adding Wind to Grass

Post by Nickak2003 »

try manually setting the fog params to something like color = white, min = 10, max=300. Or something that makes sense just to check

Lax
Orc
Posts: 482
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 30

Re: Adding Wind to Grass

Post by Lax »

Hi,
try manually setting the fog params to something like color = white, min = 10, max=300. Or something that makes sense just to check
Yes I also tried that. I also updated to newest Ogre version. I think I will give up :(

Best Regards
Lax
Image
http://www.lukas-kalinowski.com/Homepage/?page_id=1631
Please support Second Earth Technic Base built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd1 ... b97b79be62
Image

xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 166

Re: Adding Wind to Grass

Post by xrgo »

use renderdoc! you can see the values of your passBuf in the shader
also try to test values on your shader like finalColour.xyz = float3(1,0,0) just to see if its reaching/including that piece

also try this:

Code: Select all

outPs_colour0.xyz = lerp( finalColour, passBuf.fogColor, fogFactor );
instead of;

Code: Select all

finalColour.xyz = lerp(finalColour, passBuf.fogColor, fogFactor);
and I am out of ideas :)

Lax
Orc
Posts: 482
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 30

Re: Adding Wind to Grass

Post by Lax »

Hi xrgo,

Setting the values directly did also not work.
What Ogre version are you guys using? I'm using the newest Ogre version from git master.

I tried RenderDoc, its amazing and complex :| I first have to learn, how it works.

[edit]: It seems as if fog params are take into account:

Code: Select all

460: add r0.x, -r0.x, passBuf.fogParams.y
 461: add r1.x, -passBuf.fogParams.x, passBuf.fogParams.y
 462: div_sat r0.x, r0.x, r1.x
 463: add r0.x, -r0.x, l(1.0000)
 464: add r1.xyz, -r0.yzwy, passBuf.fogColor.xyzx
 465: mad o0.xyz, r0.xxxx, r1.xyzx, r0.yzwy
 466: ret
So the issue must be somewhere else... maybe there is no connection to sceneManager->setFog(...)?

Best Regards
Lax
Image
http://www.lukas-kalinowski.com/Homepage/?page_id=1631
Please support Second Earth Technic Base built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd1 ... b97b79be62
Image

xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 166

Re: Adding Wind to Grass

Post by xrgo »

I am using Ogre master from a week ago
Lax wrote:
Tue Jul 14, 2020 9:04 am
maybe there is no connection to sceneManager->setFog(...)?
you can easily test that by hardcoding some values... instead of:

Code: Select all

			//Linear Fog parameters
			*passBufferPtr++ = sceneManager->getFogStart();
			*passBufferPtr++ = sceneManager->getFogEnd();
			*passBufferPtr++ = 0.0f;
			*passBufferPtr++ = 0.0f;

			*passBufferPtr++ = sceneManager->getFogColour().r;
			*passBufferPtr++ = sceneManager->getFogColour().g;
			*passBufferPtr++ = sceneManager->getFogColour().b;
			*passBufferPtr++ = 1.0f;
try something like this:

Code: Select all

			//Linear Fog parameters
			*passBufferPtr++ = 10;
			*passBufferPtr++ = 50;
			*passBufferPtr++ = 0.0f;
			*passBufferPtr++ = 0.0f;

			*passBufferPtr++ = 1.0;
			*passBufferPtr++ = 0.0;
			*passBufferPtr++ = 0.0;
			*passBufferPtr++ = 1.0f;

Lax
Orc
Posts: 482
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 30

Re: Adding Wind to Grass

Post by Lax »

Hi xrgo,

I think I know what is going on.
I tested with your values, which would set a red fog. What now happens is, when I move away from the swaying grass, it will become more and more red. That is: The shader do only work with the grass and not global. That is because fog and wind is set together I think.

@Nicknak: How can it be, that fog is working for you :) ??

Best Regards
Lax
Image
http://www.lukas-kalinowski.com/Homepage/?page_id=1631
Please support Second Earth Technic Base built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd1 ... b97b79be62
Image

xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 166

Re: Adding Wind to Grass

Post by xrgo »

strange! are the other objects also using HlmsPbsDatablocks? what if you set same grass datablock to another object?

Lax
Orc
Posts: 482
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 30

Re: Adding Wind to Grass

Post by Lax »

Hi xrgo,
strange! are the other objects also using HlmsPbsDatablocks? what if you set same grass datablock to another object?
Yes, thats exactly the case, see:

http://www.lukas-kalinowski.com/Homepag ... bjects.mp4

Maybe the wrong hlms folders are loaded? Here is what is loaded when registerHlms is called:

Code: Select all

Unlit:
+		[0]	"Hlms/Common/HLSL"	
+		[1]	"Hlms/Common/Any"
+		[2]	"Hlms/Unlit/Any"	

Pbs:
+		[0]	"Hlms/Common/HLSL"	
+		[1]	"Hlms/Common/Any"
+		[2]	"Hlms/Pbs/Any"	
+		[3]	"Hlms/Pbs/Any/Main"

Terra:
+		[0]	"Hlms/Common/HLSL"	
+		[1]	"Hlms/Common/Any"	
+		[2]	"Hlms/Pbs/Any"
+		[3]	"Hlms/Pbs/Any/Main"	
+		[4]	"Hlms/Terra/Any"
+		 [5]    "Hlms/Terra/HLSL/PbsTerraShadows"

Wind:
+		[0]	"Hlms/Common/HLSL"	
+		[1]	"Hlms/Common/Any"	
+		[2]	"Hlms/Pbs/Any"
+		[3]	"Hlms/Pbs/Any/Main"
+		[4]	"Hlms/Wind/Any"	

Best Regards
Lax
Image
http://www.lukas-kalinowski.com/Homepage/?page_id=1631
Please support Second Earth Technic Base built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd1 ... b97b79be62
Image

Nickak2003
Gremlin
Posts: 194
Joined: Thu Jun 10, 2004 4:19 am
x 11
Contact:

Re: Adding Wind to Grass

Post by Nickak2003 »

I am using terra, and i Had to implement fog a second time for terra

Nickak2003
Gremlin
Posts: 194
Joined: Thu Jun 10, 2004 4:19 am
x 11
Contact:

Re: Adding Wind to Grass

Post by Nickak2003 »

You need to implement fog on whichever hlms need to use it

Nickak2003
Gremlin
Posts: 194
Joined: Thu Jun 10, 2004 4:19 am
x 11
Contact:

Re: Adding Wind to Grass

Post by Nickak2003 »

you can add fog to pbs with the listener

Lax
Orc
Posts: 482
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 30

Re: Adding Wind to Grass

Post by Lax »

You need to implement fog on whichever hlms need to use it
Ahh thats a good advice. I will try that out.

Best Regards
Lax
Image
http://www.lukas-kalinowski.com/Homepage/?page_id=1631
Please support Second Earth Technic Base built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd1 ... b97b79be62
Image

Post Reply