Hi! I’m messing with the render pipeline and some post processing. I’m attempting to add a simple depth fog.
This is my .render_script
s init function.
function init(self)
local color_params = {
format = render.FORMAT_RGBA,
width = 128,
height = 128,
}
local depth_params = {
format = render.FORMAT_RGBA,
width = 128,
height = 128,
}
local target_params = { [render.BUFFER_COLOR_BIT] = color_params, [render.BUFFER_DEPTH_BIT] = depth_params }
self.lowrez = render.render_target("lowrez", target_params)
render.enable_texture("render_target", self.lowrez, render.BUFFER_DEPTH_BIT)
end
I’m getting an error Render target '(asset 262146 type=ASSET_TYPE_RENDER_TARGET)' does not have a texture for the specified buffer type (type=BUFFER_TYPE_DEPTH_BIT)
.
The error persists when moving the render.enable_texture
to the update
function.
This doesn’t feel right. Am I doing something wrong?
defold:dev
← defold:issue-3547-depth-stencil-as-tex-take-2
opened 10:21PM - 25 May 23 UTC
Added support for creating render targets with depth buffers as textures, which … enables you do bind them to a shader like a regular texture without the need to write the depth data to the color texture. To create a rendertarget with a depth texture, pass in the render.TEXTURE_BIT flag in the depth buffer parameters.
```lua
-- Creating the RT in a render script:
local color_params = {
format = render.FORMAT_RGBA,
width = render.get_window_width(),
height = render.get_window_height(),
}
local depth_params = {
format = render.FORMAT_DEPTH,
width = render.get_window_width(),
height = render.get_window_height(),
flags = render.TEXTURE_BIT -- this will create the depth buffer as a texture
}
self.my_render_target = render.render_target({
[render.BUFFER_COLOR_BIT] = color_params,
[render.BUFFER_DEPTH_BIT] = depth_params
})
-- bind / enable the depth texture to a texture slot on a material:
render.enable_texture(0, self.my_render_target, render.BUFFER_DEPTH_BIT)
```
Fixes #3547
## PR checklist
* [x] Code
* [x] Add engine and/or editor unit tests.
* [x] New and changed code follows the overall code style of existing code
* [x] Add comments where needed
* [ ] Documentation
* [x] Make sure that API documentation is updated in code comments
* [ ] Make sure that manuals are updated (in github.com/defold/doc)
* [x] Prepare pull request and affected issue for automatic release notes generator
* [x] Pull request - Write a message that explains what this pull request does. What was the problem? How was it solved? What are the changes to APIs or the new APIs introduced? This message will be used in the generated release notes. Make sure it is well written and understandable for a user of Defold.
* [x] Pull request - Write a pull request title that in a sentence summarises what the pull request does. Do not include "Issue-1234 ..." in the title. This text will be used in the generated release notes.
* [x] Pull request - Link the pull request to the issue(s) it is closing. Use on of the [approved closing keywords](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue).
* [x] Affected issue - Assign the issue to a project. Do not assign the pull request to a project if there is an issue which the pull request closes.
* [x] Affected issue - Assign the "breaking change" label to the issue if introducing a breaking change.
* [x] Affected issue - Assign the "skip release notes" is the issue should not be included in the generated release notes.
Found this PR. I just needed one more line of code.
For future reference:
local depth_params = {
format = render.FORMAT_DEPTH,
width = 128,
height = 128,
flags = render.TEXTURE_BIT,
}
1 Like