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

Small request for help - lightmapper in Qt #9

Closed
ppiecuch opened this issue Jul 7, 2017 · 3 comments
Closed

Small request for help - lightmapper in Qt #9

ppiecuch opened this issue Jul 7, 2017 · 3 comments
Assignees

Comments

@ppiecuch
Copy link

ppiecuch commented Jul 7, 2017

Small request for help ... :)

I am trying to port/run lightmapper in Qt with OpenGL2. It started to work but results are broken - maybe you could point me where to start with this problem - what could cause these artifacts?

Thank you in advance
Pawel

Results:

result
debug_interpolation

and shaders:

// hemisphere shader (weighted downsampling of the 3x1 hemisphere layout to a 0.5x0.5 square)
{
	const char *vs =
		"#version 120\n"

        "#extension GL_EXT_gpu_shader4 : require\n"

		"const vec2 ps[4] = vec2[](vec2(1, -1), vec2(1, 1), vec2(-1, -1), vec2(-1, 1));\n"
		"void main()\n"
		"{\n"
			"gl_Position = vec4(ps[gl_VertexID], 0, 1);\n"
		"}\n";
	const char *fs =
		"#version 120\n"

        "#extension GL_EXT_gpu_shader4 : require\n"

        "uniform sampler2D hemispheres;\n"
		"uniform sampler2D weights;\n"
		"uniform ivec2 weightsTextureSize;\n"

        **"vec4 texelFetch(sampler2D tex, ivec2 size, ivec2 coord)\n"
        "{\n"
        "    vec2 fCoord = vec2((2.0*coord.x + 1.0)/(2.0*float(size.x)),(2.0*coord.y + 1.0)/(2.0*float(size.y)));\n"
        "    return texture2D(tex, fCoord);\n"
        "}\n"**

        "vec4 weightedSample(ivec2 h_uv, ivec2 w_uv, ivec2 quadrant)\n"
		"{\n"
			"vec4 sample = texelFetch(hemispheres, h_uv + quadrant, ivec2(0));\n"
			"vec2 weight = texelFetch(weights, w_uv + quadrant, ivec2(0)).rg;\n"
			"return vec4(sample.rgb * weight.r, sample.a * weight.g);\n"
		"}\n"

		"vec4 threeWeightedSamples(ivec2 h_uv, ivec2 w_uv, ivec2 offset)\n"
		"{\n" // horizontal triple sum
			"vec4 sum = weightedSample(h_uv, w_uv, offset);\n"
			"offset.x += 2;\n"
			"sum += weightedSample(h_uv, w_uv, offset);\n"
			"offset.x += 2;\n"
			"sum += weightedSample(h_uv, w_uv, offset);\n"
			"return sum;\n"
		"}\n"

		"void main()\n"
		"{\n" // this is a weighted sum downsampling pass (alpha component contains the weighted valid sample count)
			"vec2 in_uv = (gl_FragCoord.xy - vec2(0.5)) * vec2(6.0, 2.0) + vec2(0.01);\n"
			"ivec2 h_uv = ivec2(in_uv);\n"
			"ivec2 w_uv = ivec2(mod(in_uv, vec2(weightsTextureSize)));\n" // there's no integer modulo :(
			"vec4 lb = threeWeightedSamples(h_uv, w_uv, ivec2(0, 0));\n"
			"vec4 rb = threeWeightedSamples(h_uv, w_uv, ivec2(1, 0));\n"
			"vec4 lt = threeWeightedSamples(h_uv, w_uv, ivec2(0, 1));\n"
			"vec4 rt = threeWeightedSamples(h_uv, w_uv, ivec2(1, 1));\n"
			"gl_FragColor = lb + rb + lt + rt;\n"
		"}\n";
@ppiecuch
Copy link
Author

ppiecuch commented Jul 7, 2017

Sorry for the noise, seems like I missed quite a few pieces about texelFetch implementation. Look like it works now.

@ands
Copy link
Owner

ands commented Jul 7, 2017

Hey. :)
Sorry if I ask, but what is the reason for using OpenGL2?
So... did you get it running/can this be closed now?

@ands ands self-assigned this Jul 7, 2017
@ppiecuch
Copy link
Author

ppiecuch commented Jul 8, 2017

Hello, yes it works now. It is just easier to integrated the code with rest of the Qt, that is OGL2 based.
Pawel

@ands ands closed this as completed Jul 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants