Writing only red color component to AGAL pixel shader output - fragment-shader

I want a pixel shader om AGAL that instead of simply copying the color passed to it from the vertex shader to the output, only copies the red component from the passed color and sets the green and blue components to zero. In pseudo code:
temp = 0
temp.red = in.red
temp.alpha = in.alpha
out = temp
I can't figure out how to write this in AGAL. The following doesn't do it:
mov ft0.ra, v0.ra
mov oc, ft0
How can I get the result I want?

You must remember that
using ".something" on the right of the destination register means you are using masks
using ".something" on the right of a source register means you are using swizzles.
Supposing that
fc0 contains a zero in the first component
v0 contains the color from which you want to extract the red component
So here is your fragment shader:
// shader.
mov ft0, fc0.xxxx // fill ft0 with zeros
mov ft0.xw, v0.xxxw // fill ft0.x with v0.x and ft0.w with v0.w
mov oc, ft0
Source: I wrote Minko's ActionScript 3 to AGAL compiler.

Related

How to test if a facet of a periodic c3t3 is on the boundary

I'm trying to extract the boundary facets of a periodic c3t3, i.e. all boundary facets including those at the periodic boundaries. My current approach is to try to iterate trough all the tetrahedra and test one by one its facets with "is_infinite" (see the code snipped bellow), but "is_infinite" is always returning false.
for(Cell_iterator cit = c3t3P.cells_begin(); cit !=c3t3P.cells_end(); ++cit) {
for(int l=0; l<4; ++l) {
const int id = V[cit->vertex(l)];
CGAL_assertion(1 <= id && id <= medit_number_of_vertices);
t[l] = id - 1;
if( tr.is_infinite(cit, l) )
std::cout << "is true!" << std::endl ;//Facet_boundary.push_back(points[t[l]]);
}
}
Here is a way you could go at your problem given the clarification in the comments above:
Start from a point on your surface
Use the locate() function of the periodic triangulation . This gives you a cell and an offset such that the point is in the tetrahedron of this cell translated by the offset parameter.
You can qualify whether a vertex of the periodic triangulation is contained in the interior, on the boundary, or in the exterior of the 3D closed shape using the class Side_of_triangle_mesh.
Walk from cell to cell (using cell->neighbor(0...3)). Note that as you walk, you will eventually reach the border of the internal representation and will need to shift offset when going to its neighboring cell: that's the purpose of the neighbor_offset() function that I mentioned in the comments.
For a given visited cell, qualify the position of its vertices as in (Side_of_triangle_mesh returns on boundary or on bounded side) or out (Side_of_triangle_mesh returns on unbounded side) of the shape. The position canonical position is given by Periodic_triangulation::point(Cell_handle, index) and you can shift it using Periodic_triangulation::construct_point(Point, Offset).
Do not explore the neighbors of a cell whose vertices are all out.
Cells whose vertices are all in are directly in your output.
For cells that have some vertices in and some vertices out, you could create a surface mesh from the tetrahedron (for example with make_tetrahedron) and compute the intersection with the shape using the corefine_and_compute_intersection.

Can I overlap two framebuffer attachments outputs in a fragment shader?

Right now I am writing out to a colour buffer in the fragment shader, which is a float format.
layout (location = 0) out vec4 outColour;
I need to have a way to write the object's id to a framebuffer for picking. There are a number of ways I've thought about doing this. I can compile two versions for each shader, one a normal one, and another for the picking, which basically only needs to do the vertex position transformations and then skip everything else, lighting calculations, texturing, etc. This probably isn't ideal because this is essentially doubling the number of shaders I have to write.
An easier method I've thought is to do a conditional branch (preferably over a specialisation constant), and for picking purposes compile a picking version of the graphics pipeline with the picking boolean value set to true. This sounds better. For the ordinary passes I can write to multiple attachments. Will it be best to compile that picking pipeline with a new render pass that writes to only one framebuffer attachment, an integer one? If I swap the render pass for one that writes an integer at attachment 0 instead of the float 4 can I alias this in the fragment shader?
layout (location = 0) out vec4 outColour;
layout (location = 0) out ivec4 out_id;
void main()
{
vec4 colour;
int object_id;
if (bPicking)
out_id = ivec4(object_id, 0, 0, 0); // y, z, w not used
else
out_colour = colour;
}
I'm guessing I really need a different render pass because instead of writing to a R32G32B32A32_SFLOAT image I'm writing to a R8_UINT image for the IDs. This is really confusing what's the best way to do this?

ASM 8086 : Reading the value of a variable is different from the value assigned to the variable

