Gamestudio Links
Zorro Links
Newest Posts
Lapsa's very own thread
by Lapsa. 06/26/24 12:45
Executing Trades on Next Bar Open
by Zheka. 06/20/24 14:26
A simple game ...
by VoroneTZ. 06/18/24 10:50
Face player all the time ...
by bbn1982. 06/18/24 10:25
Zorro Beta 2.61: PyTorch
by jcl. 06/10/24 14:42
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, Lapsa), 1,331 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
Mino, squik, AemStones, LucasJoshua, Baklazhan
19061 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 4 of 4 1 2 3 4
Re: 8 BIT SHOOTER [Re: 3run] #460228
06/20/16 14:41
06/20/16 14:41
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
here's an example object shader, I've marked the important parts with ***
Code:
//==========

#define ANGLE_SURFACE_DARKEN 0.75 // *** strength of the darkening effect; range [0 - 1]

//==========

const float     fAmbient; // used as per-entity brightness factor here

const float4    vecViewPos;

const float4x4  matWorld;
const float4x4  matViewProj;

//==========

const texture entSkin1;
sampler2D smpTex = sampler_state
{
	Texture = <entSkin1>;
	
	MipFilter = Linear;
	MagFilter = Point;
	MinFilter = Point;
	
	AddressU = Wrap;
	AddressV = Wrap;
};

//==========

struct VertexShaderInput
{
	float4 Position : POSITION0;
	float2 Tex : TEXCOORD0;
	float3 Normal : NORMAL; // *** contains the object space normals of the block
};

struct VertexShaderOutput
{
	float4 Position : POSITION0;
	float2 Tex : TEXCOORD0;
	float3 Light : TEXCOORD1; // *** used to store the calculated light value for the object
};

//==========

VertexShaderOutput VShader(VertexShaderInput input)
{
	VertexShaderOutput output;
	
	//
	
	float4 vWorldPos = mul(input.Position, matWorld); // transform the coordinates in two steps (matWorld & matViewProj instead of matWorldViewProj) because the world position is needed
	output.Position = mul(vWorldPos, matViewProj); // transform to the final screen-space coordinates
	
	output.Tex = input.Tex; // pass the texture coordinates
	
	float3 vPixelToViewDir = normalize(vecViewPos.xyz - vWorldPos.xyz); // *** direction vector from the surface to the camera
	
	float3 vNormal = normalize(mul(float4(input.Normal, 0), matWorld).xyz); // *** transform surface normal from object space to world space
	
	float dot_result = dot(vPixelToViewDir, vNormal); // *** get the angle ( cos(angle) ) between these vectors; both vectors in the dot product have to be normalized (length = 1)
	
	output.Light = fAmbient.xxx; // *** light (= entity brightness) is defined by ent->ambient
	output.Light *= saturate(1.0 - (1.0 - dot_result) * ANGLE_SURFACE_DARKEN); // *** apply the darkening factor with adjustable intensity; saturate() to prevent negative numbers (and numbers > 1)
	
	//
	
	return output;
}

//==========

float4 PShader(VertexShaderOutput In) : COLOR0
{
	float4 Color = tex2D(smpTex, In.Tex);
	
	Color.rgb *= In.Light; // *** simply apply the Light value recieved from the vertex shader to the texture
	
	return Color;
}

//==========

technique Tech_PP
{
	pass Pass_1
	{
		Lighting = False;
		
		AlphaBlendEnable = False;
		AlphaTestEnable = True;
		
		VertexShader = compile vs_3_0 VShader();
		PixelShader = compile ps_3_0 PShader();
	}
}

if you're already using an object shader for your level it shouldn't be too hard to implement it.

I've put the light-calculation in the vertexshader for performance reasons. It wouldn't be that much slower when it's in the pixel shader but there are way fewer vertices than pixels in your scene so it's a free preformance boost laugh

edit: it doesn't use fog though. if you're using the default shader, fog still needs to be implemented.

Last edited by Kartoffel; 06/20/16 14:55.

POTATO-MAN saves the day! - Random
Re: 8 BIT SHOOTER [Re: Kartoffel] #460229
06/20/16 14:55
06/20/16 14:55
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
I'm getting some weird results, tried to integrate your code with no luck yet grin


Edit: @Kartoffel, can I PM you about this shader thing? Won't that be too much for me to ask?


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: 8 BIT SHOOTER [Re: 3run] #460230
06/20/16 14:55
06/20/16 14:55

M
Malice
Unregistered
Malice
Unregistered
M



Quote:
I didn't get this one to be honest. Maybe you meant something like 'bumpmapping' to 'faux it's shape', or what?


Not really,Bump-mapping is to change normals to cause a 3d distortion. I'm talking about more like per-frame shadow mapping. Right now the whole sprite gets a uniformed shadow. A flat shadow across the flat surface. Which just adjust the surface color by a gray-scale(or color-scale). But the shadow can make the shape pop up if using a map.

Pictures - QaD for example
From top left - Hand and Gun - Shadow map - Shadow mapped hand 100% -Shadowmapped 50%

Hand and Gun
http://i.imgur.com/AmYh425.png
Shadow map
http://i.imgur.com/2AYDYAv.png
Shadow mapped hand 100%
http://i.imgur.com/F4tt9KM.png
Shadowmapped 50%
http://i.imgur.com/Sx5eilJ.png

So you can get d-shadows with intensity by light distance and using 4 mapping per -frame you could lerp/blend (whatever) by light-source direction.

So the shadow will faux the shaped of the sprite object.
Anyway just an idea and post just for clarification sake.

Great work man !

Last edited by Malice; 06/20/16 14:57.
Re: 8 BIT SHOOTER [Re: ] #460231
06/20/16 14:57
06/20/16 14:57
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Originally Posted By: Malice
Quote:
I didn't get this one to be honest. Maybe you meant something like 'bumpmapping' to 'faux it's shape', or what?


Not really,Bump-mapping is to change normals to cause a 3d distortion. I'm talking about more like per-frame shadow mapping. Right now the whole sprite gets a uniformed shadow. A flat shadow across the flat surface. Which just adjust the surface color by a gray-scale(or color-scale). But the shadow can make the shape pop up it using a map.

Pictures - QaD for example
From top left - Hand and Gun - Shadow map - Shadow mapped hand 100% -Shadowmapped 50%

Hand and Gun
http://i.imgur.com/AmYh425.png
Shadow map
http://i.imgur.com/2AYDYAv.png
Shadow mapped hand 100%
http://i.imgur.com/F4tt9KM.png
Shadowmapped 50%
http://i.imgur.com/Sx5eilJ.png

So you can get d-shadows with intensity by light distance and using 4 mapping per -frame you could lerp/blend (whatever) by light-source direction.

So the shadow will faux the shaped of the sprite object.
Anyway just an idea and post just for clarification sake.

Great work man !
This looks sweet. I got the idea now, but I guess I'm not going to implement this one, cause it's going to be out of place (to my taste), but it looks like a nice idea to make sprites less 'flat'. Thank you for kind words, your time and the idea man!

My best regards!


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: 8 BIT SHOOTER [Re: ] #460232
06/20/16 14:59
06/20/16 14:59
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
@3run: frown if you'd like, I could take a look at the object shader. you can also pm me if you don't want to post the code here.

@Malice: It's a cool effect, but it would require some kind of dynamic lighting which makes things a lot more complicated :S


POTATO-MAN saves the day! - Random
Re: 8 BIT SHOOTER [Re: Kartoffel] #460241
06/20/16 20:11
06/20/16 20:11

M
Malice
Unregistered
Malice
Unregistered
M



@Kartoffel if you wanted to blend sprite_s_maps to do dynamic shading yes you'd need d-light to get a source direction. But using one sprite_s_map like the example above , you can just read the value of the level shadow map under the entity and use it as the blend factor for sprite and it's sprite_s_Map.

Last edited by Malice; 06/20/16 20:12.
Page 4 of 4 1 2 3 4

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1