Posted: 24th Sep 2016 14:18
@MadBit & @janbo : Thanks for your help ... I will try I have time to learn some thing new
Posted: 29th Sep 2016 11:12
@Harlequin thanks for "#version 120"
no it works on Intel HD 3000

@blendman thanks for your work on the normal-shader and thanks to Janbo
have to figure out, how to setup the lights to get more than only a black object

@OminusPrime, did you tried also some of the "FX"-Shaders from FPSC Classic?

Thanks to all of you for your work
Posted: 4th Oct 2016 12:55
Scanline effect fullscreen shader I just made for someone on the newcomer forum. Pixelshader (save as "scanline.ps" in your media folder):
+ Code Snippet
#ifdef GL_ES
	#ifdef GL_FRAGMENT_PRECISION_HIGH   
		precision highp float;
	#else
		precision mediump float;
	#endif
#endif

uniform sampler2D texture0;
varying vec2 uvVarying;

uniform vec2 screenSize;
uniform float noise;

float rand(vec2 n)
{
  return 0.5 + 0.5 * 
     fract(sin(dot(n.xy, vec2(12.9898, 78.233)))* 43758.5453);
}

void main()
{
	float y = floor(uvVarying.y * screenSize.y);
	float ran = (rand(uvVarying.xy) - 1.0) * 0.5;
	if (noise < 0.1)
	{
		ran = 0.0;
	}
	float delta = mod(y, 4.0) * 0.5;
	gl_FragColor = texture2D(texture0, uvVarying.xy) * (delta + ran);
}


...and below is an example project:
+ Code Snippet
// Project: scanline 
// Created: 2016-10-04

// show all errors
SetErrorMode(2)

// set display properties
SetWindowTitle( "scanline" )
SetWindowSize( 1024, 768, 0 )
SetVirtualResolution( 1024, 768 )
SetSyncRate( 60, 0 )
SetPrintSize(16)

// load media
img = LoadImage("scanline.png")

// load shader
shader = LoadFullScreenShader("scanline.ps")
SetShaderConstantByName(shader, "screenSize", 1024, 768, 0, 0)
// set 1 to 0 to remove noise
SetShaderConstantByName(shader, "noise", 1, 0, 0, 0)

// create quad object
renderImage = CreateRenderImage(1024, 768, 0, 0)
quad = CreateObjectQuad()
SetObjectShader(quad, shader)

// create sprite
SetImageMagFilter(img, 0)
spr = CreateSprite(img)
SetSpriteScale(spr, 2, 2)
SetSpritePositionByOffset(spr, 512, 384)

do
    
    // do actions on mouse button pressed
    // reset state
	MODE = 0
	change = 0
	
	// set state based on mouse pressed
    if GetPointerState()>0
		if MODE=0 then change = 1
		MODE = 1
	else
		if MODE=1 then change = 2
		MODE = 0
	endif
	
	// set shader visible as needed
	select change
		case 1
			SetObjectShader(quad, shader)
		endcase
		case 2
			SetObjectShader(quad, 0)
		endcase
	endselect
	
	select MODE
		case 0
			Print("Press mouse button to see shader")
			Sync()
		endcase
		case 1
			// render to the render image
			SetRenderToImage(renderImage, -1)
			ClearScreen()
			Update(GetFrameTime())
			print("Showing shader")
			Render2DBack()
			Render2DFront()
			SetObjectImage(quad, renderImage, 0)
			
			// render to the screen
			SetRenderToScreen()
			ClearScreen()
			DrawObject(quad)
			Swap()
		endcase
	endselect
loop


... and this is the effect:
Posted: 6th Oct 2016 10:58
@baxslash the pixel shader looks awesome!
Posted: 10th Oct 2016 5:10
Thanks, Baxslash...

One question for the scanline effect, can it be use to achieve this effect also? i mean by changing the scanline texture to diagnol pencil sketch texture?( im on travel cant try)

As in https://www.youtube.com/watch?v=5aKMdsxV0fU,

Im really like NPR games
Posted: 11th Oct 2016 14:06
That's a very different shader I'm afraid. Edge detection for a start.
Posted: 23rd Oct 2016 14:58
Ok,baxslash...thanks for the scanline shader

BTW, anybody got any shader for black outline of 3d mesh? i know its normally come with toon shader, but im doing 3d model with pixel art texture(almost altho not perfect) and black outline for mesh and scanline effect(cough) will make it look better


Thanks
Posted: 23rd Oct 2016 23:29
@madbit: I have been playing with your normal/specular shader, but it breaks if I switch fog on in AGK. I would want to fog / drop off the lighting on the shader with distance but at the moment I would have to calculate distance to object from camera in AppGameKit code and update the diffuse colour via the shader parameters.
How can the shader be altered to have light strength fall off or work with AppGameKit fog settings?
Posted: 28th Oct 2016 9:34
Sorry for the late answer.

The automatic code generator from agk does not to check if certain variables (agk_CameraPos) are already set or not. Either Paul changes it so that the code generation is searched for already set variables. Or you give the schader the Camera position in its own uniform variable and change the code accordingly. Or you can of course also write your own Fog function. I suggest you read this page (http://in2gpu.com/2014/07/22/create-fog-shader/).
Posted: 29th Oct 2016 16:48
Hi Blendman,

I am trying to do something with your mix 2 texture with alpha mask.

I wanted to be able to UVOffset the alpha mask, but it appears to be locked in place by the shader. I can offset texture0 but both the other textures also offset when I do this.

I have tried a few things, but I can't figure out how to separate them.
Posted: 29th Oct 2016 16:49
Thanks MadBit. I think that is still beyond me at the moment. I am still figuring out some basics at the moment!
Posted: 30th Oct 2016 0:17
Actually Blendman, I managed to get the UV of the texture 2 moving. I see another problem now which requires me to be able to rotate the UV of texture 2 independently on X and Z axis, which seems to be a much more complex issue.
I would guess that it may not even be possible?
Posted: 1st Nov 2016 13:29
I would like to create a Cubemapping shader for reflection/refraction.
Now it seems that there is no way to bind 6 textures as a Cubemap to an Object.
Beware that I can't just manipulate the UV coordinates of the Object/Skybox.

Can someone confirm that ?
Posted: 9th Nov 2016 4:09
@ MadBit
I can't get the normal mapping shader running on mobile devices, are there any limitations? When my scene contains more than 3 lights, which lights will be passed to the shader? The first declared, or the nearest lights to the camera?

@jambo
I've attached you one. Just create a box, apply 6 textures to the 6 stages of the object and apply the shader to it.
Posted: 9th Nov 2016 20:25
I forgot that I even helped on one
Cube Mapping Problem Tier 1

Thanks anyway
Posted: 10th Nov 2016 9:52
@Jack:
I can't get the normal mapping shader running on mobile devices, are there any limitations?

This has already been answered here.

When my scene contains more than 3 lights, which lights will be passed to the shader? The first declared, or the nearest lights to the camera?

This question can only be answered by Paul. The shader uses the light sources passed by AGK.
Posted: 9th Feb 2017 11:41
I have a small addition to Janbos excellent [2D] Normal map code from page 1. This adds the alpha channel to the normal map (I changed only the last line of the .ps file).
Be sure to change SetSpriteTransparency on your sprite to 1 to enable alpha in AppGameKit, and change the arguments in Norm2D_Init() from integers to floats

AGK code:
+ Code Snippet
function Norm2D_Init(AmbientRed#,AmbientGreen#,AmbientBlue#)
	global Norm2D_Light as NORM2D_LIGHTDATA[]
	
	global Norm2D_ShaderID
	Norm2D_ShaderID=LoadSpriteShader("Normalmapping2DAlpha.ps")
	SetShaderConstantByName(Norm2D_ShaderID,"AmbientColor",AmbientRed#/255, AmbientGreen#/255, AmbientBlue#/255, 0)
	SetShaderConstantByName(Norm2D_ShaderID,"Falloff", 0.1,0.01,0.001,0.0)
endfunction




Shader code:
+ Code Snippet
uniform sampler2D texture0;
uniform sampler2D texture1;
varying vec2 uvVarying;

uniform vec2 agk_resolution;
uniform vec4 AmbientColor;
uniform vec3 Falloff;

uniform float LightCount;
uniform vec3 LightPosition[8];
uniform vec4 LightColor[8];

vec3 light(vec3 LightPos, vec4 LightColor)
{
	LightPos.y = agk_resolution.y - LightPos.y;
	
	vec3 normal = texture2D(texture1, uvVarying.xy).rgb;
	
    vec3 LightDir = vec3(LightPos.xy - gl_FragCoord.xy, LightPos.z);
	
    vec3 LDIR=normalize(LightDir);
	
	normal = normal * 2.0 - 1.0;
	vec3 NDIR=normalize(normal);
	
	float dist = length(LightDir);
	float Attenuation = clamp((1.0 / (Falloff.x +(Falloff.y * dist) +(Falloff.z * dist * dist))) * LightColor.w,0.0,1.0);
	
	return LightColor.rgb * max(dot(NDIR, LDIR), 0.0) * Attenuation;
}

void main()
{
	
    vec4 diffuse = texture2D(texture0, uvVarying.xy);
	vec3 Light;
	for(int i=0; i < int(LightCount); i++)
	{
		Light = Light + light(LightPosition[i], LightColor[i]);
	}

	//gl_FragColor = diffuse * (AmbientColor + vec4(Light,0.0));  // previous fragcolor - no alpha
	gl_FragColor = (AmbientColor + diffuse) * vec4(diffuse.rgb * AmbientColor, diffuse.a) + vec4(Light,0.0) * diffuse.rgb; // new fragcolor with alpha. SetSpriteTransparency(SpriteID, 1) in your agk code
}


I'm sure someone can optimise it.
Posted: 10th Feb 2017 21:18
Hi all,

I've been working on a simple tiltshift shader for 2D projects.

here's a screenie of it in action:



It uses the two blur shaders in the AppGameKit shaders example, but slightly modifies them with a y-axis variable blur.

I also made a simple 3rd shader that combines the tilt-shifted image with any HUDs that you don't want blurred. The tier 1 code for the rendering would be like this:

+ Code Snippet
//update elements
	Update(0)
	
	//Create HUDs texture
	SetHUDsVisible( 1 )
	//SetMapVisible( 0 )
	//SetSpriteVisible( SptBackground, 0 )
	SetRenderToImage( ImgHUD, 0 )
	ClearScreen()
	Render()

	//Create MAP texture
	SetHUDsVisible( 0 )
	SetMapVisible( 1 )
	SetSpriteVisible( SptBackground, 1 )
	
	SetRenderToImage( ImgNoBlur, 0 )
	ClearScreen()
	Render()
	
	//apply blur
	SetMapVisible( 0 )
	SetSpriteVisible( SptBackground, 0 )
	
	SetObjectShader( ObjScreen, ShdVertBlur )
	SetRenderToImage( ImgVBlur, 0 )
	SetObjectImage( ObjScreen, ImgNoBlur, 0 )
	ClearScreen()
	DrawObject( ObjScreen )
	//Render()
	
	SetObjectShader( ObjScreen, ShdHorzBlur )
	SetRenderToImage( ImgTiltShift, 0 )
	SetObjectImage( ObjScreen, ImgVBlur, 0 )
	ClearScreen()
	DrawObject( ObjScreen )
	//Render()
	
	SetObjectShader( ObjScreen, ShdCombine )
	SetObjectImage( ObjScreen, ImgTiltShift, 0 )
	SetObjectImage( ObjScreen, ImgHUD, 1 )
	//SetHUDsVisible( 1 )
	SetRenderToScreen()
	ClearScreen()
	DrawObject( ObjScreen )
	//Render()
	
	//ClearScreen()
	
	//remend
	
	Swap()
	


Enjoy!
Posted: 12th Feb 2017 6:53
Ched80 it looks amazing
Posted: 12th Feb 2017 15:30
The normal map shader is great ! (thanks janbo and MadBit !)

Just 2 little bugs in the version provided by MadBit :
:
1. with animated models, when the normal shader is applied, animations no longer works
2. Fog activation make the shader to throw an error with the agk_CameraPos declaration (previously declared ? i don't see where)

some ideas ?

@Paul,
it seems that a SetObjectMeshShaderConstantByName() command is missing (or shader constants are global to the multi-meshes objects ? it should not due to the per-mesh SetObjectMeshShader() command