Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General Puzzles V2 #353

Closed
cailuming opened this issue Nov 9, 2021 · 32 comments
Closed

General Puzzles V2 #353

cailuming opened this issue Nov 9, 2021 · 32 comments
Labels
support Support for general questions

Comments

@cailuming
Copy link

Hi there, How can I get the texture of final RenderTarget after postprocessing, I need draw the texture on Imgui::Image

@turanszkij
Copy link
Owner

If you need the 3D scene, use RenderPath3D::GetLastPostprocessRT() or RenderPath2D::GetRenderResult() if you need the 2D overlay. These are combined in the Compose() straight to the swapchain output, so if you need both combined, you need to render the 2D overlay on top of the 3D scene yourself into a texture.

@turanszkij turanszkij added the support Support for general questions label Nov 9, 2021
@cailuming
Copy link
Author

Thanks a lot

@cailuming
Copy link
Author

cailuming commented Nov 9, 2021

image
image
It's illegal to access the pointer when "m_pixels" is null. I found that the texture I got from "GetLastPostprocessRT()" shows black in Imgui::Image , so I decide to save the texture to file for seeking the reason, But I also failed to save the texture.

@cailuming
Copy link
Author

image
Here is what I did in update function

@cailuming
Copy link
Author

image
When I modify it to this , It works fine, But I don't know whether it could disturb other system

@turanszkij
Copy link
Owner

The texture format of the RenderPath3D post process is not something that can be saved to an image file right now. The image saving is for more regular formats like R8G8B8_UNORM and some block compressed formats with basis universal. There needs to be an other way of debugging this, check how the last postprocess rt is got from the render path, or try getting a different texture from RenderPath3D, for example the RenderPath3D::rtMain should be good for testing.

@turanszkij
Copy link
Owner

I added support for additional formats for texture saving in this commit: ddb2248
The new supported formats are: FORMAT_R16G16B16A16_FLOAT and FORMAT_R11G11B10_FLOAT which are used commonly in render paths.

@cailuming
Copy link
Author

image
the format of texture from RenderPath3D is FORMAT_R11G11B10_FLOAT, But as I tested, Imgui::Image only support FORMAT_R8G8B8A8_UNORM ,maybe. So is there some way to convert FORMAT_R11G11B10_FLOAT to FORMAT_R8G8B8A8_UNORM?

@turanszkij
Copy link
Owner

wiRenderer::CopyTexture2D() can be used to convert between texture formats. It uses compute shader, so cannot be inside a render pass. An other method would be to draw a full screen texture to a render pass. But I doubt this would be the problem. I was thinking that maybe the problem is that this texture format doesn't have alpha, so it's recognized as fully transparent. The wiImage::Draw() for example could be used to draw a transparent texture as opaque by setting opaque blend mode.

@turanszkij
Copy link
Owner

turanszkij commented Nov 12, 2021

This would be the simplest way of drawing a full screen image inside a renderpass and force it to be opaque:

wiImageParams fx;
fx.enableFullScreen(); // this is the most optimal setting for full screen image
fx.blendFlag = BLENDMODE_OPAQUE; // this will make it not use the texture's alpha, result will be always non-transparent
wiImage::Draw(&texture, fx, cmd);

@cailuming
Copy link
Author

Thanks for details, I created a new renderpass, using the depth texture of Renderpath3D and myself created Render target color texture as attachments. And then I Call wiImage::draw as you said,still get black. I suspect the Imgui isn't integrated perfectly to wi Engine, Or I need do more test to make it to work

@cailuming
Copy link
Author

image
God,finally, after many times painfull try, I got this. All is my fault, it's a reason of uv offset , thank you so much again!

@cailuming
Copy link
Author

Hi, how can I add a second or multi cameras to scene and switch among them?

@turanszkij
Copy link
Owner

turanszkij commented Nov 14, 2021

You can add multiple camera proxies to the Scene::cameras. You can one active camera in the RenderPath3D::camera which is a pointer to a single CameraComponent. It is best if your main camera is not part of the Scene, but your custom user code, or you can also use the global camera that you can get from wiScene::GetCamera(). But if you want to snap the main camera to a scene camera, you can just copy the main camera from scene camera, or follow it's transform, etc. It's up to you really.

This lua script for example animates the main camera between several different cameras in the scene (assuming the scene has cameras in it named cam0, cam1, cam2.... camN): https://github.com/turanszkij/WickedEngine/blob/master/Content/scripts/camera_animation_clamped.lua

@cailuming
Copy link
Author

