Hello everyone,
first of all I would like to commit, that it`s the first time i work with HLSL, please don`t stone me for stupid begginer questions. I came accross a problem with multiple render passes in the single hlsl shader. I simply couldn`t figgure out how render my object with beckface cull cw first, save local position and then render it with backface cull none and subdivide them to get a mesh thiskness. I don`t know, how to store the cull cw local position in the texture. I have tryed to follow tutorials and rewrite some shaders I found, nevertheless they all worked as a postprocess effects. When I tryed to use the same code for my shader fx composer I got error messages just like:
"Warning Effect uses script commands on an object effect instead of a pre or post processing effect. This is not supported. c:\users\uiop\documents\fx composer 2\projects\passestest\Lambert.fx -1"
Could any one help me please?
Here is the code by the way:
#define FLIP_TEXTURE_Y
float Script : STANDARDSGLOBAL <
string UIWidget = "none";
string ScriptClass = "object";
string ScriptOrder = "standard";
string ScriptOutput = "color";
string Script = "Technique=Lambert?Main:Main10;";
> = 0.8;
//// UN-TWEAKABLES - AUTOMATICALLY-TRACKED TRANSFORMS ////////////////
float4x4 WorldITXf : WorldInverseTranspose < string UIWidget="None"; >;
float4x4 WvpXf : WorldViewProjection < string UIWidget="None"; >;
float4x4 WorldXf : World < string UIWidget="None"; >;
float4x4 ViewIXf : ViewInverse < string UIWidget="None"; >;
//// TWEAKABLE PARAMETERS ////////////////////
/// Point Lamp 0 ////////////
float3 Lamp0Pos : Position <
string Object = "PointLight0";
string UIName = "Lamp 0 Position";
string Space = "World";
> = {-0.5f,2.0f,1.25f};
float3 Lamp0Color : Specular <
string UIName = "Lamp 0";
string Object = "Pointlight0";
string UIWidget = "Color";
> = {1.0f,1.0f,1.0f};
// Ambient Light
float3 AmbiColor : Ambient <
string UIName = "Ambient Light";
string UIWidget = "Color";
> = {0.07f,0.07f,0.07f};
//////// COLOR & TEXTURE /////////////////////
texture ColorTexture : DIFFUSE <
string ResourceName = "default_color.dds";
string UIName = "Diffuse Texture";
string ResourceType = "2D";
>;
sampler2D ColorSampler = sampler_state {
Texture = <ColorTexture>;
FILTER = MIN_MAG_MIP_LINEAR;
AddressU = Wrap;
AddressV = Wrap;
};
//DECLARE_QUAD_TEX(ColrTex,ColrSampler,"A8B8G8R8")
//DECLARE_QUAD_TEX(PosTex,TexSampler,"A16B16G16R16");
// shared shadow mapping supported in Cg version
//////// CONNECTOR DATA STRUCTURES ///////////
/* data from application vertex buffer */
struct appdata {
float3 Position : POSITION;
float4 UV : TEXCOORD0;
float4 Normal : NORMAL;
float4 Tangent : TANGENT0;
float4 Binormal : BINORMAL0;
};
/* data passed from vertex shader to pixel shader */
struct vertexOutput {
float4 HPosition : POSITION;
float4 Po : TEXCOORD6;
float2 UV : TEXCOORD0;
// The following values are passed in "World" coordinates since
// it tends to be the most flexible and easy for handling
// reflections, sky lighting, and other "global" effects.
float3 LightVec : TEXCOORD1;
float3 WorldNormal : TEXCOORD2;
float3 WorldTangent : TEXCOORD3;
float3 WorldBinormal : TEXCOORD4;
float3 WorldView : TEXCOORD5;
};
///////// VERTEX SHADING /////////////////////
/*********** Generic Vertex Shader ******/
vertexOutput std_VS(appdata IN) {
vertexOutput OUT = (vertexOutput)0;
OUT.WorldNormal = mul(IN.Normal,WorldITXf).xyz;
OUT.WorldTangent = mul(IN.Tangent,WorldITXf).xyz;
OUT.WorldBinormal = mul(IN.Binormal,WorldITXf).xyz;
OUT.Po = float4(IN.Position.xyz,1);
float3 Pw = mul(OUT.Po,WorldXf).xyz;
OUT.LightVec = (Lamp0Pos - Pw);
#ifdef FLIP_TEXTURE_Y
OUT.UV = float2(IN.UV.x,(1.0-IN.UV.y));
#else /* !FLIP_TEXTURE_Y */
OUT.UV = IN.UV.xy;
#endif /* !FLIP_TEXTURE_Y */
OUT.WorldView = normalize(ViewIXf[3].xyz - Pw);
OUT.HPosition = mul(OUT.Po,WvpXf);
return OUT;
}
///////// PIXEL SHADING //////////////////////
float4 std_PS(vertexOutput IN) : COLOR {
float3 Ln = normalize(IN.LightVec);
float3 Nn = normalize(IN.WorldNormal);
float ldn = dot(Ln,Nn);
ldn = max(ldn,0.0);
float3 diffuseColor = tex2D(ColorSampler,IN.UV).rgb;
float3 result = diffuseColor * (ldn * Lamp0Color + AmbiColor);
// return as float4
return float4(result,1);
}
float4 PS_BF_Cull(vertexOutput IN):COLOR {
// float3 diffuseColor = tex2D(PosSampler,IN.UV).rgb;
//float3 result = diffuseColor * (ldn * Lamp0Color + AmbiColor);
// return as float4
float4 pokus=IN.Po;
return pokus;
}
float4 depth();
///// TECHNIQUES /////////////////////////////
RasterizerState DisableCulling
{
CullMode = NONE;
};
DepthStencilState DepthEnabling
{
DepthEnable = TRUE;
};
BlendState DisableBlend
{
BlendEnable[0] = FALSE;
};
technique10 Main10 <
string Script = "Pass=p0;";
> {
pass p0 <
string Script = "Draw=geometry;";
> {
SetVertexShader( CompileShader( vs_4_0, std_VS() ) );
SetGeometryShader( NULL );
SetPixelShader( CompileShader( ps_4_0, std_PS() ) );
SetRasterizerState(DisableCulling);
SetDepthStencilState(DepthEnabling, 0);
SetBlendState(DisableBlend, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF);
}
}
technique Main <
string Script =
"p0;"
"Pass=p2;";
> {
// I need to render this pass to toxture, for example Colortex, to read it afterwards.
pass p0 <
string Script ="RenderColorTarget0=ColrTex;"
"Draw=Geometry;";
> {
VertexShader = compile vs_2_0 std_VS();
ZEnable = true;
ZWriteEnable = true;
ZFunc = LessEqual;
AlphaBlendEnable = false;
CullMode = CCW;
PixelShader = compile ps_2_a PS_BF_Cull();
}
pass p2 <
string Script = "Draw=geometry;";
> {
VertexShader = compile vs_2_0 std_VS();
ZEnable = true;
ZWriteEnable = true;
ZFunc = LessEqual;
AlphaBlendEnable = false;
CullMode = cw;
PixelShader = compile ps_2_a std_PS();
}
}