source: creating shaders for single parts

not under any category
Post Reply
  • Author
  • Message
Offline
Posts: 5
Joined: 01 Feb 2014, 13:18

source: creating shaders for single parts

hi

i need good d3d8 source (c++) with .fx/.ps/.vs shaders for creating bloom and more for my sky and terrain textures
i dont want to bloom the whole interface.
i like this enb bloom but how can i use this as a sdk to create good shaders for special parts of my game? in c++

help Admin - no close please.

Offline
User avatar
*blah-blah-blah maniac*
Posts: 17427
Joined: 27 Dec 2011, 08:53
Location: Rather not to say

Re: source: creating shaders for single parts

Hi

Not sure that i understood what do you want. Games and d3d8 wrappers have nothing in common. Do you have sources of the game, the renderer of it, but wish to make additional effects? You know, mostly indie developers are not game developers at all, they have big ambitions, but in fact they do not release any game or any level, i helping only to those who almost finished their games. Also in general, it's not that hard to make such simple effect like bloom, even with dx8sdk.
_________________
i9-9900k, 64Gb RAM, RTX 3060 12Gb, Win7

Offline
Posts: 5
Joined: 01 Feb 2014, 13:18

Re: source: creating shaders for single parts

sure but there are open source games and i want to learn to work with the d3d sdk and shaders
i am new to this so i looked for a tutorial:

http://www.braynzarsoft.net/index.php?p=SkyMap#still (only exists for d3d10|11)

this is what i am looking for, but i want to use your compiled d3d8 lib to get those effects like bloom, hdr and this nice colour correction to the game, but as you know, the full
interface will be rendered.
if you look in this tutorial, you can see that there is used a shader to render the texture into the skybox.

now im wondering if could use a enb lib or if i need to rewrite the effects. I only have the .fx and config files + the compiled d3d8 dll.
i know that there are tutorials, even for directx 8, which has not many functions, but with enb effects i have a perfect rendered sky|terrain|... part.
i dont even use it for commercial purposes.

i am using an older enb version, i dont know if its made by enb devs but it is very nice.

dont understand why it is required to be the owner or creator of a game, i just want to learn to work with the d3d sdk and those shaders. enb is my inspiration, so i asked for tutorials how you did
those cool effects.
Would be so cool to see any of the enb d3d libs.

Offline
User avatar
*blah-blah-blah maniac*
Posts: 17427
Joined: 27 Dec 2011, 08:53
Location: Rather not to say

Re: source: creating shaders for single parts

D3d8 is definetly bad thing to start with, because dx8 is very old and to program shaders with it is a pain (in assembly only and very tricky because they are short). If game have dx8 render only, this of course limiting, but the questions you asked means that you can't create fancy effects just from reading tutorials or examples. I'm simply wrong person in such things, sample files from dxsdk 8.1 or old gamedev.net lessons may help, but not my mod. Here is f.e. bloom shader from dx8 vice city version, i don't think you need it:

Code: Select all

technique Bloom
{
	pass p0
	{
		Texture[0] = <texColor>;

		MinFilter[0] = Linear;
		MagFilter[0] = Linear;
		AddressU[0] = clamp;
		AddressV[0] = clamp;
		ColorOp[0] = SelectArg1;
		ColorArg1[0] = Texture;
		ColorOp[1] = Disable;

		VertexShaderConstant[0] = <OcclusionParameters>;

		VertexShader =
		decl
		{
			stream 0;
			float v0[3];//pos
			float v1[2];//txcoord0
		}
		asm
		{
			vs.1.1
			def c1, 1.0, 0.0, 0.0, 0.0
			add oT0.xy, v1, c0.x
			mad oPos, v0.xyzx, c1.xxxy, c1.yyyx
		};


		PixelShaderConstant[0] = <BloomParameters>;

		PixelShader =
		asm
		{
			ps.1.4

			def c1, 0.333, 0.333, 0.333, 0.5
			texld r0, t0
			add r1.w, r0.y, -r0.z
			cmp r1.w, r1.w, r0.y, r0.z
			add r2.w, r0.x, -r1.w
			cmp r1.w, r2.w, r0.x, r1.w
			mad r2.w, r1.w, c1.w, c1.w
			mul r1.w, r1.w, r2.w
			mov r1.x, r1.w
			phase
			mov r1.w, r1.x
			mul r1.xyz, r0, r1.w
			mul r1.xyz, r1, c0.x
			mad r0.xyz, r0, c0.y, r1
			dp3_sat r0.w, r0, c1
			mov r0.xyz, r0

		};

		ZEnable=FALSE;
		ZWriteEnable=FALSE;
		AlphaBlendEnable=TRUE;
		CullMode=NONE;
		//set internally
//		SrcBlend=ONE;
//		DestBlend=ONE;
		ALPHATESTENABLE=FALSE;
		FogEnable=FALSE;
	}
}
_________________
i9-9900k, 64Gb RAM, RTX 3060 12Gb, Win7