Nice day, I'm confused about rendering a scene to texture(RenderTexture) using one camera, and rendering the output texture to the scene, just like a TV screen in the scene . I have tried to use two RenderPath3D, one for output texture, another is for rendering the texture to TV screen in the scene. but failed to run. Need I override the RenderPath and implement myself another one?

@turanszkij
Copy link
Owner

This is quite advanced and there is no example for this, so you'll have to experiment. You can use multiple render paths, each having it's own camera, scene and rendering resolution, and get their final texture.

But you can also implement a custom render to texture inside the renderpath too. For that, you can look at how the planar reflections are implemented, which is an effect that renders the scene from an other camera (but in a simpler way, without post processing and screen space effects).

For implementing something advanced like this and things don't work, you will need to use a graphics debugger.

@cailuming
Copy link
Author

Thanks,I will do more experiments

@cailuming
Copy link
Author

cailuming commented Mar 3, 2022

Hi, I found the collision mode both Triangle Mesh and Convex Hull for terrain would be crash,
image
image
image
and another issue , when I slide the slider, it will complain as following
image

image
image
by the way, displacement for terrain not work

@turanszkij
Copy link
Owner

Hi, in the first case it looks like you don't have the object selected, but the light, that's why it's failing "no MeshComponent provided" assert. In the second case I don't know.

About the terrain displacement, it looks like terrain currently doesn't support tessellation (when "terrain" is enabled for the MeshComponent). I will implement this later. You can also disable "terrain" feature of the mesh in the editor Mesh window. It will disable material blending, but it will still have the same geometry and tessellation support.

@cailuming
Copy link
Author

Still problems, I'm sure I have selected the terrain object by right click this time , but when I chose the ConvexHull mode, It will stuck forever until I kill the process.
image

Second, When creating the terrain , I clicked create button, and shows the dialog right , watch the resolution and height values, which are default value, In this case, I slide the Y slider , It will crash.

Or I missed something somewhere, sorry for that

@turanszkij
Copy link
Owner

This commit fixes the Y slider bug and a problem with "triangle mesh" type physics: 313fd0c

The convex hull physics hanging issue didn't occur for me. It is pretty slow in Debug build to calculate a convex hull, but it does finish. It is much faster in Release build. By the way, for a terrain (or any concave mesh) the convex hull physics collider will not work very well.

@cailuming
Copy link
Author

Hi there, I have some problems

  1. How should I do to enbale the pathtracing denoiser
    image
  2. When I put the light inside the bunny, almost no light get out, the bunny is entirely transmited
  3. How should I change the particle color during lifetime , for example, when the particle spawns, it will be red, and dies with blue
  4. particles in path tracing mode not work or I encountered when delete an emitter causing crash

@turanszkij
Copy link
Owner

  1. Denoiser must be included manually, by downloading a binary release of OpenImageDenoise: https://github.com/OpenImageDenoise/oidn/releases/tag/v1.4.3 . The include files (config.h, oidn.h, oidn.hpp) should be placed to WickedEngine/OpenImageDenoise folder, the lib files (OpenImageDenoise.lib, tbb.lib) to the build folder, for example BUILD/x64/Release. The DLL files (OpenImageDenoise.dll, tbb12.dll) to BUILD/x64/Release/Editor_Windows (near the exe). These paths are when you are using Release build. Then the engine needs to be rebuilt. You can find out how the denoiser lib is included and linked in the RenderPath3D_Pathtracing.cpp file. The denoiser will be used for path tracing and lightmap baking if it's included.

  2. I think that is expected. In that case, environment light and emissives could still affect lighting in path traced rendering.

  3. This is not supported currently, particles can have random starting color, and then fade out during lifetime. What do you think the workflow should be for specifying start-end colors?

  4. Particles should work in path tracing. For simple example, just add a new Emitter and enable path tracing, Or you can try any of the sample emitter models too in Content/models. The raytracing can crash sometimes, and I am always trying to improve stability of it. Raytracing effects can be slightly different too if you have raytracing GPU vs. non raytracing GPU, because they are using different implementations.

@cailuming
Copy link
Author

Thanks always, I imagine the trail flame of aircraft, the color may be white to blue or to other color gradient

@cailuming
Copy link
Author

image
it's gorgeous,I builded in release mode , But debug mode still not support, I'm trying to make it support too

@turanszkij
Copy link
Owner

Nice, if you want this in Debug mode, you will also need to put the lib and dlls in similar directories, just replacing Release with Debug in paths.

Thanks always, I imagine the trail flame of aircraft, the color may be white to blue or to other color gradient

