Hi,
Here is a quick Studio sample performing a render to texture: one texture for color render, and one texture for Z value render (depth). I display the result inside 2D frames to make it visible.
To render camera to a texture inside Studio you must create a new vkViewport, then set your new vkRenderTexture as viewport target texture using vkViewport::SetTargetTexture. I would say that Index is greater than 0 if you need to perform multiple render target (MRT) post processing (meaning you fill several texures in one shader pass). Need to check that though, never used it yet. You may like that MRT stuff to render colors + normals in two textures in one rendering pass.
vkViewpot::SetTargetDepthTexture() let you define a target texture for Z buffer value. Studio uses by default ePF_D24S8 format for Z Buffer (you can check that inside Project Options / Render / Default Z Stencil format). When you create your vkRenderTexture, you can specify the texture RenderType. That would be
vkRenderTexture::fRtZ in this case.
About which method for cartoon rendering, if you are a Virtools user you could also check inside Virtools material library: there is a simple 2D cartoon shader that is very light to implement (no post processing needed, only the normal is used + environmnent map. Here is the code:
// Cartoon Shader
//
// Use only VS 1.1. Two passes: one for the edge and another for the shading.
// (c)2003 Virtools
//--- Standard Automatic Parameters
float4x4 world : WORLD;
float3x3 itworld : ITWORLD;
float4x4 view : VIEW;
float4x4 wvp : WORLDVIEWPROJECTION;
float4x4 wv : WORLDVIEW;
//--- Additional Automatic Parameters
texture tex : TEXTURE;
float4 dif : DIFFUSE;
float4 emi : EMISSIVE;
float power : POWER;
float3 lightPos : EYEPOS;
float EnvMapScaleFactor <float UIMin=0.2; float UIMax=0.5;> = 0.438;
float VertexPositionInfluence <float UIMin=0; float UIMax=3;> = 1.5;
//--- Static Variables
static float2 offset = -0.5;
static float2 scaleFactor = float2( EnvMapScaleFactor, -EnvMapScaleFactor );
static float3 vertexPositionInfluence = float3(1,1,0) * VertexPositionInfluence * 0.001;
static float3 camDir = mul( world, view._m02_m12_m22 );
static float modulation = power * 0.01;
//--- Texture Sampler
sampler texSampler = sampler_state
{
texture = <tex>;
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
MinFilter = LINEAR;
MipFilter = LINEAR;
MipMapLodBias = 0;
};
//--- VS In/Out Structure
struct VSIN {
float3 pos : POSITION;
float3 norm : NORMAL;
};
struct VSOUT {
float4 pos : POSITION;
float2 uv0 : TEXCOORD0;
float4 col : COLOR;
};
//--- Vertex Shader
VSOUT CartoonVS( VSIN vsIn )
{
VSOUT vsOut;
vsOut.pos = mul( float4(vsIn.pos,1), wvp );
float3 norm = normalize( mul( vsIn.norm, itworld) );
float2 uvNormal = mul( norm, view).xy + vsOut.pos.xy * vertexPositionInfluence;
float s = modulation * dot( norm, normalize(lightPos-vsIn.pos) );
vsOut.col = dif * s + emi * (1-s);
vsOut.uv0 = uvNormal*scaleFactor - offset;
return vsOut;
}
technique tech
{
pass p
{
Texture[0] = <tex>;
MagFilter[0] = LINEAR;
MipFilter[0] = LINEAR;
ColorOp[0] = MODULATE;
ColorArg1[0] = TEXTURE;
ColorArg2[0] = CURRENT;
VertexShader = compile vs_1_1 CartoonVS();
}
}
Attached is the map to be used.
All that is forward shading.
Deferred shading is another story, but would also allow that. Choice depends on number of light sources, quality of anti-aliasing required, and your shader programming skills (deferred is rather different, requires a bit of learning phase to work with it). But with deferred you would directly access color, normal and Z info without needing to do post processing, so might be elegant for sure.
Cheers,
Arnaud.
Attachments
-
PostProcessingSample.zip (67.8 KB, 7 downloads) 3 months old
WARNING: Files uploaded in the forums are not monitored by 3DVIA and therefore might contain content that is malicious or offensive. Download at your own risk