Errors when compiling GLSL Geometry shader: "Geometry shader didn't declare primitive input type" - graphics

I can't seem to find out how to make simplest geometry shader in glsl work:
#version 330 core
layout ( triangle_strip , max_vertices = 3) out;
layout ( triangles ) in;
void main(void){}
At runtime I get error:
geometry shader didn't declare primitive input type
Does anyone know what's up with that ?
I am using libGdx but that should be calling C API anyways since I use LWJGL3 as backend.
Edit:
Case closed. I found out I wasn't passing quite what I was expecting as geometry shader, but tests in pure C++ worked so I was able to figure out where it goes wrong.

Related

Directx12- Texture always returns ZERO when the texture format is UINT

Recently,I am learning the SAT(summed area table) Varinance Shadow Mapping.It is suggested in the paper that I can use uint format SAT to prevent precision loss.So I change my SAT format from DXGI_FORMAT_R32G32_FLOAT to DXGI_FORMAT_R32G32_UINT.However, with the same code and shader except the texture format is different, the float format texture works fine, but the uint format texture always returns ZERO(I find this problem by using RenderDoc pixel debugger).This problem persists when I use Sample() method , Load() method and even compute shader!
I have tried many ways but nothing works.Please help me!!!!!!!!!
And I do not show any code here,because I have no idea about which part of code to show.
I am a Rookie just like my name.
So if you need some code,please tell me.Thanks a lot!!
If possible,please tell me some possible solutions of this problem. Thank you very much for your answers!

GODOT How can I xray through tilemaps around me

So I'm looking to create an effect of having a bubble around my player which, when he enters a hidden area (hidden by tilemaps) the bubble activates and it essentially has an xray effect. So I can see the background, the ground and all the items inside the area I just can't see the blocks themselves.
So pretty much going from this
To this
And as I go further in the more gets revealed
I have no idea what to even begin searching for this. So any direction would be greatly appreciated
First of all, I want to get something out of the way: Making things appear when they are nearby the player is easy, you use a light and a shader. Making things disappear when they are nearby the player by that approach is impossible in 2D (3D has flags_use_shadow_to_opacity).
This is the plan: We are going to create a texture that will work as mask for what to show and what not to show. Then we will use that texture mask with a shader to make a material that selectively disappears. To create that texture, we are going to use a Viewport, so we can get a ViewportTexture from it.
The Viewport setup is like this:
Viewport
├ ColorRect
└ Sprite
Set the Viewport with the following properties:
Size: give it the window size (the default is 1024 by 600)
Hdr: disable
Disable 3D: enable
Usage: 2D
Update mode: Always
For the Sprite you want a grayscale texture, perhaps with transparency. It will be the shape you want to reveal around the player.
And for the ColorRect you want to set the background color as either black or white. Whatever is the opposite of the color on the Sprite.
Next, you are going to attach a script to the Viewport. It has to deal with two concerns:
Move the Sprite to match the position of the player. That looks like this:
extends Viewport
export var target_path:NodePath
func _process(_delta:float) -> void:
var target := get_node_or_null(target_path) as Node2D
if target == null:
return
$Sprite.position = target.get_viewport().get_canvas_transform().origin
And you are going to set the target_path to reference the player avatar.
In this code target.get_viewport().get_canvas_transform().origin will give us the position of the target node (the player avatar) on the screen. And we are placing the Sprite to match.
Handle window resizes. That looks like this:
func _ready():
# warning-ignore:return_value_discarded
get_tree().get_root().connect("size_changed", self, "_on_size_changed")
func _on_size_changed():
size = get_tree().get_root().size
In this code we connect to the "size_changed" of the root Viewport (the one associated with the Window), and change the size of this Viewport to match.
The next thing is the shader. Go to your TileMap or whatever you want to make disappear and add a shader material. This is the code for it:
shader_type canvas_item;
uniform sampler2D mask;
void fragment()
{
COLOR.rgb = texture(TEXTURE, UV).rgb;
COLOR.a = texture(mask, SCREEN_UV).r;
}
As you can see, the first line will be setting the red, green, and blue channels to match the texture the node already has. But the alpha channel will be set to one of the channels (the red one in this case) of the mask texture.
Note: The above code will make whatever is in the black parts fully invisible, and whatever is in the white parts fully visible. If you want to invert that, change COLOR.a = texture(mask, SCREEN_UV).r; to COLOR.a = 1.0 - texture(mask, SCREEN_UV).r;.
We, of course, need to set that mask texture. After you set that code, there should be a shader param under the shader material called "Mask", set it to a new ViewportTexture and set the Viewport to the one we set before.
And we are done.
I tested this with this texture from publicdomainvectors.org:
Plus some tiles from Kenney. They are all, of course, under public domain.
This is how it looks like:
Experiment with different textures for different results. Also, you can add a shader to the Sprite for extra effect. For example add some ripples, by giving a shader material to the Sprite with code like this one:
shader_type canvas_item;
void fragment()
{
float width = SCREEN_PIXEL_SIZE.x * 16.0;
COLOR = texture(TEXTURE, vec2(UV.x + sin(UV.y * 32.0 + TIME * 2.0) * width, UV.y));
}
So you get this result:
There is an instant when the above animation stutters. That is because I didn't cut the loop perfectly. Not an issue in game. Also the animation has much less frames per second than the game would.
Addendum A couple things I want to add:
You can create a texture by other means. I have a couple other answer where I cover some of it
How can I bake 2D sprites in Godot at runtime? where we use blit_rect. You might also be interested in blit_rect_mask.
Godot repeating breaks script where we are using lockbits.
I wrote a shader that outputs on the alpha channel here. Other options include:
Using BackBufferCopy.
To discard fragments.

