Posted: 3rd Jul 2017 5:00
I have a question. I had a look at Blendman's awesome shaders for blending two textures onto the one object.
Can anyone help me to expand that to being able to blend a smaller texture onto a larger texture.
basically i just want to be able to blend a shadow onto a ground plane.
so i imagine it would be similar to the examples he has posted but with an offset and orientation.
any help would be greatly appreciated
thanks
Posted: 3rd Jul 2017 13:05
You need to add "uv1Varying = uv * uvBounds1.xy + uvBounds1.zw;"
Like so:

blend.vs
+ Code Snippet
attribute vec3 position;
attribute vec2 uv;
  
varying vec2 uv0Varying;
varying vec2 uv1Varying;

uniform vec4 uvBounds0;
uniform vec4 uvBounds1;
 
uniform mat4 agk_World;
uniform mat4 agk_ViewProj;
 
void main()
{
	vec4 pos = agk_World * vec4(position,1);
	gl_Position = agk_ViewProj * pos;
	uv0Varying = uv * uvBounds0.xy + uvBounds0.zw;
	uv1Varying = uv * uvBounds1.xy + uvBounds1.zw;
}

blend.ps
+ Code Snippet
// constant values sent through from AGK code.
uniform sampler2D texture0; 
uniform sampler2D texture1; 
 
// Anything that the vertex shader passes as output needs to 
// be defined here as input. The vertex shader is passing the 
// texture coordinate, so it is defined again here.
varying vec2 uv0Varying;
varying vec2 uv1Varying;
 
void main()
{
	vec4 colorResult0  = texture2D(texture0, uv0Varying);
	vec4 colorResult1  = texture2D(texture1, uv1Varying); // you can change here the second uvlayer by texture2D(texture1, texCoord1) if you use different uvchanel for each texture

	gl_FragColor = mix(colorResult0, colorResult1, colorResult1.a); // mix with the alpha of the second texture. You can mix with a third texture if you want to use seamless texture and repeat it.
}

AGK Code (play with uvscale and uvoffset in stage 1)
+ Code Snippet
// create a sphere to see the texture
CreateObjectBox(1,20,20,20)
 
// position and orientate the camera
SetCameraPosition(1,0,100,-200)
SetCameraLookAt(1,0,0,0,0)
SetGenerateMipmaps(1)
 
