- Joined
- Nov 17, 2013
- Messages
- 1
- Reaction score
- 5
Hello, I decided to release my HLSL shader which I sold to the unmentioned team. This shader was extracted from the client and some kids are selling it without any permission like my map editor.
I used effect technology for it:
You need to bill all parameters into your effect before you will start the pass. Also, you need to store bones into a texture.
Do not ask me how to implement it because I'll not help you. If there is someone who wants to release implementation he's free to use this shader.
Do not support kids who selling other's stuff. I dislike selling stuff where you didn't create. Thank you!
I used effect technology for it:
You must be registered to see links
You need to bill all parameters into your effect before you will start the pass. Also, you need to store bones into a texture.
Do not ask me how to implement it because I'll not help you. If there is someone who wants to release implementation he's free to use this shader.
Code:
float4x4 mProj;float4x4 mView;float4x4 mWorldMatrixArray;int lightCount = 0;float4 lightAmbient[3] : LIGHTARRAYAMBIENT;float4 lightDiffuse[3] : LIGHTARRAYDIFFUSE;float4 lightDir[3] : LIGHTARRAYDIR;float4 CamPos = 0.0f;float4 mtrAmbient : MATERIALAMBIENT;float4 mtrDiffuse : MATERIALDIFFUSE;float4 Ambient;bool Skinning = 0;bool CanDiffuse = 0;bool CanFog = 0;float4 Fog;float4 FogColor : FOGCOLOR;float3x3 TexTrans;float3x3 TexTrans2;texture t;sampler samp =sampler_state{ Texture = <t>; MinFilter = POINT; MagFilter = POINT; MipFilter = NONE; AddressU = CLAMP; AddressV = CLAMP;};sampler2D samp1 : register(s0);sampler2D samp2 : register(s1);struct VS_INPUT{ float3 vPosition : POSITION0; float3 BlendWeights : BLENDWEIGHT; float4 BlendIndices : BLENDINDICES; float3 vNormal : NORMAL0; float2 vUV : TEXCOORD0;};struct VS_OUTPUT{ float4 vPosition : POSITION0; float4 Diffuse : COLOR0; float2 vUV : TEXCOORD0; float2 vUV2 : TEXCOORD1; float3 vNormal : NORMAL0; float3 vCamDir : NORMAL1; float3 vLightDir : NORMAL2; float vFog : FOG;};float4x4 getMatrix(int nIdx){ if (!Skinning) return mWorldMatrixArray; float fIdx = ((float) nIdx / 256.0f); float4x4 m = float4x4( tex2Dlod(samp, float4(float2(0.0, fIdx), 0.0f, 0.0f)), tex2Dlod(samp, float4(float2(1.0f / 3.0f, fIdx), 0.0f, 0.0f)), tex2Dlod(samp, float4(float2(2.0f / 3.0f, fIdx), 0.0f, 0.0f)), tex2Dlod(samp, float4(float2(1.0f, fIdx), 0.0f, 0.0f))); return m;}float3 getMulSkinnedPos(float3 vPos, int nIdx, float fWeight,float4x4 mWord){ if (nIdx == 0) return (mul(float4(vPos, 1.0f), mWord) * fWeight).xyz; return (mul(float4(vPos, 1.0f), getMatrix(nIdx)) * fWeight).xyz;}float4 getDiffuse(float3 pos,float3 normal){ float4 Diffuse = Ambient; for (int i = 0; i < lightCount; i++) { if (CanDiffuse) { if (lightDir[i].w < 0.0f) { // Point Light float fDist = distance(lightDir[i].xyz, pos); float lMul = fDist * lightAmbient[i].x; if (lMul < 1.0f) { float3 fColor = lerp(0.f, lightDiffuse[i].xyz, lMul); float3 normlPos = normalize(lightDir[i].xyz); float fIntenzity = max(-dot(normal, normlPos), 0.0f); float3 mulVar = (fIntenzity * mtrDiffuse.xyz) * fColor; Diffuse.xyz += mulVar; } } else { //Direction Light float fIntenzity = saturate(-dot(normal, lightDir[i].xyz)); float4 mulVar = fIntenzity * mtrDiffuse * lightDiffuse[i]; Diffuse += max(mulVar, mtrAmbient * lightAmbient[i]); } } else Diffuse += mtrAmbient * lightAmbient[i]; } return saturate(float4(Diffuse.xyz, mtrDiffuse.w));}VS_OUTPUT VSkin(VS_INPUT Input){ VS_OUTPUT Output; float3 Position = float3(0.0f, 0.0f, 0.0f); float3 Normal = 0.0f; float4x4 mWorld = getMatrix(0); if (Skinning) { int4 aiIndices = D3DCOLORtoUBYTE4(Input.BlendIndices); float fWeight = 1.0f; for (int i = 0; i < 3; i++) { if(Input.BlendWeights[i] > 0.0f) { Position += getMulSkinnedPos(Input.vPosition, aiIndices[i], Input.BlendWeights[i],mWorld); fWeight -= Input.BlendWeights[i]; } } if(fWeight) { Position += getMulSkinnedPos(Input.vPosition, aiIndices[3], fWeight,mWorld); } } else { Position = Position = mul(float4(Input.vPosition, 1.0f), mWorld); } Normal = mul(Input.vNormal, (float3x3) mWorld); Output.vCamDir = Position - CamPos.xyz; Output.vPosition = mul(float4(Position, 1.0f), mView); Output.vFog = CanFog ? Fog.w < 0.0f ? saturate((Fog.y - Output.vPosition.z) / (Fog.y - Fog.x)) : (length(Output.vPosition.xyz) * Fog.z) : 1; Output.vPosition = mul(Output.vPosition, mProj); Output.vNormal = normalize(Normal); Output.vLightDir = lightDir[0].xyz; Output.Diffuse = getDiffuse(Position,Output.vNormal); Output.vUV = mul(float3(Input.vUV, 1.0f), TexTrans).xy; Output.vUV2 = mul(float3(Input.vUV, 1.0f), TexTrans2).xy; return Output; }float4 TextureFactor;float4 PixelArg;uint nPsShader;float4 comp(float Arg, float4 c , float4 t){ return Arg >= 0 ? c : t;}float4 PixelShaderFunction(VS_OUTPUT Input): COLOR0{ float4 colorTex1 = comp(PixelArg.x, tex2D(samp1, Input.vUV), TextureFactor); float4 colorTex2 = comp(PixelArg.y, tex2D(samp2, Input.vUV2), TextureFactor); float4 color = 0; switch (nPsShader) { case 0: { color = colorTex1; } break; case 1: { color = (colorTex1 * colorTex2); } break; case 2: { color = (colorTex1 * 2.0f) * colorTex2; } break; case 3: { color = (colorTex1 * 4.0f) * colorTex2; } break; case 4: { color = (colorTex1 + colorTex2); } break; case 5: { color = colorTex1 + colorTex2 - 0.5f; } break; case 6: { color = float4((2 * (colorTex1 + colorTex2 - 0.5f)).xyz, colorTex1.w); } break; case 7: { color = (colorTex1 - colorTex2); } break; case 8: { color = (mad(-colorTex1, colorTex2, colorTex2) + colorTex2); } break; case 9: { float blend = 1 - Input.Diffuse.w; float4 colb = colorTex1 * Input.Diffuse.wwww; color = mad(colorTex2, blend, colb); } break; case 10: { float blend = 1 - colorTex2.w; float4 colb = colorTex1 * colorTex2.w; color = mad(colorTex2, blend, colb); } break; case 11: { float blend = 1 - TextureFactor.w; float4 colb = colorTex1 * TextureFactor.w; color = mad(colorTex2, blend, colb); } break; case 12: { float blend = 1 - colorTex2.w; color = mad(colorTex2, blend, colorTex1); } break; case 13: { float blend = 1 - colorTex1.w; float4 colb = colorTex1 * colorTex1.w; color = mad(colorTex2, blend, colb); } break; case 14: { float3 blend = mad(colorTex2, colorTex1.wwww, colorTex1); color = float4(blend, colorTex1.w); } break; case 15: { float4 blend = mad( colorTex1,colorTex2, colorTex1.wwww); color = float4(blend.xyz, colorTex1.w); } break; case 16: { float blend = 1 - colorTex1.w; float3 col = mad(colorTex2, blend, colorTex1); color = float4(col, colorTex1.w); } break; case 17: { float4 blend = 1 - colorTex1; float3 colr = mad(colorTex2, blend, colorTex1.wwww); color = float4(colr, colorTex1.w); } break; case 18: { color = dot(colorTex1, colorTex2); } break; case 19: { color = mad(colorTex1, colorTex2, colorTex1); } break; case 20: { color = lerp(colorTex1, colorTex2, colorTex1); } break; case 21: { //Set alpha and specular color float rcp = 1 / 257.0f; float idk = mad(256.0f, colorTex2.y, colorTex2.z) * rcp; float alpha = mad(256.0f, colorTex2.w, colorTex2.x); colorTex1.w = alpha * rcp; //Compute specular color float3 View = normalize(Input.vCamDir) - lightDir[0].xyz; float3 Colr = normalize(View); float3 Normal = normalize(Input.vNormal); float sColor = dot(Colr, Normal); sColor = max(sColor, 0.0f); sColor = pow(sColor, PixelArg.z); color = mad(idk, sColor, colorTex1); } break; } float4 finalTex = float4(color.xyz * Input.Diffuse.xyz, min(color.w,Input.Diffuse.w)); if (!CanFog || Input.vFog > 0.9999f) return finalTex; return float4(lerp(FogColor.xyz, finalTex.xyz, Input.vFog), finalTex.w);}technique TSkinning{ pass p0 { VertexShader = compile vs_3_0 VSkin(); PixelShader = compile ps_3_0 PixelShaderFunction(); }}
You must be registered to see links
Do not support kids who selling other's stuff. I dislike selling stuff where you didn't create. Thank you!
Last edited: