Sharpdx Direct3D10 How to edit pixels in texture? - texture2d

I need to change certain pixels in a texture (Texture2D) using Sharpdx with dx10
Right now I got
Texture.Map(0, MapMode.Write, MapFlags.None, out stream);
but I get a "The parameter is incorrect." exception.
All solutions I find are for either dx9 or dx11 or something other then Sharpdx and the used methods don't exist in Sharpdx.Direct3D10, hopefully someone here knows how to do this simple task of editing a texture...

Related

what is the equivelant of get_global_pos from version 2.0 in 3.0?

I want to make a turret that is shooting lazers and i watched a tutorial on it. The person in the video used (scenename).position(get.node("Position2D").get_global_pos()) in order to spawn a projectile on the potition 2d. When i run this code, the game freezes and the debugger says "Invalid call. Nonexistant function 'get_global_pos' in base 2D". In the comments someone said that the tutorial is using 2.0 godot and that in 3.0 you dont use get_ and instead of pos you put potition, so i tried changing get_global_pos to global_position but it didnt work. i am very new to this and if you want any further information please let me know
As you already found out, global_position is the equivalent to get_global_pos.
The difference is, that global_position is no function but a member.
So instead of:
(scenename).position(get.node("Position2D").get_global_pos())
you have to write:
(scenename).position = get.node("Position2D").global_position

tex2D(s,t,ddx,ddy) not working in fullscreen in unity

i'm trying to make full screen custom post effect.
with script added to main cam, with one line: blit(src,dst,mat) in void OnRenderImage(src,dst). I wrote the shader with _MainTex so it'll work in "Blit". I done it(many times) all correctlly like in tuts. if i assign this shader to any object (with texture) it works well, but the problem is when i assign that shader(in material) to script (blit(,,mat)) it ignores the ddx,ddy part,it works like tex2D(tex,uv). WHY? how can I fix it?
here is the fragment code.
fixed3 frag(vout v):sv_target
{
fixed3 c;
float2 cddx=float2(
pow(abs(0.5-v.uv.x),1.6)*_xy,
-pow(abs(0.5-v.uv.y),1.6)*_xy);
float2 cddy=float2(
-pow(abs(0.5-v.uv.x),1.6)*_xy,
pow(abs(0.5-v.uv.y),1.6)*_xy);
c=tex2D(_MainTex,v.uv,cddx,cddy);
return c*0.5;
}
I found an answer. tex2D(sampler2D,uv,ddx,ddy) and tex2Dgrad(...) methods use mipmaps. when i tried to pass "screen" texture to the shader in blit(src,dst,mat) I noticed that src has no mipmaps, only the original texture. so, I thought that I'll simply add mipmaps with src.GenerateMips() and it'll work. but there is a catch: if i try to do that the editor throws me exceptions that the rendertexture is created, that generating mips is unsuported in created rendertexture and other stuff... finally i found the recipy:
one time
create another temp renderTexture
turn off auto generate mipmaps
useMips=true
every frame (OnRenderImage(...))
blit src to temp
generate mipmaps in temp
blit(temp,dst,mat)
it generates mipmaps on new render texture and passes it to the shader without any errors.
one last thing, if someone knows how to specify mipmap count that i want to generate, tell me please.
I hope it'll be helpful to newbies in shaders like me.

Why is my "waterproof" polyhedron causing "WARNING: Object may not be a valid 2-manifold and may need repair!"?

In the script
difference() {
polyhedron(
points=[[0,0,0],
[2,0,0],
[2,1,0],
[0,1,0],
[0,0,2],
[0,1,2]],
faces=[[0,1,2,3],
[5,4,1,2],
[5,4,0,3],
[0,1,4],
[2,3,5]]);
cube([1,1,1]);
};
the polyhedron alone works fine (is rendered without warnings), but adding the cube above causes the warning WARNING: Object may not be a valid 2-manifold and may need repair! to be logged and the output to only render some parts of some surfaces.
I'm using OpenSCAD 2015.03-1 on Ubuntu 16.04.
This is because your polyhedron has some faces pointing into the wrong direction, causing issues when calculating the difference().
See the Manual and FAQ for details.
Changing the winding order of the affected polygons fixes the polyhedron:
difference() {
polyhedron(
points=[[0,0,0],
[2,0,0],
[2,1,0],
[0,1,0],
[0,0,2],
[0,1,2]],
faces=[[0,1,2,3],
[2,1,4,5],
[5,4,0,3],
[0,4,1],
[2,5,3]]);
cube([1,1,1]);
};
The difference is still non-manifold as cutting the cube results in 2 prism shaped objects just touching at one edge. That's also by definition not 2-manifold, so the warning remains.
Depending on how the exported model is supposed to be used, you could choose to ignore this warning and hope the tool processing the 3d model can handle that.
To remove the issue, for example the cube could be made a bit smaller like cube([1, 1, 0.999]).
An unrelated, but still useful strategy for preventing issues later on is to always make the cutting object a bit larger to ensure that no very thin planes remain, e.g. use cube([2,3,1.999], center = true). That will also remove the display artifacts in preview mode.

Batch processing clip layer: " 'NoneType' object has no attribute 'pendingFields' "

I am trying to clip many vector layers to a boundary by following the tutorial at http://www.qgistutorials.com/en/docs/batch_processing.html
ie using Clip in the Processing Toolbox, then 'execute as batch process'. However, I recieve an error message -
Algorithm Clip starting...
'NoneType' object has no attribute 'pendingFields'
but I don't know what that message means or how to fix it. Thanks for any help
EDIT: in the end I clipped the layers one by one through the 'Geoprocessing - Clip' menu. That worked, so now I suppose the issue is with the batch processing command rather than the shapefiles themselves.
I think the problem is that bash didn't get the target layer.
I get the similar error when I run reprojection.
before the input layer was "A layer", the input is a string.
then I redo select from open layers. the quotation mark disappear.
it works for me.
I've had the same problem. I solved it by using layers from file system instead of opened layers.
This is not very convenient but it can help !

three.js toDataURL PNG is black

I'm trying to grab a screenshot with renderer.domElement.toDataURL("image/png"), and save it to a file.
The image is the right size, but it's black.
I have preserveDrawingBuffer turned on.
I think I'm decoding and saving the file correctly, because when I hexdump it I can see the correct initial characters for the PNG format, as well as the IHDR and IDAT chunk headers. However the closing IEND is missing.
Any known issues here? Hints? Windows 7/Firefox up to date if it matters.
Thanks... (Sorry if this is dumb, I'm very new to three.js)
I had somewhat similar problems with Windows 7/Firefox. PNG Data URL's would be randomly truncated or something, much shorter than a successful PNG export. Trying to set that data url as image src resulted in "Image corrupt" exception or something in FF. As little sense it makse, setting a small window.setTimeout (10ms) between rendering and getting the data URL helped in my case. Maybe Firefox needs a rest from the JS engine before it refreshes some canvas internal state or something.. weird.
I switched to JPG format (smaller files => truncation less of an issue?) and still saw it not working, then I tried this tip which I found here
If you want to save data that is derived from a Javascript
canvas.toDataURL() function, you have to convert blanks into plusses.
If you do not do that, the decoded data is corrupted:
<?php
$encodedData = str_replace(' ','+',$encodedData);
$decodedData = base64_decode($encodedData);
?>
This worked. Thanks, Mekal.
This tip seems to apply to JPGs only. I saw PNGs decoding correctly without the + replacement, and corruptly with it. I can use JPGs so my personal problem is solved. However I never saw a PNG that wasn't black even when decoded correctly and not truncated.
Kind of a lousy situation either way, I feel like. What is up with the +'s?
A black texture is a sign that you did not indicate the texture needs to be updated.
Also, you do not need to use canvas.toDataURL(). You can pass in the canvas reference to the THREE.Texture object.
var canvas = document.getElementById('#myCanvas');
var texture = new THREE.Texture(canvas);
texture.needsUpdate = true;
// Now render the scene