Jump to content

Water Reflection & Sky?


Umnik
 Share

Recommended Posts

code example?

 

how have you set the reflections?

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites


TBuffer gbuffer=CreateBuffer(GraphicsWidth(),GraphicsHeight(),BUFFER_COLOR|BUFFER_DEPTH|BUFFER_NORMAL);


TBuffer lightbuffer=CreateBuffer(GraphicsWidth(),GraphicsHeight(),BUFFER_COLOR|BUFFER_DEPTH);
TBuffer reflectionbuffer=CreateBuffer(GraphicsWidth(),GraphicsHeight(),BUFFER_COLOR|BUFFER_DEPTH|BUFFER_NORMAL);//gbuffer for rendering reflections
TBuffer reflectionlightbuffer=CreateBuffer(GraphicsWidth(),GraphicsHeight(),BUFFER_COLOR|BUFFER_DEPTH);//buffer for rendering reflection lighting to

...
...
...

TWorld background=CreateWorld();
TMesh skybox=CreateCube();
TCamera skycam=CreateCamera();
FlipMesh(skybox);
PaintEntity(skybox,LoadMaterial("abstract::FullskiesBlueClear0016_2_L.mat"));

foreground=CreateWorld();

waterplane=CreateMesh();
TSurface surf=CreateSurface(waterplane);
AddVertex(surf,Vec3(0.5,0,-0.5));
AddVertex(surf,Vec3(0.5,0,0.5));
AddVertex(surf,Vec3(-0.5,0,0.5));
AddVertex(surf,Vec3(-0.5,0,-0.5));
AddTriangle(surf,0,2,1);
AddTriangle(surf,2,0,3);
UpdateMesh(waterplane);
PositionEntity(waterplane,Vec3(0,29,0));
ScaleEntity(waterplane,Vec3(2048));
EntityOcclusionMode(waterplane,1);

fgcam = CreateCamera();
CameraClearMode(fgcam,0);


SetWorld(world);

TBody waterbody=CreateBodyBox(20,20,20);
EntityType(waterbody,4);
PositionEntity(waterbody,Vec3(0,12-10,0));
EntityParent(waterbody,waterplane);

SetFluidPlane(Vec4(0.0,1.0,0.0,-EntityPosition(waterplane).Y),0.1);
SetFluidDensity(1);
SetFluidViscosity(0,0);


reflectioncam=CreateCamera();
HideEntity(reflectioncam);

TMaterial watermaterial=LoadMaterial("abstract::water.mat");
SetMaterialTexture(watermaterial,GetColorBuffer(reflectionlightbuffer),2);
SetMaterialTexture(watermaterial,GetColorBuffer(lightbuffer),3);
SetMaterialTexture(watermaterial,GetDepthBuffer(gbuffer),4);
TShader watershader=GetMaterialShader(watermaterial);
SetShaderFloat(watershader,"visibility",10.0); // Дальность вида в глубину
SetShaderFloat(watershader,"softness",10.0); // Прозрачность воды
TMaterial underwatermaterial=LoadMaterial("abstract::underwater.mat");
SetMaterialTexture(underwatermaterial,GetColorBuffer(reflectionlightbuffer),2);
SetMaterialTexture(underwatermaterial,GetColorBuffer(lightbuffer),3);
SetMaterialTexture(underwatermaterial,GetDepthBuffer(gbuffer),4);

TShader postfilter=LoadShader("abstract::postfilter.vert","abstract::postfilter_distancefog_wobble.frag");
SetShaderVec4(postfilter,"fogcolor",Vec4(1.02,1.59,1.74,1.0));
SetShaderVec2(postfilter,"fogrange",Vec2(0,5));
wobbletexture=LoadTexture("abstract::wobbledot3.dds");

...
...
...
while( !KeyHit() && !AppTerminate() )	{
	UpdateAppTime();
		UpdateWorld();
		//UpdateWorld(AppSpeed());
		SetBuffer(gbuffer);
		SetWorld(background);
		RenderWorld();
		SetWorld(world);
		RenderWorld();
		SetBuffer(BackBuffer());
		RenderLights(gbuffer);
		SetBuffer(lightbuffer);
		RenderLights(gbuffer);
		CopyBuffer(gbuffer,BackBuffer(),BUFFER_DEPTH);
		CopyBuffer(lightbuffer,BackBuffer(),BUFFER_COLOR);

if (EntityPosition(camera).Y>EntityPosition(waterplane).Y) {
if (!EntityCulled(waterplane,fgcam)) {
							PaintEntity(waterplane,watermaterial);
			SetShadowQuality(1);//low-quality shadows are fine when rendering reflections
			SetBuffer(reflectionbuffer); // Включаем рефлёность воды с отражением
			ShowEntity(reflectioncam); //Выводим отражение
			HideEntity(camera); //Скрываем камеру
			float waterheight=EntityPosition(waterplane).Y;
			SetCameraClipPlane(reflectioncam,0,Vec4(0,1,0,-waterheight));
			TVec3 pos = EntityPosition(camera);
			TVec3 rot = EntityRotation(camera);
			pos.Y=waterheight-(pos.Y-waterheight);
			PositionEntity(reflectioncam,pos);
			ScaleEntity(reflectioncam,Vec3(1,-1,1));
			RotateEntity(reflectioncam,Vec3(-rot.X,rot.Y,rot.Z));
			RenderWorld();				//Now render lighting for the reflection
			SetBuffer(reflectionlightbuffer);
			RenderLights(reflectionbuffer);
							//Restore settings
			ShowEntity(camera);
			HideEntity(reflectioncam);
			SetShadowQuality(1);
		}
		SetWorld(foreground);
		SetBuffer(BackBuffer());
		SetEntityMatrix(fgcam,GetEntityMatrix(camera));
		RenderWorld();
	} else {
		PaintEntity(waterplane,underwatermaterial);
					SetWorld(foreground);
		SetBuffer(gbuffer);
		CopyBuffer(lightbuffer,gbuffer,BUFFER_COLOR|BUFFER_DEPTH);
		CopyBuffer(lightbuffer,gbuffer,BUFFER_COLOR|BUFFER_DEPTH);
		SetEntityMatrix(fgcam,GetEntityMatrix(camera));
		RenderWorld();
					SetBuffer(BackBuffer());
		SetShader(postfilter);
		BindTexture(GetDepthBuffer(gbuffer),1); 
  		BindTexture(wobbletexture,7);
		TTexture tex=GetColorBuffer(gbuffer);
		TextureFilter(tex,TEXFILTER_SMOOTH);
		DrawImage(tex,0,TextureHeight(tex),TextureWidth(tex),-TextureHeight(tex));
		TextureFilter(tex,TEXFILTER_PIXEL);
		SetShader(NULL);
           }
}

 

Sample from tutorial clear!

Windows 7 Ultimate x64bit / Intel Core 2 Quad Q8400 / 4GB DDR2 SDRAM / GeForce 8800 GTS

Resource War Developer [ dev blog ]

Link to comment
Share on other sites

Is this from the rendering water tutorial?

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

I'm still very new at this, but I loaded my scene using the example posted in this thread:

 

http://leadwerks.com/werkspace/index.php?/topic/381-scene-loading-example/

 

 

It uses the SetSkybox() function in "Framewerk.h"

 

// Load Skybox

fw.GetRenderer().SetSkybox(LoadMaterial("abstract::FullskiesBlueClear0016_2_L.mat"));

 

It doesn't look like you're using Framewerk, but you may want to look for the SetSkybox() function in "Framwerk.cpp" to see exactly what it is doing. It reflects everything correctly in my scene.

 

Hope that helps

  • Upvote 1
Link to comment
Share on other sites

Framewerk is not a 3rd party library, it's part of LE. It makes really no sense not to use it. If more features and customizations are needed in Framewerk, they can be added, but so far nobody (except Michael Betke) hasn't really said what they would like to see added to it. In the C++ version it would be easily possible to add a hook or callback to have your own custom postshaders added. It should be possible in the BlitzMax version too.

  • Upvote 1

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

I agree with Lumooja it really makes no sense not to use framewerk. Plus most of the tutes need updating for the more recent versions of the engine, which I think Josh is in the middle of right now.

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...