Shade-C all in one FX

Posted By: DLively

Shade-C all in one FX - 04/15/14 08:01

Hi.

Shade-C asside, I am simply trying to use the all in one shader as a primitive step as I am having great difficulty setting up Normal Maps... Apparently.

The ambience works, but for some reason I get no normal maps.

----------------------------

Okay, So lets say I don't want to use shadows.. for now. All I need are the first 3 skins -> ColorMap, Specmap, Normalmap

in that order.

I create them with a software I downloaded, obviously dependent on the models colormap.

In a sorta related post, Rojart suggested turning the b and g channels black or white for the spec map? and apply them in the above order through the skin manager in MED. (Should I be properly naming them something?) after they are saved, I then apply this material to the model, build and run. I get a result as if nothing but an ambient shader has been applied to it. EDIT: and a bit of white specs from the spec_rgb

Code:
MATERIAL* allinone_mat = {
	ambient_red = 0;			   // The ambient color - a dark grey.
	ambient_green = 0;
	ambient_blue = 0;
	
	specular_red = 80;
	specular_green = 80;
	specular_blue = 80;
	
	diffuse_blue = 200;  
	diffuse_green = 202;  
	diffuse_red = 208;
	
	//emissive_blue = 200;  //'fog'
	//emissive_green = 200;  
	//emissive_red = 200;
	
	power = 500;
	
	flags = enable_render;  // for normal mapping
	effect = "sc_obj_aio.fx";
}



The sc_obj_aio.fx file
Click to reveal..

/******************************************************************************************************
"All-in-One" Shader by Wolfgang "BoH_Havoc" Reichardt

Entity Textures:
Skin1 = Colormap
Skin2 = Effectmask
Skin3 = Normalmap (RGB) + Luminancemask (A)
Skin4 = Shadowmap (uses 2nd UV-Map)

Effectmask.r = Specular Intensity
Effectmask.g = Environmentmapping Intensity
Effectmask.b = Velvety Intensity
Effectmask.a = TeamColor Alpha

Material Textures:
Skin1 = Environment Map

Usage:
Uncomment/Comment the #defines to add/remove an effect.
vecSkill1.x sets the diffuse shadow alpha (mtl.skill1)
vecSkill1.y sets the specular power (mtl.skill2)
vecSkill1.y sets the velvety power (mtl.skill3)
vecSkill5.xyz sets the teamcolor (mtl.skill5, mtl.skill6, mtl.skill7)
vecSkill9.xyz sets the luminance color (mtl.skill9, mtl.skill10, mtl.skill11)

******************************************************************************************************/

/***************************************TWEAKABLES*****************************************************/

// Default Values (will be used if vecSkill1, vecSkill5 or vecSkill9 hasn't been set):
float specularExp = 50; // vecSkill1.y | sharpness of the specular lighting
float velvStrength = 0.4; // vecSkill1.z | velvety Strength
float3 teamColor = {1.0f, 0.50f, 0.0f}; // vecSkill5.xyz | teamcolor
float3 lumColor = {1.2f, 1.8f, 5.2f}; // vecSkill9.xyz | color of the luminancemap
//

//misc
float shadowAlpha = 0.0; // range: 0-1 | 0 = pure black shadow | 1 = no shadow at all
float3 velvColor = {1.4f, 1.4f, 1.4f}; // velvety color
float bumpStrength = 2; // bumpmapping strength
//

//Luminance Map Animation
float texRotSpeed = 0; // Rotation Speed
float texXShiftSpeed = 0; // Shift Speed X
float texYShiftSpeed = 0; // Shift Speed Y
float RepeatS = 1.0; // tiling
float RepeatT = 1.0; // tiling
float Angle = 0.0; // pan at start
float OffsetS = 0.0; // offset at startup
float OffsetT = 0.0; // offset at startup
float RotCenterS = 0.5; // rotation center
float RotCenterT = 0.5; // rotation center
//

// UNCOMMENT/COMMENT TO ACTIVATE/DEACTIVATE

//Use Diffuse Lighting
#define DIFFLIGHT

//Use Shadowmap
//#define SHADOWMAPPING

//Use Specular Lighting
#define SPECLIGHT

//Use Environment Mapping
//#define ENVMAPPING

//Use Velvety Effect
//#define VELVETY

//Use Normalmapping
#define NORMALMAPPING

//Use Luminance Mapping
//#define LUMMAPPING

//Use Team Color
//#define TCOLOR

//Above Effects will react to sunlight (only needed if you have dynamic lights in your level)
//#define DOSUN

//Diffuse Lighting will react to 5 additional dynamic lights including the sun
#define DYNLIGHTS

//Use PixelShader 2.a | set this if you get an errormessage ("code uses too many many arithmetic instruction slots")
#define PS2A





/***************************************SHADER*CODE****************************************************/

// Matrices
float4x4 matWorldViewProj;
float4x4 matWorldInv;
float4x4 matViewInv;
float4x4 matWorld;

// Passed by the engine
float4 vecTime;
float4 vecFog;
float4 vecViewPos;
float4 vecViewDir;
float4 vecLight;
float4 vecSunPos;
float4 vecSunColor;
float4 vecLightPos[8];
float4 vecLightColor[8];
float4 vecSkill1;
float4 vecSkill5;
float4 vecSkill9;

//Textures
texture entSkin1; // Colormap
texture entSkin2; // Mask texture
texture entSkin3; // Normalmap
texture entSkin4; // Shadowmap
texture mtlSkin1; // Environment Map

// Color map sampler
sampler ColorMapSampler = sampler_state
{
Texture = <entSkin1>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
};

// Mask sampler
sampler MaskSampler = sampler_state
{
Texture = <entSkin2>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
};

//NormalMap
sampler NormalMapSampler = sampler_state
{
Texture = <entSkin3>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
};

//ShadowMap
sampler ShadowMapSampler = sampler_state
{
Texture = <entSkin4>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
};

// Environment map sampler
sampler EnvMapSampler = sampler_state
{
Texture = <mtlSkin1>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
};


// Vertex Shader
void DiffuseVS(
in float4 InPos: POSITION,
in float3 InNormal: NORMAL,
in float2 InTex: TEXCOORD0,
in float3 InTangent : TEXCOORD0,
in float2 InShadow : TEXCOORD1,
out float4 OutPos: POSITION,
out float4 OutTex: TEXCOORD0,
out float4 OutLight: TEXCOORD1,
out float3 OutViewDir: TEXCOORD2,
out float3 OutWorldNormal : TEXCOORD3,
out float3 OutWorldTangent : TEXCOORD4,
out float3 OutWorldBinorm : TEXCOORD5,
out float3 OutWorldPos : TEXCOORD6,
out float2 OutLumUV : TEXCOORD7,
out float OutFog : FOG)
{
// Transform the vertex from object space to clip space:
OutPos = mul(InPos, matWorldViewProj);
// Pass the texture coordinate to the pixel shader:
OutTex.xy = InTex;
// Pass the shadow coordinate to the pixel shader:
OutTex.zw = InShadow;

float3 PosWorld = mul(InPos, matWorld);

//Light
#ifdef DOSUN
OutLight.xyz = vecSunPos - PosWorld;;
OutLight.w = 100000;//distance(PosWorld,vecLightPos[0])/vecLightPos[0].w;
#else
OutLight.xyz = vecLightPos[0] - PosWorld;
OutLight.w = 0;
if(vecLightPos[0].w < 100000) OutLight.w = 1-distance(PosWorld,vecLightPos[0])/vecLightPos[0].w;
#endif
//

//Specular Lighting

/*
#ifdef DOSUN
OutViewDir = (vecSunPos) - mul(InPos, matWorld);
#else
OutViewDir = (vecLightPos[0]) - mul(InPos, matWorld);
#endif
*/

OutViewDir = matViewInv[3].xyz - PosWorld;
//

//Environment Mapping
float3 Binormal = cross(InNormal,InTangent);
OutWorldNormal.xyz = mul(InNormal, matWorld).xyz;
OutWorldTangent.xyz = mul(InTangent, matWorldInv).xyz;
OutWorldBinorm.xyz = mul(Binormal, matWorldInv).xyz;
OutWorldPos = PosWorld;
//

//Luminance Map Animation
float a = radians(Angle + (vecTime.w/2)*texRotSpeed);
float ca = cos(a);
float sa = sin(a);
float2 off = float2(RotCenterS,RotCenterT);
float2 nuv = InTex.xy - off;
float2 ruv = float2(nuv.x*ca-nuv.y*sa,nuv.x*sa+nuv.y*ca);
nuv = ruv + off;
OutLumUV = float2(max(0.001,RepeatS) * nuv.x + OffsetS + ((vecTime.w/200)*texXShiftSpeed),
max(0.001,RepeatT) * nuv.y + OffsetT + ((vecTime.w/200)*texYShiftSpeed));
//

//Fog
OutFog = 1 - (distance(PosWorld, vecViewPos) - vecFog.x) * (vecFog.z);
//
}

// Pixel Shader:
float4 DiffusePS(
in float4 InTex: TEXCOORD0,
in float4 InLight : TEXCOORD1,
in float4 InViewDir: TEXCOORD2,
in float3 InWorldNormal : TEXCOORD3,
in float3 InWorldTangent : TEXCOORD4,
in float3 InWorldBinorm : TEXCOORD5,
in float3 InWorldPos : TEXCOORD6,
in float2 InLumUV : TEXCOORD7
): COLOR
{
float3 Ln = normalize(InLight.xyz);
float3 Nn = normalize(InWorldNormal);
float3 Tn = normalize(InWorldTangent);
float3 Bn = normalize(InWorldBinorm);
float3 Nb = 0;
float3 Vn = 0;
float3 Hn = 0;
float4 lighting = 0;

//check if vecSkill1 has been set. If not, use default values
#ifdef DIFFLIGHT
if(vecSkill1.x == 0) vecSkill1.x = shadowAlpha;
#endif
#ifdef SPECLIGHT
if(vecSkill1.y == 0) vecSkill1.y = specularExp;
#endif
#ifdef VELVETY
if(vecSkill1.z == 0) vecSkill1.z = velvStrength;
#endif

#ifdef TCOLOR
//check if vecSkill9 has been set. If not, use default values
if(vecSkill5.x + vecSkill5.y + vecSkill5.z == 0) vecSkill5.xyz = teamColor;
#endif

#ifdef LUMMAPPING
//check if vecSkill5 has been set. If not, use default values
if(vecSkill9.x + vecSkill9.y + vecSkill9.z == 0) vecSkill9.xyz = lumColor;
#endif

//get color
float4 Color = tex2D(ColorMapSampler,InTex.xy);
//get effectmask
float4 Mask = tex2D(MaskSampler,InTex.xy);
//get luminancemap
float luminance = tex2D(NormalMapSampler,InTex.xy).a;

float3 Light1 = Color.xyz;



#ifdef TCOLOR
Light1 += Mask.a * vecSkill5.xyz;
Light1 = clamp(Light1,0,1);
#endif

float3 bumpNormal = 0;
#ifdef NORMALMAPPING
bumpNormal= bumpStrength * (tex2D(NormalMapSampler,InTex.xy).xyz-(0.5).xxx);
#endif

#ifdef DIFFLIGHT
Nb = Nn + (bumpNormal.x * Tn + bumpNormal.y * Bn);
Nb = normalize(Nb);
Vn = normalize(InViewDir);
Hn = normalize(Vn + Ln);
lighting = lit(dot(Ln,Nb),dot(Hn,Nb),vecSkill1.y);
#else
#ifdef SPECLIGHT
Nb = Nn + (bumpNormal.x * Tn + bumpNormal.y * Bn);
Nb = normalize(Nb);
Vn = normalize(InViewDir);
Hn = normalize(Vn + Ln);
lighting = lit(dot(Ln,Nb),dot(Hn,Nb),vecSkill1.y);
#endif
#endif

#ifdef ENVMAPPING
Nb = Nn + ((InWorldNormal) * Tn + (InWorldNormal) * Bn);
Nb = normalize(Nb);
Vn = normalize(matViewInv[3].xyz - InWorldPos);

float3 reflVect = reflect(Vn,Nb);
float3 reflColor = texCUBE(EnvMapSampler,float4(-reflVect, 1)).rgb;

float3 Light1BCK = Light1;
Light1 -= Mask.g;
Light1 = clamp(Light1,0,1);
Light1 += reflColor*Mask.g;
#else
#ifdef VELVETY
Vn = normalize(matViewInv[3].xyz - InWorldPos);
#endif
#endif


#ifdef DIFFLIGHT
#ifdef DOSUN
Light1.xyz *= clamp((lighting.y*vecSunColor*2),shadowAlpha,1);
#else
Light1.xyz *= clamp((lighting.y*vecLightColor[0]*2*InLight.a),shadowAlpha,1);
#endif
#endif

#ifdef SPECLIGHT
#ifdef DOSUN
Light1.xyz += lighting.z*Mask.r;
#else
Light1.xyz += lighting.z*Mask.r*InLight.a;
#endif
#endif

#ifdef VELVETY
half3 velvety1;
float vdn = vecSkill1.z-dot(Vn,Nn);
float3 vecColor = float4(vdn.xxx,1.0);
velvety1 = float4((vecColor*velvColor).xyz,1);
velvety1 = clamp(velvety1,0,1);
Light1 += velvety1*Mask.b;
#endif

#ifdef SHADOWMAPPING
Light1 *= tex2D(ShadowMapSampler,InTex.zw);
#endif

#ifdef LUMMAPPING
Light1 += luminance * (tex2D(NormalMapSampler,InLumUV.xy).a * vecSkill9.xyz);
#endif

return float4(Light1,Color.a);
}