Offline
Posts: 5
Joined: 01 Feb 2014, 13:18

Re: source: creating shaders for single parts

this is a shader file but i wanted to make my shader file work that ive got from an enb version
i need to know how you did it with the d3d dlls, like adding palette maps(UsePaletteTexture). there isnt any source around to those dlls, so its hard to code it

some d3d8 modified libs has a d3d9 proxy, dont know how this works, but the d3d9 is getting loaded and the effects works too.
for the fx file was a d3d8 and a d3d9 created, it loads the d3d9 proxy lib. without it doesnt work.

Code: Select all

//keyboard controled variables
float	tempF1;
float	tempF2;
float	tempF3;
float	tempF4;
float	tempF5;
float	tempF6;
float	tempF7;
float	tempF8;
float	tempF9;
float	tempF0;


//global variables, already set before executing this code
float	ScreenSize;	//width of the display resolution (1024 f.e.)
float	ScreenScaleY;	//screen proportions (1.333 for 1024/768)
float4	ScreenBrightness;//rgba(0..1) color of the screen with time dependent inertia
float	ScreenBrightnessAdaptation;//(-10..10) for bloom it controls how much to dark in the night or when scene is dark (user defined constant factor)
float	bloomPower;//(0..10) actually used for bloom, but may be useful here (user defined constant factor)
float	useBloom;//(0 or 1) if bloom enabled by user




//textures
texture2D texColor;
texture2D texBloom;
texture2D texDepth;

sampler2D SamplerColor = sampler_state
{
	Texture   = <texColor>;
	
   MinFilter = Anisotropic;//
   MagFilter = Anisotropic;//
   MipFilter = Anisotropic;//LINEAR;
   AddressU  = Wrap;
   AddressV  = Wrap;
   AddressW  = Wrap;
   SRGBTexture=FALSE;
   MaxMipLevel=0;
   MipMapLodBias=0;
};


sampler2D SamplerBloom = sampler_state
{
	Texture   = <texBloom>;

	  MinFilter = Anisotropic;//
   MagFilter = Anisotropic;//
   MipFilter = Anisotropic;//LINEAR;
   AddressU  = Clamp;
   AddressV  = Clamp;
   AddressW  = Clamp;
   SRGBTexture=FALSE;

};

struct VS_OUTPUT_POST {
	float4 vpos  : POSITION;
	float2 txcoord : TEXCOORD0;
};

struct VS_INPUT_POST {
	float3 pos  : POSITION;
	float2 txcoord : TEXCOORD0;
};




//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
VS_OUTPUT_POST VS_PostProcess(VS_INPUT_POST IN)
{
	VS_OUTPUT_POST OUT;

	float4 pos=float4(IN.pos.x,IN.pos.y,IN.pos.z,1);
	float4 pos2=float4(IN.pos.x,IN.pos.y,IN.pos.z,1);

	OUT.vpos=pos2;
	OUT.txcoord.xy=IN.txcoord.xy;

	return OUT;
}




float4 PS_PostProcess(VS_OUTPUT_POST In) : COLOR
{



	float2 offset[4]=
	{
		float2(-0.0,-0.0),
		float2(-0.0, 0.0),
		float2( 0.0, 0.0),
		float2( 0.0,-0.0)

	};
	float4 res=0.0;
	float4 coord=0.0;
	
	coord.xy=In.txcoord.xy;
	float4 origcolor=tex2D(SamplerColor, coord.xy);
	float origgray=max(origcolor.r, max(origcolor.g, origcolor.b));
	res+=origcolor;
	float range=0.1*tempF9/ScreenSize;
	for (int i=0; i<4; i++)
	{

		coord.xy=In.txcoord+offset[i]*range;
		float4 color;
		float gray;
		color=tex2D(SamplerColor, coord.xy);
		float4 colordiff=abs(origcolor-color);
		gray=dot(colordiff.rgb,5.2);
		float lerpfact=saturate(1.5*abs(gray)*color.a);//saturate
		res+=lerp(origcolor, color, lerpfact);
	}
	res=res*0.1;




//res=origcolor;

coord.xy=In.txcoord.xy;
coord.w=0.1*tempF1;
float4 envcol1=tex2Dbias(SamplerColor, coord);
coord.w=0.1*tempF2;
float4 envcol2=tex2Dbias(SamplerColor, coord);
float4 envcol3=tex2D(SamplerBloom, coord.xy);
float4 bloom=envcol3;


float4 envcol=(envcol1+envcol2+envcol3)*0.760;


//envcol=tempF5*pow(envcol,tempF4);

//envcol=envcol*tempF7/(1.0+envcol*tempF8);

//envcol=dot(envcol.xyz,1);
//envcol=max(envcol.x, max(envcol.y, envcol.z));
float4 tempcol;//=max(envcol.x, max(envcol.y, envcol.z));
//envcol=lerp(tempcol, envcol, tempF3);

tempcol.xyz=saturate(res.xyz-envcol.xyz);
float diff=dot(tempcol.xyz, 0.999);

//float srcgray=dot(res.xyz,0.999);
//envcol.xyz=res.xyz-(tempF7*envcol.xyz)*(1.0-saturate(srcgray));

envcol=tempF5*pow(envcol,tempF4);
res=lerp(res, res*envcol, tempF6);
//res=res*tempF7/(1.0+res*tempF8);
//res+=tempF7*pow(bloom,4.0*tempF8);


//desaturate
	float middlegray=(res.r+res.g+res.b)*0.933;
	float3 diffcolor=res.rgb-middlegray;
	res.rgb-=diffcolor*0.2*tempF0;

if (tempF3>1.1) res=origcolor;

	res.a=0.0;
	return res;
}



