Posted: 22nd May 2017 12:00
ive changed the line
Quote: "WriteLine(file,"gl_FragColor = (texture2D(texture0, uvVarying) + texture2D(texture1, uvVarying))/2.0;")"

to
gl_FragColor = (texture2D(texture0, uvVarying) + (2.0*.5*texture2D(texture1, uvVarying)))/2.0;

where .5 is a percentage that seemed to work

the main problem I was having was setting the variable from the program but I fixed that thanks
with the following which converts one texture to another gradually on an object
+ Code Snippet
SetWindowSize( 1024, 768, 0 )
SetVirtualResolution( 1024, 768 )
// create a sphere to see the texture
CreateObjectSphere(1,20,40,60)
//CreateObjectplane(1,1024,768)

// position and orientate the camera
SetCameraPosition(1,0,100,-200)
SetCameraLookAt(1,0,0,0,0)
SetGenerateMipmaps(1)

LoadImage(1,"texture.jpg") // no need for alpha with this one
LoadImage(2,"texture2.png") // with alpha ;)

CreatePointLight(1,-5,5,5,500,200,200,200)

// initial rotation values
angle_x# = 0.0

// main loop
SetObjectRotation(1,-60,-60,0.0)
SetObjectScale(1,4,2,2)
createShader()
LoadShader(3, "vertex.vs", "fragment.ps")
SetObjectShader(1,3)
SetObjectImage(1,1,0)
SetObjectImage(1,2,1)