//----------------------------------------------------------------------------------------------------------------
// LIGHTS
//----------------------------------------------------------------------------------------------------------------

struct VS_LIGHTS0
{
float4 Pos : POSITION;

float4 Light1 : TEXCOORD0;
float4 Light2 : TEXCOORD1;
float4 Light3 : TEXCOORD2;
float4 Light4 : TEXCOORD3;
float4 Light5 : TEXCOORD4;

float2 Tex : TEXCOORD5;
float Fog : FOG;
};

VS_LIGHTS0 LightsVS(float4 Pos : POSITION, float3 texcoord0 : TEXCOORD0, float3 Normal : NORMAL, float3 Tangent : TEXCOORD0 )
{
VS_LIGHTS0 Out = (VS_LIGHTS0)0;
Out.Pos = mul(Pos, matWorldViewProj); // transform Position

// compute the 3x3 tranform matrix
// to transform from world space to tangent space
float3x3 worldToTangentSpace;
worldToTangentSpace[0] = mul(Tangent, matWorld);
worldToTangentSpace[1] = mul(cross(Tangent, Normal), matWorld);
worldToTangentSpace[2] = mul(Normal, matWorld);

float3 PosWorld = mul(Pos, matWorld);

//Light1
float3 Light1 = PosWorld - vecLightPos[0].xyz ;
Out.Light1.xyz = normalize(mul(worldToTangentSpace, -Light1));
Out.Light1.xyz = saturate(dot(1, Out.Light1.xyz));
Out.Light1.w = distance(PosWorld,vecLightPos[0])/vecLightPos[0].w;
Out.Light1.xyz *= 1-saturate(dot(Out.Light1.w, Out.Light1.w));

//Light2
float3 Light2 = PosWorld - vecLightPos[1].xyz ;
Out.Light2.xyz = normalize(mul(worldToTangentSpace, -Light2));
Out.Light2.xyz = saturate(dot(1, Out.Light2.xyz));
Out.Light2.w = distance(PosWorld,vecLightPos[1])/vecLightPos[1].w;
Out.Light2.xyz *= 1-saturate(dot(Out.Light2.w, Out.Light2.w));

//Light3
float3 Light3 = PosWorld - vecLightPos[2].xyz ;
Out.Light3.xyz = normalize(mul(worldToTangentSpace, -Light3));
Out.Light3.xyz = saturate(dot(1, Out.Light3.xyz));
Out.Light3.w = distance(PosWorld,vecLightPos[2])/vecLightPos[2].w;
Out.Light3.xyz *= 1-saturate(dot(Out.Light3.w, Out.Light3.w));

//Light4
float3 Light4 = PosWorld - vecLightPos[3].xyz ;
Out.Light4.xyz = normalize(mul(worldToTangentSpace, -Light4));
Out.Light4.xyz = saturate(dot(1, Out.Light4.xyz));
Out.Light4.w = distance(PosWorld,vecLightPos[3])/vecLightPos[3].w;
Out.Light4.xyz *= 1-saturate(dot(Out.Light4.w, Out.Light4.w));

//Light5
float3 Light5 = PosWorld - vecLightPos[4].xyz ;
Out.Light5.xyz = normalize(mul(worldToTangentSpace, -Light5));
Out.Light5.xyz = saturate(dot(1, Out.Light5.xyz));
Out.Light5.w = distance(PosWorld,vecLightPos[4])/vecLightPos[4].w;
Out.Light5.xyz *= 1-saturate(dot(Out.Light5.w, Out.Light5.w));

float ofog = 1 - (distance(PosWorld, vecViewPos) - vecFog.x) * (vecFog.z);
Out.Fog = ofog;

Out.Tex = texcoord0.xy;

return Out;
}

struct PS_LIGHTS0
{
float3 Light1 : TEXCOORD0;
float3 Light2 : TEXCOORD1;
float3 Light3 : TEXCOORD2;
float3 Light4 : TEXCOORD3;
float3 Light5 : TEXCOORD4;

float2 Tex : TEXCOORD5;
};

float4 LightsPS( float4 Light1 : TEXCOORD0,
float4 Light2 : TEXCOORD1,
float4 Light3 : TEXCOORD2,
float4 Light4 : TEXCOORD3,
float4 Light5 : TEXCOORD4,
float2 Tex : TEXCOORD5
):COLOR0
{
float3 color = tex2D(ColorMapSampler,Tex);

float4 shadow1 = Light1;
float4 shadow2 = Light2;
float4 shadow3 = Light3;
float4 shadow4 = Light4;
float4 shadow5 = Light5;

float3 result =
(shadow1*vecLightColor[0])+
(shadow2*vecLightColor[1])+
(shadow3*vecLightColor[2])+
(shadow4*vecLightColor[3])+
(shadow5*vecLightColor[4]);

result *= color;

//-------------------------------------------
//Finalize
//-------------------------------------------

return float4(result,1.0);

}




technique t01
{

pass P0
{
VertexShader = compile vs_2_0 DiffuseVS();
#ifdef PS2A
PixelShader = compile ps_2_a DiffusePS();
#else
PixelShader = compile ps_2_0 DiffusePS();
#endif



}

#ifdef DYNLIGHTS
pass P1 //lights
{

alphablendenable=true;
srcblend=one;
destblend=one;
VertexShader = compile vs_1_0 LightsVS();
PixelShader = compile ps_1_4 LightsPS();
}
#endif

}
Posted By: DLively

Re: Shade-C all in one FX - 04/15/14 17:11

Okay, so where does my diffuse map go?
Posted By: DLively

Re: Shade-C all in one FX - 04/15/14 17:28

added this: event = sc_mtlEvent_aio;

no luck. frown
Posted By: rojart

Re: Shade-C all in one FX - 04/17/14 21:29

I think it's better if you change to Shade-C EVO.

Older revisions were designed for A7 Engine.

Shade-C EVO works very well with A8 and i've some experience in normal maps which this should help you.
Posted By: DLively

Re: Shade-C all in one FX - 04/17/14 23:06

I tried the shade-c EVO and couldnt figure it out -> the A7 Version comes CHM file which was helpful for me.

I think I had shade-c EVO working however and as mentioned in Randoms thread, the fx didnt work on mdls... which is ALL I use. I dont use blocks smirk
Posted By: DLively

Re: Shade-C all in one FX - 04/17/14 23:07

Another note, I noticed the shade-c Dynamic lights are slower than regular dynamic lights..
Posted By: rojart

Re: Shade-C all in one FX - 04/17/14 23:58

Shade-C EVO Wiki

fx works well on mdls, examples checked?

Originally Posted By: DLively
Another note, I noticed the shade-c Dynamic lights are slower than regular dynamic lights..

What exactly you meant it's slower, fps...?
Posted By: DLively

Re: Shade-C all in one FX - 04/18/14 01:55

When I Open WED I get these errors:

Invalid Name:
sc_lights_shadowmapBlur.fx
sc_lights_pointSpecular.fx
sc_lights_pointProjection.fx
sc_lights_spotSpecular.fx
sc_lights_spotSpecularShadow.fx
sc_lights_spotShadow.fx
sc_lights_sunShadowCreate.fx
sc_lights_sunShadowEdge.fx
sc_lights_sunShadowExpand.fx
sc_lights_deferred_finalize.fx

sc_obj_softSpriteOverlay.fx
sc_obj_softFogOverlay.fx
sc_obj_softFogOverlayBright.fx
sc_pp_explosionRefractScreen.fx

And then my level loads, and the game runs -> none of the above fx are used in my level yet.



Thank you for the wiki link!! Didn't know it exsisted laugh
Yes when I enable sc_setup and create one light the fps drops by 1/3
Posted By: DLively

Re: Shade-C all in one FX - 04/18/14 04:08

Got the normal maps to work!! Still getting the invalid names: ...
Posted By: sivan

Re: Shade-C all in one FX - 04/18/14 08:44

because those fx file names are too long for WED. if they are assigned in code to materials and not directly in WED they should work. but I don't use WED only for publishing by an empty level...
Posted By: rojart

Re: Shade-C all in one FX - 04/18/14 11:51

Yes, like Sivan mentioned the fx files are limited like WAD and MDL models files to 15 characters.

Originally Posted By: DLively
...Yes when I enable sc_setup and create one light the fps drops by 1/3

Hmm strange, i got stable 60fps eg. 144 dynamic lights, like code below.



Code:
#include <default.c>

#define PRAGMA_PATH "shadec"
#include "shade-c.h"

#include "common.h"

ENTITY* skycube =
{
	type = "plain_abraham+6.tga";
	flags2 = SKY | CUBE | SHOW;
	red = 130;
	green = 130;
	blue = 130;
}

VECTOR vSpeed, vAngularSpeed, vForce, vMove;
ENTITY* spotlight[144];

void main()
{	
	fps_max = 60;
	shadow_stencil = -1;
	video_set(800, 600, 0, 2);
	level_load("05.wmb");
	wait(3);
	vec_set(sun_color, vector(0,0,0)); 
	vec_set(ambient_color, vector(0,0,0));
	
	vec_set(camera.x,vector(840,-870,700));
	vec_set(camera.pan,vector(135,-40,0));
	camera.arc = 90;
	
	sc_sky(skycube);
	sc_screen_default = sc_screen_create(camera);
	sc_setup(sc_screen_default);
	
	int i,j,k=0;
	var dist_x = -646, dist_y = 520;
	
	random_seed(0);
	
	for (i=0;i<12;i++){
		for (j=0;j<12;j++){
			spotlight[k] = sc_light_create(vector(dist_x,dist_y,200), 500, vector(random(255),random(255),random(255)), SC_LIGHT_SPOT | SC_LIGHT_SPECULAR, vector(0,-90,0), 40);
			k++; 
			dist_x += 114;
		}
		dist_x = -646;
		dist_y -= 114;
	}
	
	for (k=0;k<143;k++)
	sc_light_update(spotlight[k]);
	
	def_debug();
	
	draw_textmode("Arial",3,16,100);
	var speed = 20;
	
	while(1)
	{
		draw_text("click and hold [RMB] and use [QWEASD] keys to move the camera",2,115,COLOR_GREEN);
		
		if(mouse_right) // Move the camera if the right mouse button was pressed
		{
			vForce.x = -speed *(key_force.x + mouse_force.x); // pan angle
			vForce.y =  speed *(key_force.y + mouse_force.y);	// tilt angle
			vForce.z = 0;	// roll angle
			vec_accelerate(vMove,vAngularSpeed,vForce,0.8);
			vec_add(camera.pan,vMove);
			vForce.x = speed * (key_w - key_s);	// forward
			vForce.y = speed * (key_a - key_d);	// sideward
			vForce.z = speed * (key_q - key_e);	// upward
			vec_accelerate(vMove,vSpeed,vForce,0.5);
			vec_rotate(vMove,camera.pan);
			vec_add(camera.x,vMove);
		}
		wait(1);
	}
}

Posted By: DLively

Re: Shade-C all in one FX - 04/18/14 14:46

Okay, thats good to know laugh

If I reduce my screen size to 800x600 then my fps stays around 60. Otherwise I get an fps of 31 or so at 1280x720.