I'm writing a little program in Assembly 8086 and I have to use variables.
So I have a variable that is defined in the data segment :
myVar BYTE 3,0
Afterwards in my code I have to acces the variable and use it's value. But the program did not work like expected. So I searched the error in my code and I found that when I acces "myVar", the value is different from the value I assigned to it.
When I print the contents of "myVar" it prints 173 instead of 3 :
xor dx, dx
mov dl, myVar
push dx
CALL tprint
"tprint" is a function I wrote, that will display the number passed as argument via the stack. So in this case it will print the content of the DX register.
When I put 3 in dx and then print it, it prints 3, so "tprint" works fine :
xor dx, dx
mov dl, 3
push dx
CALL tprint
So the problem is that when I move the contents of the variable "myVar" in the DL register, the wrong value is put in DL (another value than the value assigned to "myVar") :
xor dx, dx
mov dl, myVar ; DL != 3 --> why???
I really don't understand this behaviour, I searched a lot of sites and they all do it this way, why does it works fine for them and not for me?
Remark : The "tprint" function is a function for printing signed numbers using two's complement method.
Thanks for your help!
When you move a value from a register, you want to use brackets to move the actual value and not the memory address. So for
mov dl, myVar
you're likely moving just the pointer instead of the value.
See this link

Updating variable that lives in the data segment from the stack and its segment

I currently have three segments of memory, my main data segment, stack segment and the segment where my API lives. The following instructions are executed from the data segment, they push the address of cursorRow and welcomeMsg then do a far call to the function in my API segment. The cursorRow variable lives in the main data segment that is calling the API function. The call looks like this:
push cursorRow
push welcomeMsg
call API_SEGMENT:API_printString
How can I alter cursorRow, inside of the segment where my API lives, through the stack? cursorRow needs to be updated from the API. NO API functions alter the data segment. I have tried things like: inc byte [ds:bp+8] and add [ds:bp+8], 1.
Here is the API procedure being called:
printStringProc:
push bp
mov bp, sp
mov si, [bp+6]
.printloop:
lodsb
cmp al, 0
je printStringDone
mov ah, 0x0E ; teletype output
mov bh, 0x00 ; page number
mov bl, 0x07 ; color (only in graphic mode)
int 0x10
jmp .printloop
printStringDone:
; move the cursor down
mov ah, 02h ; move cursor
mov dh, [bp+8]
mov dl, 0 ; column
mov bh, 0 ; page number
int 10h
add [ds:bp+8], 1
pop bp
retf
it prints strings, but the cursorRow variable doesn't correctly update. I hope I'm clear enough on my issue. It's hard to explain :D
This is because you passed the pointer to cursorRow, not cursorRow itself. When you perform
inc [ds:bp+8]
you: 1) get the value of bp, 2) add 8, 3) assume the result is a pointer in ds, 4) increment the value stored there (the pointer to cursorRow). Since the pointer is stored on the stack, you are incrementing the pointer when you do this. What you need to do is take the pointer off of the stack and increment the value that points to.
mov bx, [bp+8]
inc [bx]
This code: 1) gets the value of bp, 2) adds 8, 3) assumes the result is a pointer in ss, 4) load the value stored there (the pointer to cursorRow) into bx, 5) assumes bx is a pointer in ds, 6) increments the value stored there (the value of cursorRow).
It's look like you just pushed the value of cursorRow onto the stack. Without the address you cannot update it. With the address you can easily reference that addresses' value, put it into a register, perform operations on it, then take the value that's in that register and put it into the address of cursorRow.

Basic samples for shader in Managed DirectX

I am new write a pixel shader and use in my managed directx project, where i can get some basic sample to start it.
I'm assuming you know how to create a device.
First, you need to prepare the shader itself.
Here's a little sample pixel shader (which uses pixel shader 1.4, as seen by ps_1_4; r0 is a register that is read as the final result; v0 is a register that stores primary colour (of diffuse lighting)):
ps_1_4
mov r0, v0
This shader, which is in shader assembly, has to be assembled. You can do that as follows (note that you need D3DX library referenced, otherwise you won't see the ShaderLoader class):
Imports Microsoft.DirectX
' other code
Dim graphicsStream As GraphicsStream = Direct3D.ShaderLoader.FromString(shaderText, Nothing, Direct3D.ShaderFlags.None)
' other code.
After assembling the shader, you can finally create a PixelShader object as follows:
' other code
Dim p As Direct3D.PixelShader = New Direct3D.PixelShader(Device, graphicsStream)
' other code
To apply the pixel shader, use:
' other code
Device.PixelShader = p
' other code
where Device is the Direct3D Device.
A similar process applies for compiling shaders in case you use HLSL.
Edit:
Just noticed this was an year old question.