LoadImage(1,"texture0.jpg") // no need for alpha with this one
LoadImage(2,"texture1.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)
LoadShader(3, "blend.vs", "blend.ps")
SetObjectShader(1,3)
SetObjectImage(1,1,0)
SetObjectImage(1,2,1)
SetObjectUVScale(1,1,2.0,2.0)
SetObjectUVOffset(1,1,-0.25,-0.25)
 
do
     
    angle_x# = angle_x# + 1 
    SetObjectRotation(1,0, angle_x#,0.0)
    sync()
 
loop
Posted: 4th Jul 2017 1:03
That's fantastic janbo, thanks heaps.
That solves the position issue but how would i rotate the shadow texture?

ps: i'm not sure this is the right approach as it will limit the shadows to 8 objects. i'm wondering if i can pass the bounding points of my objects (they will always be rectangular) and the shader could just darken those areas?
Posted: 4th Jul 2017 13:58
Well, a real shadow shader or projected decals could be the way to go
We have had that 8 shadow limit also with lights and other stuff in the game industry... they only showed the nearest lights ...so you could do the same for shadows I guess... but I don't know your game.
With deferred rendering we don't have this problem
blend.vs
+ Code Snippet
attribute vec3 position;
attribute vec2 uv;
  
varying vec2 uv0Varying;
varying vec2 uv1Varying;

uniform vec4 uvBounds0;
uniform vec4 uvBounds1;
uniform float uvAngle;
 
uniform mat4 agk_World;
uniform mat4 agk_ViewProj;
 
void main()
{
	vec4 pos = agk_World * vec4(position,1);
	gl_Position = agk_ViewProj * pos;
	uv0Varying = uv * uvBounds0.xy + uvBounds0.zw;
	
	vec2 uvRotate = uv * uvBounds1.xy + uvBounds1.zw;
	float sinAngle = sin(uvAngle);
	float cosAngle = cos(uvAngle);
	uvRotate = (uvRotate - 0.5) * mat2(cosAngle, sinAngle, -sinAngle, cosAngle);
	uvRotate += 0.5;
	uv1Varying = uvRotate;
}
Posted: 4th Jul 2017 23:30
Thanks janbo. That helps a lot
Posted: 6th Jul 2017 17:04
As I plan to make a 3D Shader Pack, what would you like me to add to the shader pack.
I have these Shaders ready but have to wrap them in to some nice functions and test if they interference with the other Shaders
?Updated Water Shader
?Normalmapping Shader
?Shield Shader
?See Through Shader
?Outline Shader
?Fur Shader

I like this cuddly bundle of fluff (the hair moves if you move the fluffy ball)
I imagine it with big eyes and little stick legs.. so cute

Those shaders are forward rendering only, for now
I don't work on my shadow shader as Paul will add shadows to AGK

I looked into normal mapping and lighting for deferred rendering(have a little test project which looks right but it is not )
I looked into screen space ambient occlusion and screen space decals... I might add this to the pack if I get deferred rendering working
Posted: 6th Jul 2017 21:21
PBR Shaders ? :p

Thanks a lot for your work, instabuy when it come out !
Posted: 6th Jul 2017 22:17
PBR Shaders ?

Well I could add a Specularmap, Roughnessmap and Ambientocclusionmap to the Normalmapping one...I think thats all you gonna need for PBR...
I have a little problem there, as we have limited amount of textures, and if I add the agk shadows later or matalicness I want to reflect the cubemap on the surface...for now we have to pass a texture for each side of the cubemap...
Hm...Or we compress it into hemispheres and pass 2 textures... then I would have PBR in forward rendering with one spare texture to mask something for example
I'll look into it
Diffuse/Albedo
Normal
Specular/Metalicness
Roughness
Ambientocclusion
And the two Dual-Paraboloid ones

That gonna be no mobile games you make with this shader
Posted: 7th Jul 2017 5:14
I'll be your first customer!
As a hobbyist programmer, shadows, normal maps, water, outline shaders are OK
A glowing effect on individual objects will be a good addition for me
Posted: 7th Jul 2017 13:45
Is single Glowmap ok ?
Or do I have to create every single combination of shader myself ? should I make it Glow+Normalmapping ?
You can achieve the glowing effect with the bloom shader from the examples, but I will make the little masking part of the glow map for you.
I forgot about my Dissolve shader I'll add it to the Pack too

(The effect is not not perfect jet)
It gets the diffuse texture a color ramp and the NoiseMask
Posted: 7th Jul 2017 16:14
Could you please describe the difference between the single glow map and the combination (with normal map)?
Posted: 7th Jul 2017 17:55
Aw... I wrote a very long text to explain you why I don't want to end up writing 49 different shaders if I combine every shader I have now, but I accidentally reloaded the page
So there is no easy way to combine shaders except of some genius shader code generation I don't know of and a mix of deferred and forward rendering which only saves you from writing the PBR code again.
You know Normalmapping and you know Glowmaps and you don't want to write one big shader which includes every single effect because glsl isn't good in branching and hardcoding is still the fastest method...
So you have to make a combination manually if you need it in you scene.

I better aim for easy access and understanding then writing every combination I can imagine.
Thats all, it's just combining them

Actually I don't care too much about writing all shader combination than the AppGameKit part behind it... but I'm not at that point(maybe it's easy)

Have the diffuse,normal and specular part of the PBR shader
Posted: 7th Jul 2017 18:17
Looking fantastic so far. Any idea you have in mind for when this will be released? Do you think it might be ready by August or are you thinking more towards end of the year?
Posted: 7th Jul 2017 18:54
As I know me... its like more[s] towards end of the year[/s].
I try to aim shorter

[Edit] I would like to know what exactly is inside "mediump vec3 GetVSLighting( mediump vec3 normal, highp vec3 pos );" anybody have an Idea how I get at it ? [/Edit]
Posted: 10th Jul 2017 17:49
Having PBR working for PC :
The Floor is PBR(using Diffuse,Normal,Metal,Roughness and AO) and the right sphere is Normal+Specularmapping: See Attachments

But I will not investigate in a PBR shader or shadow shader anymore as TGC have plans to provide their own.
I already wrapped most of the functions for the other shaders of ASK(AppShaderKit)...progress is faster than I thought.
Posted: 10th Jul 2017 21:02
So beautiful ! Thanks janbo !

Good news to hear that TGC have plans to provide it !!
Posted: 10th Jul 2017 22:54
Is there a shader that supports transparency in textures?
Posted: 11th Jul 2017 12:54
If you use SetObjectTransparency(ObjectID,1) AppGameKit will generate one for you so, yes there is...
Or I misunderstood you !?
Posted: 14th Jul 2017 0:12
Great work Janbo - I would be happy to support your shader pack.
Posted: 14th Jul 2017 1:43
r I misunderstood you !?


I would like the "white" area at the base of that tree to be transparent (It is transparent in the texture sheet for the model). I tried setobjecttransparent() but i got the results shown.