Since the upgrade to my project, I'll have to do some level optimizing - my level dimensions are around 6000x4000 - that being my biggest level conisting of several rooms and models adding to 306 entities (using LOD stages) -> My Nexus is 339573 and that has to be bad.. since I read that 500MB is commercial size.. mem is 391, geo and shad 0 -> ents 274 and 1578 Free. This level is only 25% done (If that).. Face Palm..
Posted By: DLively

Re: Shade-C all in one FX - 04/19/14 00:19

Okay disregard the last post - I am going to redo that level and just optimize the hell out of it...

How do I use particles with shadec?
Posted By: DLively

Re: Shade-C all in one FX - 04/19/14 01:38

Figured it out laugh

Thanks For this fine Whole lot of Awesome laugh
Posted By: DLively

Re: Shade-C all in one FX - 04/19/14 01:57

I wanted to note that my model works when:

entskin1 = diffuse
entskin2 = specular (G,B,A are black)
entskin3 = NormalMap (Alpah is Black)


---------------------

Am I doing something wrong? Cause I tried to follow the instructions that were given to Random in a seperate post and although he was successful in his results after following the instructions, I was not.

I would like to also ask how to add Shadows now laugh
Posted By: rojart

Re: Shade-C all in one FX - 04/19/14 09:37

Originally Posted By: DLively
Okay, thats good to know laugh...If I reduce my screen size to 800x600 then my fps stays around 60. Otherwise I get an fps of 31 or so at 1280x720...

Ok, checked in fullscreen resolution by full HD (1920x1080) for you and i get ~31fps > ~60fps depending of the distance to the ground.
You can test my exe in relation of performance also.

My Computer Specs:
OS: Windows 8.1 Pro 64-bit
CPU: i7-4770 @ 3.40GHz
GPU: GeForce GTX 760 @ 2048MB
RAM: 16GB
PRG: A8 Pro 8.45.4


Originally Posted By: DLively
Since the upgrade to my project, I'll have to do some level optimizing - my level dimensions are around 6000x4000 - that being my biggest level conisting of several rooms and models adding to 306 entities (using LOD stages)...

You use the Automated Managed Level of Detail from MED for your models (MED > Object > Manage Level of Detail), right?

Originally Posted By: DLively
...How do I use particles with shadec?

sc_screen_default.settings.forward.enabled = 1; //enable if you need particles or custom materials which can't be rendered in the deferred pipeline
Was this?

Originally Posted By: DLively
I wanted to note that my model works when:
entskin1 = diffuse
entskin2 = specular (G,B,A are black)
entskin3 = NormalMap (Alpah is Black)
---------------------
Am I doing something wrong?

It seems to me, that you've another chronology of skin numbers.
Your Specular have skin2.x and Normalmap skin3.xyz
If you need the same like me, then change to:
Code:
//assign skins
#define SKIN_ALBEDO (skin1.xyz) //diffusemap
#define SKIN_ALPHA (skin1.w) //alpha
#define SKIN_NORMAL (skin2.xyz) //normalmap
#define SKIN_GLOSS (skin2.w) //glossmap



Originally Posted By: DLively
...I would like to also ask how to add Shadows now laugh

It's very simple, add this flag SC_LIGHT_SHADOW to the light function:

Code:
spotlight[k] = sc_light_create(vector(dist_x,dist_y,200), 500, vector(random(255),random(255),random(255)), SC_LIGHT_SPOT | SC_LIGHT_SPECULAR | SC_LIGHT_SHADOW, vector(0,-90,0), 40);

Posted By: DLively

Re: Shade-C all in one FX - 04/19/14 13:30

Mine looks like this? smirk

I had added :
ENTITY* light_child = sc_light_create(vector(0,0,0), sc_lightrange, vector(255,140,80), SC_LIGHT_SHADOW);

and get no shadows -> about to try your suggested methods -> You rock Rojart laugh

...

Okay shaodws are working however to make my work a little less guessy - Could I ask what these peramteres are?

spotlight[k] = sc_light_create(vector(dist_x,dist_y,200), LIGHTRANGE*, COLOR RGB*, SC_LIGHT_SPOT | SC_LIGHT_SPECULAR | SC_LIGHT_SHADOW, vector(0,-90,0), 40);
Posted By: DLively

Re: Shade-C all in one FX - 04/19/14 16:16

I found it in the commons laugh But I still dont understand everything laugh
Posted By: DLively

Re: Shade-C all in one FX - 04/19/14 17:48

1280X720 zoomed out I get 10Fps with your example Rojart laugh

The computer I am using only has 4GB of Ram and 512MB Card smirk My other machine has 8GB or Ram and 1024MB GPU.

Is there a way to acchieve these graphics without the huge loss of fps? I've played games on this computer that would require so much more reources than I use - and I my fps doesn't drop - It obviously must be me.
Posted By: DLively

Re: Shade-C all in one FX - 04/19/14 18:28

Here's a note:

Code:
#define SKIN_ALBEDO (skin1.xyz) //diffusemap
#define SKIN_ALPHA (skin1.w) //alpha
#define SKIN_NORMAL (skin3.xyz) //normalmap
#define SKIN_GLOSS (skin3.w) //glossmap



which is skin 1 and 3 smirk

Click to reveal..

//------------------------------------------------------------------------------
//----- USER INPUT -------------------------------------------------------------
//------------------------------------------------------------------------------

//assign skins
#define SKIN_ALBEDO (skin1.xyz) //diffusemap
#define SKIN_ALPHA (skin1.w) //alpha
#define SKIN_NORMAL (skin3.xyz) //normalmap
#define SKIN_GLOSS (skin3.w) //glossmap
//#define SKIN_EMISSIVEMASK (skin3.y) //emissive mask
//#define SKIN_COLOR (skin3.w) //(team)color mask
//#define SKIN_EMVMAPMASK (skin3.x) //environment mapping mask
//#define SKIN_VELVETYMASK (skin3.z) //velvety lighting mask
//...

//#define MTL_SKIN1 //skin1 is a mtlSkin and not an entSkin?
//#define MTL_SKIN2 //skin2 is a mtlSkin and not an entSkin?
//#define MTL_SKIN3 //skin3 is a mtlSkin and not an entSkin?
//#define MTL_SKIN4 //skin4 is a mtlSkin and not an entSkin?

