Adding Wind to Grass
-
- Goblin
- Posts: 272
- Joined: Thu Jun 10, 2004 4:19 am
- x 26
Re: Adding Wind to Grass
-
- Gnoll
- Posts: 659
- Joined: Mon Aug 06, 2007 12:53 pm
- Location: Saarland, Germany
- x 63
Re: Adding Wind to Grass
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
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
-
- OGRE Expert User
- Posts: 1148
- Joined: Sat Jul 06, 2013 10:59 pm
- Location: Chile
- x 169
Re: Adding Wind to Grass
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 );
-
- Gnoll
- Posts: 659
- Joined: Mon Aug 06, 2007 12:53 pm
- Location: Saarland, Germany
- x 63
Re: Adding Wind to Grass
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() );
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
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
Code: Select all
@piece( custom_passBuffer )
//Fog
float4 fogParams;
float4 fogColor;
//wind
float windStrength;
float globalTime;
float padding0;
float padding1;
@end
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);
The grass swaying does work correctly.
What could that be? I tried everything.
Best Regards
Lax
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
-
- Goblin
- Posts: 272
- Joined: Thu Jun 10, 2004 4:19 am
- x 26
Re: Adding Wind to Grass
-
- Gnoll
- Posts: 659
- Joined: Mon Aug 06, 2007 12:53 pm
- Location: Saarland, Germany
- x 63
Re: Adding Wind to Grass
Yes I also tried that. I also updated to newest Ogre version. I think I will give uptry manually setting the fog params to something like color = white, min = 10, max=300. Or something that makes sense just to check
Best Regards
Lax
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
-
- OGRE Expert User
- Posts: 1148
- Joined: Sat Jul 06, 2013 10:59 pm
- Location: Chile
- x 169
Re: Adding Wind to Grass
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 );
Code: Select all
finalColour.xyz = lerp(finalColour, passBuf.fogColor, fogFactor);
-
- Gnoll
- Posts: 659
- Joined: Mon Aug 06, 2007 12:53 pm
- Location: Saarland, Germany
- x 63
Re: Adding Wind to Grass
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
Best Regards
Lax
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
-
- OGRE Expert User
- Posts: 1148
- Joined: Sat Jul 06, 2013 10:59 pm
- Location: Chile
- x 169
Re: Adding Wind to Grass
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;
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;
-
- Gnoll
- Posts: 659
- Joined: Mon Aug 06, 2007 12:53 pm
- Location: Saarland, Germany
- x 63
Re: Adding Wind to Grass
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
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
-
- OGRE Expert User
- Posts: 1148
- Joined: Sat Jul 06, 2013 10:59 pm
- Location: Chile
- x 169
Re: Adding Wind to Grass
-
- Gnoll
- Posts: 659
- Joined: Mon Aug 06, 2007 12:53 pm
- Location: Saarland, Germany
- x 63
Re: Adding Wind to Grass
Yes, thats exactly the case, see:strange! are the other objects also using HlmsPbsDatablocks? what if you set same grass datablock to another object?
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"
Lax
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
-
- Goblin
- Posts: 272
- Joined: Thu Jun 10, 2004 4:19 am
- x 26
Re: Adding Wind to Grass
-
- Goblin
- Posts: 272
- Joined: Thu Jun 10, 2004 4:19 am
- x 26
Re: Adding Wind to Grass
-
- Goblin
- Posts: 272
- Joined: Thu Jun 10, 2004 4:19 am
- x 26
Re: Adding Wind to Grass
-
- Gnoll
- Posts: 659
- Joined: Mon Aug 06, 2007 12:53 pm
- Location: Saarland, Germany
- x 63
Re: Adding Wind to Grass
Ahh thats a good advice. I will try that out.You need to implement fog on whichever hlms need to use it
Best Regards
Lax
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