Yeah this is a good idea and wouldn't be hard to implement, just not sure what's the best way to allow configuring this in the emitter.
An other way to do it would be to use two emitters, one orange for the main flame and one blue for the tail of the flames that lives a bit longer.

@cailuming
Copy link
Author

Hi, I need help when I'm trying to make a triangle or some other polygon manually, the case is following
TestCode:
```
Entity object = scene::GetScene().Entity_CreateObject("TestObject");
Entity light = scene::GetScene().Entity_CreateLight("TestLight");
Entity meshID = scene::GetScene().Entity_CreateMesh("TestMesh");
ObjectComponent &obj = scene::GetScene().objects.GetComponent(object);
obj.meshID = meshID;
LightComponent
lightComp = scene::GetScene().lights.GetComponent(light);
lightComp->energy = 100;
MeshComponent *mesh = scene::GetScene().meshes.GetComponent(meshID);

mesh->SetRenderable(true);
mesh->subsets.emplace_back();

mesh->vertex_positions.resize(3);
mesh->vertex_normals.resize(3);
mesh->vertex_colors.resize(3);
mesh->vertex_uvset_0.resize(3);
mesh->vertex_uvset_1.resize(3);
mesh->vertex_atlas.resize(3);
mesh->indices.resize(3);
mesh->vertex_positions[0] = XMFLOAT3(0,1,0);
mesh->vertex_positions[1] = XMFLOAT3(1, 0, 0);
mesh->vertex_positions[2] = XMFLOAT3(-1, 0, 0);
mesh->vertex_normals[0] = XMFLOAT3(1, 1, -1);
mesh->vertex_normals[1] = XMFLOAT3(1, 1, -1);
mesh->vertex_normals[2] = XMFLOAT3(1, 1, -1);

mesh->vertex_colors[0] = wi::Color::Red().rgba;
mesh->vertex_colors[1] = wi::Color::Blue().rgba;
mesh->vertex_colors[2] = wi::Color::Green().rgba;

mesh->indices[0] = 0;
mesh->indices[1] = 1;
mesh->indices[2] = 2;

mesh->vertex_uvset_0[0] = XMFLOAT2(0,0);
mesh->vertex_uvset_0[1] = XMFLOAT2(0, 1);
mesh->vertex_uvset_0[2] = XMFLOAT2(1, 1);

mesh->subsets.back().indexCount = (uint32_t)mesh->indices.size();

mesh->subsets.back().materialID = scene::GetScene().Entity_CreateMaterial("Material");
mesh->subsets.back().indexOffset = 0;
MaterialComponent* material = scene::GetScene().materials.GetComponent(mesh->subsets.back().materialID);
material->SetUseVertexColors(true);
material->baseColor = Color::Yellow();
material->shaderType = material->SHADERTYPE_PBR;
mesh->ComputeNormals(MeshComponent::COMPUTE_NORMALS_SMOOTH_FAST);
 
mesh->CreateRenderData();
But it shows nothing but black,I'm sure I have add light and some other prerequirements,and it really work when I load some model.
![image](https://user-images.githubusercontent.com/19427259/160962769-b3e3236d-f4e3-4784-9917-aa1bc2581a2e.png)

@turanszkij
Copy link
Owner

turanszkij commented Mar 31, 2022

Thanks for posting the code, it was easy for me to try it out. And in fact it works, I get this triangle:
image

But I had to go behind it, because the culling of it is reversed. This is because the indexing is the reverse order. To fix it, you can reorder the indices like this for example:

mesh->indices[0] = 0;
mesh->indices[1] = 2;
mesh->indices[2] = 1;

Or you can also call the mesh->FlipCulling(); to reverse the index winding order.

@cailuming
Copy link
Author

cailuming commented Apr 8, 2022

Hi,I met some problems, This is rendered by blender in Eevee,
image
and this is rendered by our engine
image
what makes me confused is that the point light and shadow is not so much contract and the color on the top of helmet behaves green , but the original color should tends more white and bright
model.zip

@turanszkij
Copy link
Owner

  1. I clicked on the ground mesh and in the mesh window Flip Normals button
  2. I added an Environmnet probe with the EnvProbe Button -> Put
    Result:
    image
    The helmet models have high metalness, so they don't have much color of their own, because they will take more of the environment color. In a black environment, their color will be mostly black too.

@turanszkij
Copy link
Owner

And this is their helmet with metalness = 0 (setin Material window)
image

@cailuming
Copy link
Author

cailuming commented Apr 8, 2022

Thanks, maybe I missed some settings and difference between blender eevee and WickedEngine, I'll do more experiment to make it looks similar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support Support for general questions
Projects
None yet
Development

No branches or pull requests

2 participants