#define NORMALMAPPING //do normalmapping?

#define GLOSSMAP //entity has glossmap?
#define GLOSSSTRENGTH 0 //glossmap channel will be set to this value if GLOSSMAP is not defined

//#define EMISSIVEMASK //use emissive mask? (formula: emissive_color = SKIN_EMISSIVEMASK * SKIN_ALBEDO)
//#define EMISSIVE_A7 // (optional EMISSIVEMASK addon) use emissive_red/green/blue for as emissive color? (formula: emissive_color = SKIN_EMISSIVEMASK * vecEmissive)
//#define EMISSIVE_SHADEC // (optional EMISSIVEMASK addon) OR use SC_OBJECT_EMISSIVE as emissive color? (formula: emissive_color = SKIN_EMISSIVEMASK * SC_OBJECT_EMISSIVE)

//#define OBJECTCOLOR_A7 // use diffuse_red/green/blue as (team)color using the colormask?
//#define OBJECTCOLOR_SHADEC // OR use SC_OBJECT_COLOR as (team)color using the colormask?

//#define ALPHACLIP //do alphatesting/alphacutout?

//#define USE_VEC_DIFFUSE //use diffuse_red/green/blue? (note: don't use with OBJECTCOLOR_A7 at the same time)

//#define ZPREPASS //do an early zbuffer prepass? Only makes sense for heavy ALU

//------------------------------------------------------------------------------
// ! END OF USER INPUT !
//------------------------------------------------------------------------------

#include <scHeaderObject>
// <-
// insert custom code here
// ->
#include <scObject>


I changed that and it works now laugh Starting to figure shadows out too laugh

Thank you for your patience!!
Posted By: DLively

Re: Shade-C all in one FX - 04/19/14 18:30

Im gunna make a tutorial Once I figure this out lmao..

BTW: I don't know if there was a difference - But when I had the choice of selecting Shade-c Versions, I selected the SHADE-C EVO MASTER (So that's what I am using) xD
Posted By: DLively

Shade-C EVO MASTER Q&A - 04/19/14 19:16

Are the lights supposed to turn off when the camera isn't looking at them?


Code:
action light_act(){
ENTITY* light_child = sc_light_create(vector(my.x, my.y, my.z), my.skill4, vector(my.skill1,my.skill2,my.skill3), SC_LIGHT_SPOT | SC_LIGHT_SPECULAR | SC_LIGHT_SHADOW , vector(my.pan, my.tilt-90, my.roll), my.skill5);
	ENTITY* light_child2 = sc_light_create(vector(my.x, my.y, my.z), my.skill4, vector(my.skill1,my.skill2,my.skill3), SC_LIGHT_SPOT | SC_LIGHT_SPECULAR | SC_LIGHT_SHADOW , vector(my.pan, my.tilt+90, my.roll+180), my.skill5);
	
	while(1){wait(1);
		vec_set(light_child.x,you.x);
		light_child.z += 200;
		sc_light_update(light_child);
		vec_set(light_child2.x,you.x);
		//light_child.z -= 12;
		sc_light_update(light_child2); 
}
}



I had to roll the light because it was making shadows in the wrong direcion.. smirk
Posted By: rayp

Re: Shade-C EVO MASTER Q&A - 04/19/14 21:38

Quote:
Are the lights supposed to turn off when the camera isn't looking at them?
Faced the same prob but only when using ZNEAR on fps weapon models. In some directions the lights disappear ( only with ZNEAR ). Also my fire particles are rendered through walls when ZNEAR is activated. I changed camera.clip_near, maybe it has something to do with it. mhhh...
Posted By: DLively

Re: Shade-C EVO MASTER Q&A - 04/19/14 21:46

im not using znear smirk

If I change clip_near my models clip in the camera.
Posted By: DLively

Re: Shade-C EVO MASTER Q&A - 04/19/14 21:51

the min dist I can go is 5 - and there is little to no change - however if I set it to a higher value just for debug purposes that seems to be the problem...
Posted By: rojart

Re: Shade-C EVO MASTER Q&A - 04/19/14 22:08

Tried with clipfactor?
Posted By: rojart

Re: Shade-C all in one FX - 04/19/14 22:21

Originally Posted By: DLively
...Okay shaodws are working however to make my work a little less guessy - Could I ask what these peramteres are?

spotlight[k] = sc_light_create(vector(dist_x,dist_y,200), LIGHTRANGE*, COLOR RGB*, SC_LIGHT_SPOT | SC_LIGHT_SPECULAR | SC_LIGHT_SHADOW, vector(0,-90,0), 40);


That should be clear enough, by the way have a look on sc_lights.c too.

ENTITY* sc_light_create(VECTOR* inPos, var inRange, VECTOR* inColor, int inType, BMAP* inProjMap, VECTOR* inDir, var inSpotArc)
Posted By: DLively

Re: Shade-C all in one FX - 04/20/14 01:16

No I didnt try ClipFactor laugh Looks like that will fix my problem.
I had forgot to update you and inform you I had already figured out the lights laugh
Posted By: DLively

Re: Shade-C all in one FX - 04/20/14 01:28

Id really like to say it worked, but No better results... anything below 1200 doesn't do anything.. and above 1200 doesn't display it anymore..

Setting it to 1 did nothing - 2 and 3 are useless, cause A shadow is pointless without light smirk
Posted By: DLively

Re: Shade-C all in one FX - 04/20/14 01:56

A little bit more info: I've noted that when the light is behind the player (if the players / camera pan is between 270 - 310 or so) then it removes it. If not then everything works fine :?

^^EDIT: It doesn't matter actually. I just had to find the glitchy spot.. where the second glitch spot is, isnt as bad as the fist, as the player will be running by that area many many times.

EDIT, EDIT: Its more prominent when the player faces the pan settings I indicated above.



Another Note For Clipfactor: Above 1200 Removes all lights in the level.
Posted By: DLively

Re: Shade-C all in one FX - 04/20/14 02:20




within 30 quants its triggered.
Posted By: DLively

Re: Shade-C all in one FX - 04/20/14 03:57

I've tried and tried... why does this happen? This makes no sense tongue

Posted By: rojart

Re: Shade-C all in one FX - 04/20/14 12:53

Originally Posted By: DLively
1280X720 zoomed out I get 10Fps with your example Rojart laugh