/*

float4 PS_PostProcess(VS_OUTPUT_POST In) : COLOR
{

	float2 offset[4]=
	{
		float2(-0,-0),
		float2(-0, 0),
		float2( 0, 0),
		float2( 0,-0)
	};
	float4 res=1.0;
	float4 coord=4.0;
	coord.xy=In.txcoord.xy;
	float4 origcolor=tex2Dlod(SamplerColor, coord);
	float origgray=max(origcolor.r, max(origcolor.g, origcolor.b));
	res+=origcolor;
	float range=tempF5*0.001;// /ScreenSize.x
	for (int i=0; i<4; i++)
	{
		coord.xy=In.txcoord+offset[i]*range;
		float4 color;
		float gray;
		color=tex2Dlod(SamplerColor, coord);
		float4 colordiff=abs(origcolor-color);
		gray=max(colordiff.r, max(colordiff.g, colordiff.b));
		float lerpfact=saturate(tempF6*abs(gray));//saturate
		res+=lerp(origcolor, color, lerpfact);
	}
	res=res/5.0;

	res.a=15.0;
	return res;
}
*/



//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
technique PostProcess
{
    pass P0
    {
	VertexShader = compile vs_2_0 VS_PostProcess();
	PixelShader  = compile ps_2_0 PS_PostProcess();

	FogEnable=FALSE;
	ALPHATESTENABLE=FALSE;
	SEPARATEALPHABLENDENABLE=FALSE;
	AlphaBlendEnable=FALSE;
	FogEnable=FALSE;
	SRGBWRITEENABLE=FALSE;
	}
}

Offline
User avatar
*blah-blah-blah maniac*
Posts: 17427
Joined: 27 Dec 2011, 08:53
Location: Rather not to say

Re: source: creating shaders for single parts

ENBSeries is not open source project and i definetly not share convertor too.
_________________
i9-9900k, 64Gb RAM, RTX 3060 12Gb, Win7

Offline
Posts: 5
Joined: 01 Feb 2014, 13:18

Re: source: creating shaders for single parts

that wasnt a request for the whole source, i needed a good tutorial to those palette and bloom effects with snippets, because im a beginer, as i already said
but it seems like that i have to update to d3d9

another question.. if i render a texture to a cube it renders it in a very bad quality, so clouds are not really possible, only gradients, otherwise it looks a bit crappy
you think its because of my old directx version or because i did something wrong? dds file

i dont know if i should update it or not

Offline
User avatar
*blah-blah-blah maniac*
Posts: 17427
Joined: 27 Dec 2011, 08:53
Location: Rather not to say

Re: source: creating shaders for single parts

I don't have tutorials and wrapper is not the thing which is simple to understand, especially the way i programming it.
First of all, your mistake is in d3d8, this version have very poor funtionality because of short shaders, bloom is not the same as in d3d9 mod, palette code physically can't be made the same as in d3d9 version, again because of shader length limitation. D3d9 version of palette is in the end of enbeffect.fx shaders for many games (Skyrim f.e.), simply search "palette" keyword.
Can't answer question about cubemap, this require deeper looking on to the problem and in the code. And of course it's the bad place to ask such things, use gamedev.net forum or other similar. In general, directx version 8 or 9 should not matter for such simple things like cubemaps drawing, so it's mistake in your code.
_________________
i9-9900k, 64Gb RAM, RTX 3060 12Gb, Win7
Post Reply