perc#=.1:time#=Timer()
do
	angle_x# = angle_x# + 1 
	SetShaderConstantByName(3,"Percentage",perc#,0.0,0.0,0.0)
	SetObjectRotation(1,0, angle_x#,0.0)
	if perc#<=1 and time#>.1 
		perc#=perc#+.01
		ResetTimer()
	endif
	SetSpriteImage(1,2)
	time#=Timer()
	sync()
loop

function createShader()
file = OpenToWrite("vertex.vs")
WriteLine(file,"attribute vec3 position;")
WriteLine(file,"attribute vec2 uv;")
WriteLine(file,"varying vec2 uvVarying;")
WriteLine(file,"uniform vec4 uvBounds0;")
WriteLine(file,"uniform mat4 agk_World;")
WriteLine(file,"uniform mat4 agk_ViewProj;")
WriteLine(file,"void main()")
WriteLine(file,"{")
WriteLine(file,"vec4 pos = agk_World * vec4(position,1);")
WriteLine(file,"gl_Position = agk_ViewProj * pos;")
WriteLine(file,"uvVarying = uv * uvBounds0.xy + uvBounds0.zw;")
WriteLine(file,"}")
CloseFile(file)

file = OpenToWrite("fragment.ps")
WriteLine(file,"uniform sampler2D texture0;")
WriteLine(file,"uniform sampler2D texture1;")
WriteLine(file,"uniform float Percentage;")
WriteLine(file,"varying vec2 uvVarying;")
WriteLine(file,"void main()")
WriteLine(file,"{")
WriteLine(file,"gl_FragColor = (texture2D(texture0, uvVarying) + (4.0*Percentage*texture2D(texture1, uvVarying)))/2.0;")
//WriteLine(file,"gl_FragColor = gl_FragColor+(10.0/1.0*texture2D(texture1, uvVarying));")
WriteLine(file,"}")
CloseFile(file)
endfunction
Posted: 22nd May 2017 12:42
Why I'm sure you don't need to multiply it by 2, then divide by 2 at the end?
+ Code Snippet
gl_FragColor = ( texture2D( texture0, uvVarying ) + ( .5 * texture2D( texture1, uvVarying ) ) )
Posted: 22nd May 2017 12:58
There is much going on with VR right now and I through I released my "Lens Correction shaders/Tiny VR Lib" month ago...I realized, I did not
So here it is:

Demo
You can use the magnet of the card board to switch the width of the lenses center.
VR Test v2

Image
Posted: 22nd May 2017 22:44
janbo

Thanks for your contribution. I have a question on your VR shader.
How would I adjust it so it would completely fill the screen top to bottom and left to right
in it's half of the screen?
Posted: 22nd May 2017 23:59
remove it ? :p
Posted: 23rd May 2017 0:34
I mean like this screen shot from Google cardboard app.
Posted: 23rd May 2017 1:25
This low lens correction is strange ... This headset has no lenses ? :p

for my FreeFly VR (which have the big FOV of 120?) i need this correction :

Posted: 23rd May 2017 16:03
Stab in the Dark software

I think it's a different technique they use...or the lens curvature is so small that you could ignore it ^^
I think they are doing the correction on vertex level.
It's faster because you don't have to process every pixel on screen like I do, even if you have to add some vertices's to your models to make a good illusion.
I think its on vertex level because if you hold an ruler at an edge of the hill model, you can see that it is straight... that's why you don't notice the lens correction.
So it's not a perfect solution like the per fragment one, but in some cases a much faster one...ofc. you need a game art that fits well to that kind dependence...
Mobile VR apps tend to make it kind of polygon style with only face colors and no textures and so on.

[Edit]
You could probably zoom out, apply the shader and then take a smaller area from the resulting render image which you then stretch to fit the borders.
You need to increase the resolution of the render image so it fits the device resolution after the procedure...
I only tested my lib on my Honor 8 with a cheap copy the of Google cardboard, but it works perfectly and I can't see the borders nor I get ill...
[Edit]
Posted: 24th May 2017 3:17
I changed this line in your shader to this value and just set the center to 0.0

+ Code Snippet
highp float alpha = 0.015; /* lens parameter */


It seems to be working well for my tzumi Dream Vision head set with my LG Stylo 3.
The screen resolution on the LG Stylo 3 is 1280 x 720.
Are the other shaders in your demo deprecated as part of the development process?
Posted: 24th May 2017 15:15
Well,
Now you have nearly no lens correction.
You could probably remove the shader...
I have read that the lens of your Dream Vision does have a focal length of 42mm and the Cardboard lenses have 45mm, so you should have a higher curvature...
You should increase the alpha variable instead.

Are the other shaders in your demo deprecated as part of the development process?

sort of ...you can probably make them all work again... as they was working once ...
Posted: 28th May 2017 22:06
ou should increase the alpha variable instead.


You are correct, I still need the barrel distortion to compensate for the lenses.
0.2 seems to be correct for my lenses. I found that if I change this line in the shader
it keeps the barrel distortion but creates a larger image to fill the screen so I can not see
the edges in the viewer. I changed the 1.0 - alpha to 1.18 - alpha. Do you think this is correct
or have I made a mistake again?

+ Code Snippet
	/* Transform */
	highp vec2 p2 = p1 / (1.18 - alpha * length(p1));
Posted: 29th May 2017 12:19
@Stab in the Dark software
No you are right that should work, but the center will get shifted and you might want to increase the render target size.
Actually its a pretty good finding

You can use the "BarrelDistortion#" value in the "VR_Init" function to increase the render target..just set it to 1.18 then
[Edit]I updated my demo above[/Edit]
Posted: 30th May 2017 13:00
Hey there, I just looked at this 2D Normal Map Shader:
https://forum.thegamecreators.com/thread/212611

But using the latest AGKv2 version it looks like:
Posted: 30th May 2017 16:39
@Xaron
Hm try this
Posted: 31st May 2017 7:30
Thanks, it has the same issue. Maybe it's because of my system then? I have quite an unusual graphics card, the NVidia Quadro K600.
Posted: 31st May 2017 12:18
Even if its an unusual graphics card, the Quadro series is for rendering heavy stuff and I doubt that NVIDIA didn't got it right.
If you are a bit familiar with glsl you could remove/shrink the shader to it's bare-bones step by step and see if it gets any better and where it fails.

You can even see the vertices of the sprite...very unusual stuff...maybe it's the card though
What happens if you have no lights ?
Posted: 31st May 2017 12:20
Yeah I will try to strip it down. I have a bit of shader knowledge so it should be possible. Let's see. I'll try it on my other PCs as well but I guess it's a problem with the specific one here.

edit: Will try with no lights...
edit2: That's without lights:
Posted: 31st May 2017 12:40
Ok fixed it. In your main shader there was the following:
+ Code Snippet
vec3 Light;
for(int i=0; i < int(LightCount); i++)
{
  Light = Light + light(LightPosition[i], LightColor[i]);
}


So you use a not initialized variable called Light. This might work on many platforms but obviously mine is NOT initialized correctly with 0,0,0. Doing that fixed it:
+ Code Snippet
vec3 Light = vec3( 0.0, 0.0, 0.0 );
for(int i=0; i < int(LightCount); i++)
{
  Light = Light + light(LightPosition[i], LightColor[i]);
}


Cheers!
Posted: 31st May 2017 12:59
@Xaron
Haha, I was about to say that you should try to initialize the Light variable, don't know why I did not
But I'm glad the problem is out of the way.
So why is it working for me...in other words: why is the Light variable zero and not pointing into nowhere ?
Posted: 31st May 2017 13:06
Well that's the "magic" of different compilers on different systems. You see even C++ does quite funny things with not initialized variables on some systems but not all of them. It's just not clearly defined so always dangerous.