The computer I am using only has 4GB of Ram and 512MB Card smirk My other machine has 8GB or Ram and 1024MB GPU.

Is there a way to acchieve these graphics without the huge loss of fps? I've played games on this computer that would require so much more reources than I use - and I my fps doesn't drop - It obviously must be me.

Nice shots! You are using DDS textures with generated 10 mipmaps DXT1 no alpha or DXT5 + alpha max res. 2048², right?

By the way Frame Rate Optimization.


Originally Posted By: DLively
A little bit more info: I've noted that when the light is behind the player (if the players / camera pan is between 270 - 310 or so) then it removes it. If not then everything works fine :?
^^EDIT: It doesn't matter actually. I just had to find the glitchy spot.. where the second glitch spot is, isnt as bad as the fist, as the player will be running by that area many many times.
EDIT, EDIT: Its more prominent when the player faces the pan settings I indicated above.
Another Note For Clipfactor: Above 1200 Removes all lights in the level.

You should check this function sc_screen_default.settings.lights.sunShadowRange = 0; too.

Quote:
manually set the shadow range...we don't need realtime shadows in the far distant! If set to 0 (default) shadow range will be set to camera.clip_far

If you have 0, then check camera.clip_far, default is 50000!


If this all doesn't help the best way is to make a small test level where it happens.
Posted By: DLively

Re: Shade-C all in one FX - 04/20/14 18:49

The light only turns off when the player is facing the pan direction I indicated above - Otherwise it deactivates when the player is a little in front of it.
Sorry - The light Turns off if the players pan is between 270 - 310 and if he is not facing the floortorch. Otherwise its not as noticeable.

I would love to send you a compiled version, but it seems that when I compile with or without a resource file I get an error: 88760b59 and the lighters light does not get created.

Nor does any light for that matter.
Posted By: rojart

Re: Shade-C all in one FX - 04/20/14 20:07

You have to create a folder named shadec/tex/ in your compiled folder and put the sc_deferredLighting_LUT.dds into it.
Posted By: DLively

Re: Shade-C all in one FX - 04/21/14 00:05

Thanks for your patience Rojart,
That fixed it!

However, there seems to be a glitch with my text now that I've upgraded to Shade-C Evo... When I run the game, instead of it saying what it is supposed to say it says "TEXT" which it didn't do until I upgraded.

I was able to deal with it until I had to ask about it - but now is the time since I cannot light my floor torch as it must be that glitch that causes the compiled version to stop responding..

So at this point I can not send you a compiled version of my glitch tongue
I've also tried using draw_text which still had the same effect as the regular TEXT*
Posted By: DLively

Re: Shade-C all in one FX - 04/21/14 17:26

Trying to fix this glitch still.. . I tried to rotate the pan of the floor torch to see it I could 'trick the engine' into thining its pan was in a direction that is less likely to be notable to the player... (rotated it 90*) and still the same.
Posted By: DLively

Re: Shade-C all in one FX - 04/21/14 17:27

I also brought my models closer to the ORIGIN, still nothing.
Posted By: DLively

Re: Shade-C all in one FX - 04/21/14 17:38

Just a note, I made two lights for this:

1 is in the negative direction witch is above the floor torch, (Light pointing down)

2. the other is tilted possitive, and is inside the torch to have light comming from inside the torch...

--- I removed one light with the same error..



I moved my floor torches south in the area that they glitch in - as to have a quick fix to solve the glitch, but now it happens on the other side of it too..
Posted By: DLively

Re: Shade-C all in one FX - 04/21/14 17:54

i also tried to rotate the light's pan and rolls to see if that would help.. nope.
Posted By: rojart

Re: Shade-C all in one FX - 04/21/14 19:35

Can you do a screenshot of the issue?
Maybe i can see what's going wrong.
Posted By: DLively

Re: Shade-C all in one FX - 04/21/14 22:43

I could send you the compiled version if you like but it seems pointless as the problem is as soon as i approach the floor torch it freezes and crashes.

I could instead show you the code I use:



Code:
FONT* arial_font = "Arial#20b";

//ACTION TEXTS
STRING* Light_candle_str = "LIGHT CANDLE [HOLD ACTION]";
STRING* Light_torch_str = "LIGHT TORCH [HOLD ACTION]";
STRING* Keep_candle_lit_str = "KEEP CANDLE LIT [ACTION]";
STRING* AT_opencabinet = "OPEN CABINET [HOLD ACTION]";
STRING* AT_lockedcabinet = "THIS CABINET IS LOCKED, YOU DON'T HAVE THE KEY!";
//TEMP ACTION STR
STRING * action_str = "text";

TEXT* action_text =	
{
	font = arial_font;
  	string = action_str;
  	layer = 15;
  	flags = CENTER_X;
} 

..........

