1 registered members (AndrewAMD),
684
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: How to:Render Target?
[Re: Joey]
#208642
05/28/08 15:13
05/28/08 15:13
|
Joined: Jul 2004
Posts: 1,710
MMike
OP
Serious User
|
OP
Serious User
Joined: Jul 2004
Posts: 1,710
|
ok i will post the whole code here.
There are some pass, first it takes the ent texture and blurs it horizontal and vertical. Then it renderes that blur outpput to a render target that then will be merged on the buffer screen, so you can thee that the object has a glow blur coming out.
Will the render target work in A6? THIS is the Glow shader. HSLS.
the tecnique part is not fully complete since i tested pass by pass.
// 3ds max effect file // Glow Effect - updated to support 3ds max autoui. // Copyright (c) Microsoft Corporation. All rights reserved. // // Note: This effect file works with EffectEdit. //
// texture texture entSkin1;
matrix matWorldViewProj; matrix matWorld; matrix matWorldView; matrix matView;
// light direction (view space) float3 LightDir : Direction = normalize(float3(0.0f, 0.0f, 1.0f));
// glow parameters float4 GlowColor = {0.5f, 0.2f, 0.2f, 1.0f}; float4 GlowAmbient = {0.2f, 0.2f, 0.0f, 0.0f}; float GlowThickness= 0.015f;
struct VSTEXTURE_OUTPUT { float4 Position : POSITION; float4 Diffuse : COLOR; float2 TexCoord : TEXCOORD0; };
// draws unskinned object with one texture and one directional light. VSTEXTURE_OUTPUT VSTexture ( float4 Position : POSITION, float3 Normal : NORMAL, float2 TexCoord : TEXCOORD0 ) { VSTEXTURE_OUTPUT Out = (VSTEXTURE_OUTPUT)0; float3 L = -LightDir; // light direction (view space) float3 P = mul(Position, matWorldView); // position (view space) float3 N = normalize(mul(Normal, (float3x3)matWorldView)); // normal (view space) Out.Position = mul(float4(P, 1), matWorldViewProj); // projected position Out.Diffuse = max(0, dot(N, L)); // diffuse Out.TexCoord = TexCoord; // texture coordinates return Out; }
struct VSGLOW_OUTPUT { float4 Position : POSITION; float4 Diffuse : COLOR; };
// draws a transparent hull of the unskinned object. VSGLOW_OUTPUT VSGlow ( float4 Position : POSITION, float3 Normal : NORMAL ) { VSGLOW_OUTPUT Out = (VSGLOW_OUTPUT)0;
float3 N = normalize(mul(Normal, (float3x3)matWorldView)); // normal (view space) float3 P = mul(Position, matWorldView) + GlowThickness * N; // displaced position (view space) float3 A = float3(0, 0, 1); // glow axis
float Power;
Power = dot(N, A); Power *= Power; Power -= 1; Power *= Power; // Power = (1 - (N.A)^2)^2 [ = ((N.A)^2 - 1)^2 ] Out.Position = mul(float4(P, 1), matWorldViewProj); // projected position Out.Diffuse = GlowColor * Power + GlowAmbient; // modulated glow color + glow ambient return Out; }
technique TGlowOnly { pass PGlow { // glow shader VertexShader = compile vs_1_1 VSGlow(); PixelShader = NULL; // no texture Texture[0] = NULL;
// enable alpha blending AlphaBlendEnable = True; zWriteEnable = true; //SrcBlend = ONE; //DestBlend = ONE;
// set up texture stage states to use the diffuse color ColorOp[0] = SELECTARG2; ColorArg2[0] = DIFFUSE; AlphaOp[0] = SELECTARG2; AlphaArg2[0] = DIFFUSE;
ColorOp[1] = DISABLE; AlphaOp[1] = DISABLE; } }
Last edited by MMike; 05/28/08 15:16.
|
|
|
Re: How to:Render Target?
[Re: MMike]
#208680
05/28/08 19:17
05/28/08 19:17
|
Joined: Jan 2003
Posts: 4,615 Cambridge
Joey
Expert
|
Expert
Joined: Jan 2003
Posts: 4,615
Cambridge
|
all i see is a vertex shader which displaces the vertices along the view space normals by a given constant. i *think* this code will run directly within the engine but it won't give you a glow effect. there is no blurring part, you see. for blurring, you need pixel shaders. object-only blurring can be done by rendering the models with slight offset (see above) in numberous passes. i see that you don't give up and you want your code to work with the engine... all i don't hear is: "how does a glow shader in 3d gamestudio work?" how have you learned in school? have you begun a discussion with every teacher telling him that you have something in mind which must be correct? at all costs? i don't want to offend you but i hope you see that the way you're going currently is way too costly for both you and the community. and don't expect other members to reply you so patiently (the lions must still be asleep as it seems ). so... do you want to know how a glow shader in game engines works in principle? and how you can achieve this effect in 3dgs? can you program hlsl, lite-c or c-script? joey.
|
|
|
Re: How to:Render Target?
[Re: MMike]
#208737
05/29/08 08:25
05/29/08 08:25
|
Joined: Jan 2003
Posts: 4,615 Cambridge
Joey
Expert
|
Expert
Joined: Jan 2003
Posts: 4,615
Cambridge
|
first of all you need a model, an entity, with a second skin which gives you the glowing parts of the model (or an alpha channel on the first skin). during normal camera rendering you're just rendering the model as-is, without the glow. now you need a second camera (or wait for multiple render targets in 7.08 and do the following in the same technique, outputting to COLOR1 instead of COLOR0). this second camera renders all objects which need to glow with the glow skin. this rendered image goes into a bitmap (or the second render target) via the view.bmap parameter.
now comes the actual glow. theoretically you need a7 for that, if you've strong directx coding skills then it should be no problem for you anyways. assign a fragment shader to your rendered image with the glowing parts. gaussian blur in a horizontal and a vertical part (since it's a convolution) for example, or poisson blur. at last you blend your second image over your normal render, either by another fragment pogram or - far more easily - by using the camera.stage render chain stuff.
if you're searching the shader forums you'll even find some finished glow or bloom shaders. you can then see how it's realized in detail.
joey.
edit: you need three or four effects or fx files for glow.
Last edited by Joey; 05/29/08 08:26.
|
|
|
Re: How to:Render Target?
[Re: MMike]
#209066
05/31/08 19:02
05/31/08 19:02
|
Joined: Jul 2004
Posts: 1,710
MMike
OP
Serious User
|
OP
Serious User
Joined: Jul 2004
Posts: 1,710
|
There is the fx file This file maynot work ormmaye yes i do't know.
So i assigned render targets (targetmap) texture..
now i asign this to the model i want to glow right? but how do i make it post process? i have the A7.07 , but manual its not very clear about this, or is process target just for lite.c?
float3 baseColor : DIFFUSE = {1.0f, 0.6f, 0.2f};
float fIntensity = 1.0f;
float Glowness = 3.0f;
// file texture (surface)
texture entSkin1;
sampler ModelTexSamp = sampler_state { texture = <entSkin1>; AddressU = WRAP; AddressV = WRAP; AddressW = WRAP; MIPFILTER = LINEAR; MINFILTER = LINEAR; MAGFILTER = LINEAR; };
/////////////////////////////////////////////////////////// /////////////////////////////////////// Un-Tweakables ///// ///////////////////////////////////////////////////////////
matrix matWorldViewProj; /////////////////////////////////////////////////////////// ///////////////////////////// Render-to-Texture Data ////// ///////////////////////////////////////////////////////////
#define RTT_SIZE 128
float TexelIncrement = 1.0f / RTT_SIZE;
texture TargetMap; float2 Dimensions = { RTT_SIZE, RTT_SIZE };
sampler GlowSamp1 = sampler_state { texture = <TargetMap>; AddressU = CLAMP; AddressV = CLAMP; AddressW = CLAMP; MIPFILTER = NONE; MINFILTER = LINEAR; MAGFILTER = LINEAR; };
sampler GlowSamp2 = sampler_state { texture = <TargetMap>; AddressU = CLAMP; AddressV = CLAMP; AddressW = CLAMP; MIPFILTER = NONE; MINFILTER = LINEAR; MAGFILTER = LINEAR; };
texture DepthBuffer : RENDERDEPTHSTENCILTARGET < float2 Dimensions = { RTT_SIZE, RTT_SIZE }; string format = "D24S8"; string UIWidget = "None"; >; /////////////////////////////////////////////////////////// /////////////////////////////////// data structures /////// ///////////////////////////////////////////////////////////
struct VS_OUTPUT_BLUR { float4 Position : POSITION; float4 Diffuse : COLOR0; float4 TexCoord0 : TEXCOORD0; float4 TexCoord1 : TEXCOORD1; float4 TexCoord2 : TEXCOORD2; float4 TexCoord3 : TEXCOORD3; float4 TexCoord4 : TEXCOORD4; float4 TexCoord5 : TEXCOORD5; float4 TexCoord6 : TEXCOORD6; float4 TexCoord7 : TEXCOORD7; float4 TexCoord8 : COLOR1; };
struct VS_OUTPUT { float4 Position : POSITION; float4 Diffuse : COLOR0; float4 TexCoord0 : TEXCOORD0; };
//////////////////////////////////////////////////////////// ////////////////////////////////// vertex shaders ////////// ////////////////////////////////////////////////////////////
VS_OUTPUT VS(float3 Position : POSITION, float3 Normal : NORMAL, float3 TexCoord : TEXCOORD0) { VS_OUTPUT OUT = (VS_OUTPUT)0; OUT.Position = mul(float4(Position, 1), matWorldViewProj); OUT.Diffuse = float4(baseColor,1); OUT.TexCoord0 = float4(TexCoord, 1); return OUT; }
VS_OUTPUT VS_Quad(float3 Position : POSITION, float3 TexCoord : TEXCOORD0) { VS_OUTPUT OUT = (VS_OUTPUT)0; OUT.Position = float4(Position, 1); OUT.TexCoord0 = float4(TexCoord, 1); return OUT; }
VS_OUTPUT_BLUR VS_Quad_Vertical_9tap(float3 Position : POSITION, float3 TexCoord : TEXCOORD0) { VS_OUTPUT_BLUR OUT = (VS_OUTPUT_BLUR)0; OUT.Position = float4(Position, 1); float3 Coord = float3(TexCoord.x + TexelIncrement, TexCoord.y + TexelIncrement, 1); OUT.TexCoord0 = float4(Coord.x, Coord.y + TexelIncrement, TexCoord.z, 1); OUT.TexCoord1 = float4(Coord.x, Coord.y + TexelIncrement * 2, TexCoord.z, 1); OUT.TexCoord2 = float4(Coord.x, Coord.y + TexelIncrement * 3, TexCoord.z, 1); OUT.TexCoord3 = float4(Coord.x, Coord.y + TexelIncrement * 4, TexCoord.z, 1); OUT.TexCoord4 = float4(Coord.x, Coord.y, TexCoord.z, 1); OUT.TexCoord5 = float4(Coord.x, Coord.y - TexelIncrement, TexCoord.z, 1); OUT.TexCoord6 = float4(Coord.x, Coord.y - TexelIncrement * 2, TexCoord.z, 1); OUT.TexCoord7 = float4(Coord.x, Coord.y - TexelIncrement * 3, TexCoord.z, 1); OUT.TexCoord8 = float4(Coord.x, Coord.y - TexelIncrement * 4, TexCoord.z, 1); return OUT; }
VS_OUTPUT_BLUR VS_Quad_Horizontal_9tap(float3 Position : POSITION, float3 TexCoord : TEXCOORD0) { VS_OUTPUT_BLUR OUT = (VS_OUTPUT_BLUR)0; OUT.Position = float4(Position, 1); float3 Coord = float3(TexCoord.x + TexelIncrement, TexCoord.y + TexelIncrement, 1); OUT.TexCoord0 = float4(Coord.x + TexelIncrement, Coord.y, TexCoord.z, 1); OUT.TexCoord1 = float4(Coord.x + TexelIncrement * 2, Coord.y, TexCoord.z, 1); OUT.TexCoord2 = float4(Coord.x + TexelIncrement * 3, Coord.y, TexCoord.z, 1); OUT.TexCoord3 = float4(Coord.x + TexelIncrement * 4, Coord.y, TexCoord.z, 1); OUT.TexCoord4 = float4(Coord.x, Coord.y, TexCoord.z, 1); OUT.TexCoord5 = float4(Coord.x - TexelIncrement, Coord.y, TexCoord.z, 1); OUT.TexCoord6 = float4(Coord.x - TexelIncrement * 2, Coord.y, TexCoord.z, 1); OUT.TexCoord7 = float4(Coord.x - TexelIncrement * 3, Coord.y, TexCoord.z, 1); OUT.TexCoord8 = float4(Coord.x - TexelIncrement * 4, Coord.y, TexCoord.z, 1); return OUT; }
VS_OUTPUT_BLUR VS_Quad_Vertical_5tap(float3 Position : POSITION, float3 TexCoord : TEXCOORD0) { VS_OUTPUT_BLUR OUT = (VS_OUTPUT_BLUR)0; OUT.Position = float4(Position, 1); float3 Coord = float3(TexCoord.x + TexelIncrement, TexCoord.y + TexelIncrement, 1); OUT.TexCoord0 = float4(Coord.x, Coord.y + TexelIncrement, TexCoord.z, 1); OUT.TexCoord1 = float4(Coord.x, Coord.y + TexelIncrement * 2, TexCoord.z, 1); OUT.TexCoord2 = float4(Coord.x, Coord.y, TexCoord.z, 1); OUT.TexCoord3 = float4(Coord.x, Coord.y - TexelIncrement, TexCoord.z, 1); OUT.TexCoord4 = float4(Coord.x, Coord.y - TexelIncrement * 2, TexCoord.z, 1); return OUT; }
VS_OUTPUT_BLUR VS_Quad_Horizontal_5tap(float3 Position : POSITION, float3 TexCoord : TEXCOORD0) { VS_OUTPUT_BLUR OUT = (VS_OUTPUT_BLUR)0; OUT.Position = float4(Position, 1); float3 Coord = float3(TexCoord.x + TexelIncrement, TexCoord.y + TexelIncrement, 1); OUT.TexCoord0 = float4(Coord.x + TexelIncrement, Coord.y, TexCoord.z, 1); OUT.TexCoord1 = float4(Coord.x + TexelIncrement * 2, Coord.y, TexCoord.z, 1); OUT.TexCoord2 = float4(Coord.x, Coord.y, TexCoord.z, 1); OUT.TexCoord3 = float4(Coord.x - TexelIncrement, Coord.y, TexCoord.z, 1); OUT.TexCoord4 = float4(Coord.x - TexelIncrement * 2, Coord.y, TexCoord.z, 1); return OUT; }
////////////////////////////////////////////////////// ////////////////////////////////// pixel shaders ///// //////////////////////////////////////////////////////
// just map the glow-mask texture to the screen - no lighting // this shader will draw to a texture float4 PS_BlurBuffer(VS_OUTPUT IN) : COLOR { float3 Col = IN.Diffuse * tex2D(ModelTexSamp, float2(IN.TexCoord0.xy)).xyz; Col *= fIntensity; return float4(Col,1); }
////////
// For two-pass blur, we have chosen to do the horizontal blur FIRST. The // vertical pass includes a post-blur scale factor.
// Relative filter weights indexed by distance from "home" texel // This set for 9-texel sampling #define WT9_0 1.0 #define WT9_1 0.8 #define WT9_2 0.6 #define WT9_3 0.4 #define WT9_4 0.2
// Alt pattern -- try your own! // #define WT9_0 0.1 // #define WT9_1 0.2 // #define WT9_2 3.0 // #define WT9_3 1.0 // #define WT9_4 0.4
#define WT9_NORMALIZE (WT9_0+2.0*(WT9_1+WT9_2+WT9_3+WT9_4))
float4 PS_Blur_Horizontal_9tap(VS_OUTPUT_BLUR IN) : COLOR { float4 OutCol = tex2D(GlowSamp1, IN.TexCoord0) * (WT9_1/WT9_NORMALIZE); OutCol += tex2D(GlowSamp1, IN.TexCoord1) * (WT9_2/WT9_NORMALIZE); OutCol += tex2D(GlowSamp1, IN.TexCoord2) * (WT9_3/WT9_NORMALIZE); OutCol += tex2D(GlowSamp1, IN.TexCoord3) * (WT9_4/WT9_NORMALIZE); OutCol += tex2D(GlowSamp1, IN.TexCoord4) * (WT9_0/WT9_NORMALIZE); OutCol += tex2D(GlowSamp1, IN.TexCoord5) * (WT9_1/WT9_NORMALIZE); OutCol += tex2D(GlowSamp1, IN.TexCoord6) * (WT9_2/WT9_NORMALIZE); OutCol += tex2D(GlowSamp1, IN.TexCoord7) * (WT9_3/WT9_NORMALIZE); OutCol += tex2D(GlowSamp1, IN.TexCoord8) * (WT9_3/WT9_NORMALIZE); return OutCol; }
float4 PS_Blur_Vertical_9tap(VS_OUTPUT_BLUR IN) : COLOR { float4 OutCol = tex2D(GlowSamp2, IN.TexCoord0) * (WT9_1/WT9_NORMALIZE); OutCol += tex2D(GlowSamp2, IN.TexCoord1) * (WT9_2/WT9_NORMALIZE); OutCol += tex2D(GlowSamp2, IN.TexCoord2) * (WT9_3/WT9_NORMALIZE); OutCol += tex2D(GlowSamp2, IN.TexCoord3) * (WT9_4/WT9_NORMALIZE); OutCol += tex2D(GlowSamp2, IN.TexCoord4) * (WT9_0/WT9_NORMALIZE); OutCol += tex2D(GlowSamp2, IN.TexCoord5) * (WT9_1/WT9_NORMALIZE); OutCol += tex2D(GlowSamp2, IN.TexCoord6) * (WT9_2/WT9_NORMALIZE); OutCol += tex2D(GlowSamp2, IN.TexCoord7) * (WT9_3/WT9_NORMALIZE); OutCol += tex2D(GlowSamp2, IN.TexCoord8) * (WT9_3/WT9_NORMALIZE); return Glowness*OutCol; }
// Relative filter weights indexed by distance from "home" texel // This set for 5-texel sampling #define WT5_0 1.0 #define WT5_1 0.8 #define WT5_2 0.4
#define WT5_NORMALIZE (WT5_0+2.0*(WT5_1+WT5_2))
float4 PS_Blur_Horizontal_5tap(VS_OUTPUT_BLUR IN) : COLOR { float4 OutCol = tex2D(GlowSamp1, IN.TexCoord0) * (WT5_1/WT5_NORMALIZE); OutCol += tex2D(GlowSamp1, IN.TexCoord1) * (WT5_2/WT5_NORMALIZE); OutCol += tex2D(GlowSamp1, IN.TexCoord2) * (WT5_0/WT5_NORMALIZE); OutCol += tex2D(GlowSamp1, IN.TexCoord3) * (WT5_1/WT5_NORMALIZE); OutCol += tex2D(GlowSamp1, IN.TexCoord4) * (WT5_2/WT5_NORMALIZE); return OutCol; }
float4 PS_Blur_Vertical_5tap(VS_OUTPUT_BLUR IN) : COLOR { float4 OutCol = tex2D(GlowSamp2, IN.TexCoord0) * (WT5_1/WT5_NORMALIZE); OutCol += tex2D(GlowSamp2, IN.TexCoord1) * (WT5_2/WT5_NORMALIZE); OutCol += tex2D(GlowSamp2, IN.TexCoord2) * (WT5_0/WT5_NORMALIZE); OutCol += tex2D(GlowSamp2, IN.TexCoord3) * (WT5_1/WT5_NORMALIZE); OutCol += tex2D(GlowSamp2, IN.TexCoord4) * (WT5_2/WT5_NORMALIZE); return Glowness*OutCol; }
////////
// just drawn model itself
float4 PS_Model(VS_OUTPUT IN) : COLOR { float4 Col = IN.Diffuse * tex2D(ModelTexSamp, float2(IN.TexCoord0.xy)); return Col; }
// add glow on top of model
float4 PS_GlowPass(VS_OUTPUT IN) : COLOR { float4 tex = tex2D(GlowSamp1, float2(IN.TexCoord0.x, IN.TexCoord0.y)); return tex; }
//////////////////////////////////////////////////////////// /////////////////////////////////////// techniques ///////// ////////////////////////////////////////////////////////////
//////////////
technique Glow_5Tap
{
pass BlurPass { cullmode = none; ZEnable = true; VertexShader = compile vs_1_1 VS(); PixelShader = compile ps_2_0 PS_BlurBuffer(); } pass BlurGlowBuffer_Horz { cullmode = none; ZEnable = false; VertexShader = compile vs_2_0 VS_Quad_Horizontal_5tap(); PixelShader = compile ps_2_0 PS_Blur_Horizontal_5tap(); } pass BlurGlowBuffer_Vert { cullmode = none; ZEnable = false; VertexShader = compile vs_2_0 VS_Quad_Vertical_5tap(); PixelShader = compile ps_2_0 PS_Blur_Vertical_5tap(); } pass ModelPass { ZEnable = true; ZWriteEnable = true; AlphaBlendEnable = false; AlphaTestEnable = false; VertexShader = compile vs_1_1 VS(); PixelShader = compile ps_2_0 PS_Model(); } pass GlowPass { cullmode = none; ZEnable = false; ZWriteEnable = false; AlphaBlendEnable = true; SrcBlend = one; DestBlend = one; VertexShader = compile vs_1_1 VS_Quad(); PixelShader = compile ps_2_0 PS_GlowPass(); } }
//////////////
technique NoGlow { pass ObjectRender { ZWriteEnable = true; AlphaBlendEnable = false; AlphaTestEnable = false; VertexShader = compile vs_1_1 VS(); PixelShader = compile ps_1_1 PS_Model(); } }
Last edited by MMike; 05/31/08 19:50.
|
|
|
|