How to draw pixels for ray-tracing in C++?

I'm currently trying to learn ray-tracing in C++. I am getting help from two books: one is Ray Tracing from the Ground Up by Kevin Suffern, and the other one is Physically Based Rendering by Matt Pharr. These two books are great for learning basics and, later, advanced stuff.
I could create some basic shapes using user interface of Suffern's book. However when I tried to write all code on my own, things have gone wild. I realized that I don't even know how to open a window and fill pixels on that. Do you have any good resource to recommend that could teach me the basics of drawing in C++.
You could generate image files instead of drawing to windows. The PPM format is the simplest one to generate. Browsers usually can display PPM. Safari does.
If you want to generate PNG files use libpng.
SDL might work for you: http://www.libsdl.org/
You can allocate your own image buffer, write your pixels to it, and then save to file/draw to window as needed. I expect the Pharr book has its own version of this tucked away somewhere, courtesy of Literate Programming.
More concretely: GUI API's and image file format libraries will typically be able to read simple image buffer data, stored in row-major array order. I would recommend an RGBA pixel format, something like the following:
template<class T> class image_rgba {
unsigned m_rows, m_cols;
T *m_data;
public:
image_rgba(unsigned rows, unsigned columns)
: m_rows(rows)
, m_cols(columns)
, m_data(new T[rows*columns*4])
{}
~image_rgba() { delete[] m_data; }
typedef T pixel[4];
pixel index_pixel_ref(unsigned row, unsigned col) {
assert(row<m_rows && col<m_cols);
return m_data + (m_cols*row+col)*4;
}
}
(note that I have not tested the above -- best to treat it as pseudocode...)

How to light-up a sprite in cocos2d?

I've already know how to dark-down a CCSprite object by:
sprite.color = ccc3(x, x, x); // x is a value less then 255
(As far as i know, it should be a direct mapping of openGL functions, so its easy to achieve.)
But when it comes to light-up, my current solution is adding another mask sprite (same shape but all in white), changing its blendFunc to { GL_SRC_ALPHA, GL_ONE } and overlaying it onto the target. Besides all the codes added, there should be a mask image for each need-to-light-up one.
Is there a way to do light-up as easily as dark-down?
However, not as easy as setColor, in Cocos2d 2.x, with OpenGL ES 2.0 support, you can achieve this by using custom shaders. You can get started here:
http://www.raywenderlich.com/10862/how-to-create-cool-effects-with-custom-shaders-in-opengl-es-2-0-and-cocos2d-2-x
You may also try inverting the sprite's darker color to get a lighter one.

How can I render mixed-colour text in DirectWrite?

I want to use DirectWrite for mixed-colour text formatting (syntax highlighting, to be precise), but can't seem to find a way to do it, either in the Layout or Typography options. The only option is passing a Brush when rendering the text, which doesn't work for me because I basically have just one Layout. Help!
Use IDWriteTextLayout::SetDrawingEffect to apply drawing effects on subranges. If you're using DWrite with D2D DrawTextLayout, which it sounds like you are, then that drawing effect would just be a brush (such as ID2D1Brush via CreateSolidColorBrush or one of the gradient brushes). If you have implemented your own IDWriteTextRenderer for IDWriteTextLayout::Draw, then the drawing effect can be whatever you interpret it to be. In the IDWriteTextRenderer::DrawGlyphRun callback, you then call QueryInterface on the drawingEffect parameter, or if you are certain it is your own type, just static_cast it directly.
// ... create the colored brushes and determine where to draw ...
wchar_t const* text = L"Red Green";
dwriteFactory->CreateTextLayout(....., OUT &textLayout);
DWRITE_TEXT_RANGE textRange1 = {0,3}, textRange2 = {4,5};
textLayout->SetDrawingEffect(redBrush, textRange1);
textLayout->SetDrawingEffect(greenBrush, textRange2);
renderer->DrawTextLayout(point, textLayout, defaultBrush);

Resources