action candle_stick(){
	
	var light_snd_once = 0;
	var lighting_snd;
	var action_panel_trigger = 0;//triggers the Hold action panel
	var wick_vec_num = 130;
	if(my.skill3 == 0){wick_vec_num = 130;}
	else{wick_vec_num = my.skill3;}
	if(my.skill5 == 0){wick_vec_num = 130;}
	else{wick_vec_num = my.skill5;}
	// 130 is for a standard candle / wall candle
	// 49 is for a skull candle
	
	var light_displacement = 30;//how far from the fire is the light source?
	var light_timer = 0;//how long has it taken to light the flame?
	var light_time = 10;//how long it takes to light the flame
	VECTOR wick_pos, temp_vec;
	
	if(is(my,POLYGON)){set(my,POLYGON);}
	else{set(my,PASSABLE);}
	my.material = mtl_levelDefaultNM;
	
	while(1){wait(1);
		
		while(left_hand_slot == lighter_slot){wait(1);//if there is no lightsource then wait until there is one.
			
			while(!fire_source){wait(1);}
			
			if(is(my,FLAG6)){vec_set(wick_pos.x,vector(my.x,my.y,my.z));wick_pos.z += 125;}
			else{vec_for_vertex(wick_pos,me,wick_vec_num);}//vector position in the modle
			if (my.skill1==0) {//if im not lit
				
				if(vec_dist(wick_pos.x,fire_source.x) <= source_min_dist && light_timer < light_time){
					
					//.............................................
					//action bar has been determined
					//the player is now ready to follow instructions
					if(is(action_text, SHOW)){//if the action key is on screen
						if(action_keys==1){//if action keys have been pressed
							
							if(light_snd_once == 0 && light_timer >= 6){lighting_snd=ent_playsound(me,candle_ignite_snd,100);light_snd_once = 1;}
							
							light_timer += 0.5;//start the timer
							//progress_bar_y = light_timer * 25;//calculations
							progress_bar_y = floor(light_timer)*25;
							set(progress_bar_pan,SHOW);//show the progressbar
						}
						else{//action has been released
							snd_stop(lighting_snd);
							light_snd_once = 0;
							reset(progress_bar_pan,SHOW);//reset progress bar
							light_timer = 0;//reset lighting time
						}
					}
					//.............................................
					//the action bar has not been determined yet
					else{
						action_panel_trigger = 1;//has been trigger to make sure action can be removed
						if(is(my,FLAG7)==0 && is(my,FLAG6)==0){str_cpy(action_str, "LIGHT CANDLE [HOLD ACTION]");}
						if(is(my,FLAG7)==1 || is(my,FLAG6)==1){str_cpy(action_str, "LIGHT TORCH [HOLD ACTION]");}
						iconlist_x = 64;iconlist_y = 0;// set to lighter icon
						set(action_text,SHOW);//show the action map
						set(iconlist_pan,SHOW);//show the icon map
					}	
					//.............................................
					
				}//light source is close, lighting up
				if(vec_dist(wick_pos.x,fire_source.x) > source_min_dist){//light source is not close enough
					if(action_panel_trigger == 1){//if it hasn't been reset yet...
						action_panel_trigger = 0;//reset it
						reset(progress_bar_pan,SHOW);//remove these panels
						reset(action_text,SHOW);
						reset(iconlist_pan,SHOW);
					}
					light_timer = 0;
				}
				
				if(light_timer >= light_time){//if the light source has lit me up	
					
					reset(progress_bar_pan,SHOW);//remove these panels now
					reset(action_text,SHOW);
					reset(iconlist_pan,SHOW);
					
					vec_set(temp_vec.x,wick_pos.x);//temp how holds the wicks location
					//if the light is on the wall, then it needs to be moved away:
					//FLAG8FLAG8FLAG8FLAG8FLAG8FLAG8FLAG8FLAG8FLAG8FLAG8FLAG8FLAG8
					if(is(my,FLAG8)){//for wall lights only
						temp_vec.x += light_displacement * cos(my.pan-90);
						temp_vec.y += light_displacement * sin(my.pan-90);
					}
					
					//temp_vec.z += candle_light_height;//prepare to move the light upwards so its not pushing through the this model
					if(is(my,FLAG6)){
						candle_light_height = torch_height;
						//temp_vec.z += candle_light_height;
						you = ent_create("cube.mdl",temp_vec.x,floortorch_fire);
					}//create the candles lightsource
					else{
						candle_light_height = candle_height;
						temp_vec.z += candle_light_height;
						if(is(my,FLAG7)){you = ent_create("cube.mdl",temp_vec.x,torch_fire);}//create the candles lightsource
						else{you = ent_create("cube.mdl",temp_vec.x,candle_fire);}
					}
					you.skill1 = candle_max_light;
					my.skill2 = handle(you);//the candles lightsource is now stored for using later
					
					my.skill1=1;//I am now lit
					light_timer = 0;//reset the light_timer for relighting
					
				}	
				
			}
			
			if(my.skill1 == 1){//if I am lit
				you = ptr_for_handle(my.skill2);//I must be reminded you is the candles lightsource
				if(you.skill1 > 85 && you.skill1 < 200){
					if(vec_dist(wick_pos.x,fire_source.x) < source_min_dist){//if the light_source is close enough
						
						if(is(action_text, SHOW)){//if the action key is on screen
							if(action_keys==1){//if action keys have been pressed
								you = ptr_for_handle(my.skill2);//I must be reminded you is the candles lightsource
								you.skill1 = candle_max_light;
								action_panel_trigger = 0;//reset it
								reset(action_text,SHOW);//remove these panels
								reset(iconlist_pan,SHOW);
							}
							
						}
						//.............................................
						//the action bar has not been determined yet
						else{
							action_panel_trigger = 1;//has been trigger to make sure action can be removed
							str_cpy(action_str, "KEEP CANDLE LIT [ACTION]");
							iconlist_x = 64;iconlist_y = 0;// set to lighter icon
							set(action_text,SHOW);//show the action map
							set(iconlist_pan,SHOW);//show the icon map
						}	
						//.............................................
						
					}
					
				}
				if(vec_dist(wick_pos.x,fire_source.x) > source_min_dist || you.skill1 < 81){//door is not close enough
					if(action_panel_trigger == 1){//if it hasn't been reset yet...
						action_panel_trigger = 0;//reset it
						reset(action_text,SHOW);//remove these panels
						reset(iconlist_pan,SHOW);
					}
				}
				
			}
			if(left_hand_slot != lighter_slot){reset(progress_bar_pan,SHOW);reset(action_text,SHOW);reset(iconlist_pan,SHOW);}
	}
	}	
	
}



Keeping in mind this worked in a compiled copy before I upgraded to shade-c EVO MASTER
Posted By: rojart

Re: Shade-C all in one FX - 04/22/14 09:35

At first glance i can only speculate what's wrong.

In the top of your candle action put this:
Code:
action candle_stick(){
while (!me) {wait (1);}
 ...
}



Check also this:
Code:
// set camera sizes (this is only needed if you use "camera" as main):
camera.size_x = screen_size.x;
camera.size_y = screen_size.y;
// set camera as main view of sc_screen_default:
sc_screen_default = sc_screen_create(camera);



Try and compile without shader //my.material = mtl_levelDefaultNM;

Your game is an interior, exterior level?
If interior make sure you have sun light and shadows disabled vec_set(sun_color, vector(0,0,0)); sc_screen_default.settings.lights.sunShadows = 0; //enable shadows for the sun

Originally Posted By: DLively
I could send you the compiled version if you like but it seems pointless as the problem is as soon as i approach the floor torch it freezes and crashes.

What error message?

You can use the sys_marker command to mark positions in the code and find the place where the crash happens.

Make your action small as possible and expand step by step to find your issue, good luck.
© 2024 lite-C Forums